[PATCH] use idr_get_new to allocate a bus id in drivers/i2c/i2c-core.c

From: Faik Uygur
Date: Sat May 15 2004 - 17:29:32 EST


Hi,

This patch uses idr_get_new to allocate a bus id while registering
a new adapter.


--- a/drivers/i2c/i2c-core.c Sat May 15 23:19:11 2004
+++ b/drivers/i2c/i2c-core.c Sat May 15 23:19:11 2004
@@ -28,6 +28,7 @@
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/init.h>
+#include <linux/idr.h>
#include <linux/seq_file.h>
#include <asm/uaccess.h>

@@ -35,6 +36,7 @@
static LIST_HEAD(adapters);
static LIST_HEAD(drivers);
static DECLARE_MUTEX(core_lists);
+static DEFINE_IDR(i2c_adapter_idr);

int i2c_device_probe(struct device *dev)
{
@@ -113,13 +115,17 @@
*/
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");



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