LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Faik Uygur <faikuygur@tnn.net>
Cc: greg@kroah.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] use idr_get_new to allocate a bus id in drivers/i2c/i2c-core.c
Date: Sat, 15 May 2004 16:58:12 -0700	[thread overview]
Message-ID: <20040515165812.7e771f20.akpm@osdl.org> (raw)
In-Reply-To: <20040515222632.GA7218@dsl.ttnet.net.tr>

Faik Uygur <faikuygur@tnn.net> wrote:
>
> Hi,
> 
> This patch uses idr_get_new to allocate a bus id while registering
> a new adapter.
> 

The IDR interface is a bit cumbersome.  Even though you called
idr_pre_get(), there's no guarantee that the memory which it preallocated
is still present when you call idr_get_new().

It's easily fixed though:


>  int i2c_add_adapter(struct i2c_adapter *adap)
>  {
> -	static int nr = 0;
> +	int id;
>  	struct list_head   *item;
>  	struct i2c_driver  *driver;
>  
> +	if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0)
> +		return -ENOMEM;
> +
>  	down(&core_lists);
>  
> -	adap->nr = nr++;
> +	id = idr_get_new(&i2c_adapter_idr, NULL);
> +	adap->nr =  id & MAX_ID_MASK;
>  	init_MUTEX(&adap->bus_lock);
>  	init_MUTEX(&adap->clist_lock);
>  	list_add_tail(&adap->list,&adapters);
> @@ -207,6 +213,9 @@
>  	/* wait for sysfs to drop all references */
>  	wait_for_completion(&adap->dev_released);
>  	wait_for_completion(&adap->class_dev_released);
> +
> +	/* free dynamically allocated bus id */
> +	idr_remove(&i2c_adapter_idr, adap->nr);
>  
>  	dev_dbg(&adap->dev, "adapter unregistered\n");

Just move the idr_pre_get() to after the down().  That way you know nobody
else will steal the preallocation.

Is the kernel likely to ever have so many bus IDs that we actually need
this patch?  Or do you specifically want first-fit-from-zero for some
reason?


  reply	other threads:[~2004-05-15 23:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-15 22:26 Faik Uygur
2004-05-15 23:58 ` Andrew Morton [this message]
2004-05-16  9:13   ` Faik Uygur
2004-05-16  9:36     ` Andrew Morton
2004-05-19  7:07     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040515165812.7e771f20.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=faikuygur@tnn.net \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH] use idr_get_new to allocate a bus id in drivers/i2c/i2c-core.c' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).