lkml.org 
[lkml]   [2004]   [May]   [15]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
DateSat, 15 May 2004 16:58:12 -0700
FromAndrew Morton <>
SubjectRe: [PATCH] use idr_get_new to allocate a bus id in drivers/i2c/i2c-core.c
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?

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:03    [from the cache]
©2003-2008