From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org, sensors@stimpy.netroedge.com
Subject: [PATCH] I2C update for 2.6.7-rc1
Date: Fri, 28 May 2004 15:00:43 -0700 [thread overview]
Message-ID: <1085781643100@kroah.com> (raw)
In-Reply-To: <20040528215908.GA13626@kroah.com>
ChangeSet 1.1717.6.23, 2004/05/19 00:24:54-07:00, faikuygur@tnn.net
[PATCH] I2C: use idr_get_new to allocate a bus id in drivers/i2c/i2c-core.c
drivers/i2c/i2c-core.c | 21 +++++++++++++++++----
1 files changed, 17 insertions(+), 4 deletions(-)
diff -Nru a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
--- a/drivers/i2c/i2c-core.c Fri May 28 14:52:36 2004
+++ b/drivers/i2c/i2c-core.c Fri May 28 14:52:36 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,19 @@
*/
int i2c_add_adapter(struct i2c_adapter *adap)
{
- static int nr = 0;
+ int id, res = 0;
struct list_head *item;
struct i2c_driver *driver;
down(&core_lists);
- adap->nr = nr++;
+ if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) {
+ res = -ENOMEM;
+ goto out_unlock;
+ }
+
+ 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);
@@ -151,10 +159,12 @@
/* We ignore the return code; if it fails, too bad */
driver->attach_adapter(adap);
}
- up(&core_lists);
dev_dbg(&adap->dev, "registered as adapter #%d\n", adap->nr);
- return 0;
+
+ out_unlock:
+ up(&core_lists);
+ return res;
}
@@ -207,6 +217,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");
next prev parent reply other threads:[~2004-05-28 22:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-28 21:59 [BK PATCH] I2C update for 2.6.7-rc1 Greg KH
2004-05-28 22:00 ` Greg KH [this message]
2004-05-28 22:00 ` [PATCH] " Greg KH
2004-05-28 22:00 ` Greg KH
2004-05-28 22:00 ` Greg KH
2004-05-28 22:00 ` Greg KH
2004-05-28 22:00 ` Greg KH
2004-05-28 22:00 ` Greg KH
2004-05-28 22:00 ` 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=1085781643100@kroah.com \
--to=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sensors@stimpy.netroedge.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox