linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, lm-sensors@lm-sensors.org
Cc: mhoffman@lightlink.com
Subject: [PATCH] i2c: make better use of IDR in i2c-core
Date: Mon, 11 Jul 2005 15:02:57 -0700	[thread overview]
Message-ID: <1121119377358@kroah.com> (raw)
In-Reply-To: <11211193773155@kroah.com>

[PATCH] i2c: make better use of IDR in i2c-core

This patch uses the already existing IDR mechanism to simplify and
improve the i2c_get_adapter function in i2c-core.

Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
commit a0920e10438e9fe8b22aba607083347c84458ed8
tree 8953a2c3c19cab0d4e67fc0e396c23711388403b
parent 5da69ba42aa42a479c0f5d8cb8351ebb6b51c12e
author Mark M. Hoffman <mhoffman@lightlink.com> Tue, 28 Jun 2005 00:21:30 -0400
committer Greg Kroah-Hartman <gregkh@suse.de> Mon, 11 Jul 2005 14:10:36 -0700

 drivers/i2c/i2c-core.c |   17 ++++++-----------
 1 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -156,7 +156,7 @@ int i2c_add_adapter(struct i2c_adapter *
 		goto out_unlock;
 	}
 
-	res = idr_get_new(&i2c_adapter_idr, NULL, &id);
+	res = idr_get_new(&i2c_adapter_idr, adap, &id);
 	if (res < 0) {
 		if (res == -EAGAIN)
 			res = -ENOMEM;
@@ -765,20 +765,15 @@ int i2c_adapter_id(struct i2c_adapter *a
 
 struct i2c_adapter* i2c_get_adapter(int id)
 {
-	struct list_head   *item;
 	struct i2c_adapter *adapter;
 	
 	down(&core_lists);
-	list_for_each(item,&adapters) {
-		adapter = list_entry(item, struct i2c_adapter, list);
-		if (id == adapter->nr &&
-		    try_module_get(adapter->owner)) {
-			up(&core_lists);
-			return adapter;
-		}
-	}
+	adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id);
+	if (adapter && !try_module_get(adapter->owner))
+		adapter = NULL;
+
 	up(&core_lists);
-	return NULL;
+	return adapter;
 }
 
 void i2c_put_adapter(struct i2c_adapter *adap)


  reply	other threads:[~2005-07-11 22:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-11 22:01 [GIT PATCH] I2C patches for 2.6.13-rc2 Greg KH
2005-07-11 22:02 ` [PATCH] I2C: max6875 documentation update Greg KH
2005-07-11 22:02   ` [PATCH] I2C: max6875 Kconfig update Greg KH
2005-07-11 22:02     ` [PATCH] I2C: drop bogus eeprom comment Greg KH
2005-07-11 22:02       ` [PATCH] I2C: Strip trailing whitespace from strings Greg KH
2005-07-11 22:02         ` [PATCH] I2C: m41t00: fix incorrect kfree Greg KH
2005-07-11 22:02           ` [PATCH] I2C: Coding style cleanups to via686a Greg KH
2005-07-11 22:02             ` [PATCH] I2C: minor TPS6501x cleanups Greg KH
2005-07-11 22:02               ` [PATCH] I2C: New max6875 driver may corrupt EEPROMs Greg KH
2005-07-11 22:02                 ` Greg KH [this message]
2005-07-11 22:02                   ` [PATCH] w1: fix CRC calculation on bigendian platforms Greg KH
2005-07-11 22:02                     ` [PATCH] I2C: Clarify the usage of i2c-dev.h Greg KH
2005-07-11 22:02                       ` [PATCH] I2C: minor I2C doc cleanups Greg KH
2005-07-11 22:02                         ` [PATCH] I2C: SENSORS_ATXP1 must select I2C_SENSOR Greg KH
2005-07-11 22:02                           ` [PATCH] I2C: Documentation fix Greg KH
2005-07-11 22:02                             ` [PATCH] I2C: Move hwmon drivers (1/3) 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=1121119377358@kroah.com \
    --to=gregkh@suse.de \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lm-sensors@lm-sensors.org \
    --cc=mhoffman@lightlink.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;
as well as URLs for NNTP newsgroup(s).