LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] use idr_get_new to allocate a bus id in drivers/i2c/i2c-core.c
@ 2004-05-15 22:26 Faik Uygur
  2004-05-15 23:58 ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Faik Uygur @ 2004-05-15 22:26 UTC (permalink / raw)
  To: greg; +Cc: linux-kernel

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");
 



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-05-19  7:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-15 22:26 [PATCH] use idr_get_new to allocate a bus id in drivers/i2c/i2c-core.c Faik Uygur
2004-05-15 23:58 ` Andrew Morton
2004-05-16  9:13   ` Faik Uygur
2004-05-16  9:36     ` Andrew Morton
2004-05-19  7:07     ` Greg KH

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).