lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 6 Jun 2013 11:33:46 -0700
From:	Bin Gao <bin.gao@...ux.intel.com>
To:	Wolfram Sang <wsa@...-dreams.de>, linux-i2c@...r.kernel.org
Cc:	linux-kernel@...r.kernel.org
Subject: i2c: introduce i2c helper i2c_find_client_by_name()

i2c: introduce i2c helper i2c_find_client_by_name()

There is a requirement to get the i2c_client pointer dynamically without
knowing the bus and slave address. But we do know the client name,
i.e. the name in the i2c_board_info. This patch is to fit this requirement.

A good example is that an ISP(Imaging Signal Processor) driver needs
register i2c camera sensor devices via v4l2, so it has to unregister
all i2c clients that were previously registered by calling
i2c_register_board_info(), and then re-register. For this case we
can use this helper to get i2c_client by passing the client name.

Signed-off-by: Bin Gao <bin.gao@...ux.intel.com>
---
 drivers/i2c/i2c-core.c |   17 +++++++++++++++++
 include/linux/i2c.h    |    1 +
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 48e31ed..17683de6 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -2326,6 +2326,23 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
 }
 EXPORT_SYMBOL(i2c_smbus_xfer);
 
+static int match_name(struct device *dev, void *data)
+{
+	const char *name = data;
+	struct i2c_client *client = to_i2c_client(dev);
+
+	return !strncmp(client->name, name, strlen(client->name));
+}
+
+struct i2c_client *i2c_find_client_by_name(char *name)
+{
+	struct device *dev;
+
+	dev = bus_find_device(&i2c_bus_type, NULL, name, match_name);
+	return dev ? to_i2c_client(dev) : NULL;
+}
+EXPORT_SYMBOL_GPL(i2c_find_client_by_name);
+
 MODULE_AUTHOR("Simon G. Vogl <simon@...uni-linz.ac.at>");
 MODULE_DESCRIPTION("I2C-Bus main module");
 MODULE_LICENSE("GPL");
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index e988fa9..7d8bf02 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -509,6 +509,7 @@ extern void i2c_clients_command(struct i2c_adapter *adap,
 extern struct i2c_adapter *i2c_get_adapter(int nr);
 extern void i2c_put_adapter(struct i2c_adapter *adap);
 
+extern struct i2c_client *i2c_find_client_by_name(char *name);
 
 /* Return the functionality mask */
 static inline u32 i2c_get_functionality(struct i2c_adapter *adap)
-- 
1.7.4.4

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ