Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1516081 > unrolled thread

[PATCHv7 00/11] i2c: Relax mandatory I2C ID table passing

Started byKieran Bingham <kieran@ksquared.org.uk>
First post2016-11-07 13:50 +0100
Last post2016-11-07 14:00 +0100
Articles 9 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCHv7 00/11] i2c: Relax mandatory I2C ID table passing Kieran Bingham <kieran@ksquared.org.uk> - 2016-11-07 13:50 +0100
    [PATCHv7 06/11] i2c: Provide a temporary .probe_new() call-back type Kieran Bingham <kieran@ksquared.org.uk> - 2016-11-07 13:50 +0100
    [PATCHv7 05/11] i2c: Export i2c_match_id() for direct use by device drivers Kieran Bingham <kieran@ksquared.org.uk> - 2016-11-07 13:50 +0100
    [PATCHv7 08/11] i2c: match vendorless strings on the internal string length Kieran Bingham <kieran@ksquared.org.uk> - 2016-11-07 13:50 +0100
      Re: [PATCHv7 08/11] i2c: match vendorless strings on the internal  string length Javier Martinez Canillas <javier@osg.samsung.com> - 2016-11-07 20:30 +0100
    [PATCHv7 11/11] [TESTPATCH] rtc: convert ds1307 to interim probe_new Kieran Bingham <kieran@ksquared.org.uk> - 2016-11-07 13:50 +0100
    [PATCHv7 02/11] i2c: Add the ability to match device to compatible string without an of_node Kieran Bingham <kieran@ksquared.org.uk> - 2016-11-07 13:50 +0100
    [PATCHv7 01/11] i2c: Add pointer dereference protection to i2c_match_id() Kieran Bingham <kieran@ksquared.org.uk> - 2016-11-07 14:00 +0100
    [PATCHv7 04/11] i2c: Make I2C ID tables non-mandatory for DT'ed devices Kieran Bingham <kieran@ksquared.org.uk> - 2016-11-07 14:00 +0100

#1516081 — [PATCHv7 00/11] i2c: Relax mandatory I2C ID table passing

FromKieran Bingham <kieran@ksquared.org.uk>
Date2016-11-07 13:50 +0100
Subject[PATCHv7 00/11] i2c: Relax mandatory I2C ID table passing
Message-ID<sARx7-3aL-3@gated-at.bofh.it>
Version 7 of this patchset performs a rebase to linux-4.9-rc4 and adjust
the usage of strncasecmps to sysfs_streq. I have also renamed the
function i2c_of_match_device_strip_vendor to i2c_of_match_device_sysfs
which feels more appropriate now.

Retested with successful usage of full compatible strings, and shortened
device id's based on the vendor prefix being stripped.

Wolfram, for your convenience this series is available as a tagged commit
at: https://git.kernel.org/pub/scm/linux/kernel/git/kbingham/linux.git 
i2c-dt/v4.9-rc4-probe-conversion-v7, though this includes the TESTPATCH so
it is not by itself suitable for a merge.

Verifying the sysfs_streq usage can be seen below:

root@arm:~# ./new_i2c_device ds1307 0x68
ds1307 0x68 > /sys/bus/i2c/devices/i2c-2/new_device
[  216.289958] rtc-ds1307 2-0068: rtc core: registered ds1307 as rtc0
[  216.296740] rtc-ds1307 2-0068: 56 bytes nvram
[  216.301534] i2c i2c-2: new_device: Instantiated device ds1307 at 0x68
root@arm:~# 
root@arm:~# cat /sys/class/rtc/rtc0/date 
2016-11-07
root@arm:~# cat /sys/class/rtc/rtc0/name 
ds1307
root@arm:~# ./delete_i2c_device 0x68
[  237.018514] i2c i2c-2: delete_device: Deleting device ds1307 at 0x68
root@arm:~# ./new_i2c_device maxim,ds1307 0x68
maxim,ds1307 0x68 > /sys/bus/i2c/devices/i2c-2/new_device
[  243.346216] rtc-ds1307 2-0068: I'm a Maxim ... 
[  243.370115] rtc-ds1307 2-0068: rtc core: registered maxim,ds1307 as rtc0
[  243.377517] rtc-ds1307 2-0068: 56 bytes nvram
[  243.382343] i2c i2c-2: new_device: Instantiated device maxim,ds1307 at 0x68
root@arm:~# ./delete_i2c_device 0x68
[  263.897905] i2c i2c-2: delete_device: Deleting device maxim,ds1307 at 0x68
root@arm:~# ./new_i2c_device maxim,ds13072 0x68
maxim,ds13072 0x68 > /sys/bus/i2c/devices/i2c-2/new_device
[  266.357120] i2c i2c-2: new_device: Instantiated device maxim,ds13072 at 0x68
root@arm:~# ./delete_i2c_device 0x68
[  268.966851] i2c i2c-2: delete_device: Deleting device maxim,ds13072 at 0x68
root@arm:~# ./new_i2c_device maxim,ds130 0x68
maxim,ds130 0x68 > /sys/bus/i2c/devices/i2c-2/new_device
[  272.005528] i2c i2c-2: new_device: Instantiated device maxim,ds130 at 0x68
root@arm:~# ./delete_i2c_device 0x68
[  274.182360] i2c i2c-2: delete_device: Deleting device maxim,ds130 at 0x68
root@arm:~# ./new_i2c_device ds1307 0x68
ds1307 0x68 > /sys/bus/i2c/devices/i2c-2/new_device
[  281.313329] rtc-ds1307 2-0068: rtc core: registered ds1307 as rtc0
[  281.320218] rtc-ds1307 2-0068: 56 bytes nvram
[  281.325043] i2c i2c-2: new_device: Instantiated device ds1307 at 0x68



Kieran Bingham (3):
  i2c: match dt-style device names from sysfs interface
  i2c: match vendorless strings on the internal string length
  [TESTPATCH] rtc: convert ds1307 to interim probe_new

Lee Jones (8):
  i2c: Add pointer dereference protection to i2c_match_id()
  i2c: Add the ability to match device to compatible string without an
    of_node
  i2c: Match using traditional OF methods, then by vendor-less
    compatible strings
  i2c: Make I2C ID tables non-mandatory for DT'ed devices
  i2c: Export i2c_match_id() for direct use by device drivers
  i2c: Provide a temporary .probe_new() call-back type
  mfd: 88pm860x: Move over to new I2C device .probe() call
  mfd: as3722: Rid driver of superfluous I2C device ID structure

 drivers/i2c/i2c-core.c      | 84 ++++++++++++++++++++++++++++++++++++++++-----
 drivers/mfd/88pm860x-core.c |  5 ++-
 drivers/mfd/as3722.c        | 12 ++-----
 drivers/rtc/rtc-ds1307.c    | 54 ++++++++++++++++-------------
 include/linux/i2c.h         | 22 +++++++++++-
 5 files changed, 131 insertions(+), 46 deletions(-)

-- 
2.7.4

[toc] | [next] | [standalone]


#1516084 — [PATCHv7 06/11] i2c: Provide a temporary .probe_new() call-back type

FromKieran Bingham <kieran@ksquared.org.uk>
Date2016-11-07 13:50 +0100
Subject[PATCHv7 06/11] i2c: Provide a temporary .probe_new() call-back type
Message-ID<sARx8-3aL-27@gated-at.bofh.it>
In reply to#1516081
From: Lee Jones <lee.jones@linaro.org>

This will aid the seamless removal of the current probe()'s, more
commonly unused than used second parameter.  Most I2C drivers can
simply switch over to the new interface, others which have DT
support can use its own matching instead and others can call
i2c_match_id() themselves.  This brings I2C's device probe method
into line with other similar interfaces in the kernel and prevents
the requirement to pass an i2c_device_id table.

Suggested-by: Grant Likely <grant.likely@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
[Kieran: fix rebase conflicts and adapt for dev_pm_domain_{attach,detach}]
Tested-by: Kieran Bingham <kieran@bingham.xyz>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
---
Changes since v4 [Kieran]
 - Rename .probe2 to probe_new
 - Checkpatch warnings fixed

 drivers/i2c/i2c-core.c | 15 ++++++++++++---
 include/linux/i2c.h    |  8 +++++++-
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 48237d035246..3d377598647a 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -924,8 +924,6 @@ static int i2c_device_probe(struct device *dev)
 	}
 
 	driver = to_i2c_driver(dev->driver);
-	if (!driver->probe)
-		return -EINVAL;
 
 	/*
 	 * An I2C ID table is not mandatory, if and only if, a suitable Device
@@ -967,7 +965,18 @@ static int i2c_device_probe(struct device *dev)
 	if (status == -EPROBE_DEFER)
 		goto err_clear_wakeup_irq;
 
-	status = driver->probe(client, i2c_match_id(driver->id_table, client));
+	/*
+	 * When there are no more users of probe(),
+	 * rename probe_new to probe.
+	 */
+	if (driver->probe_new)
+		status = driver->probe_new(client);
+	else if (driver->probe)
+		status = driver->probe(client,
+				       i2c_match_id(driver->id_table, client));
+	else
+		status = -EINVAL;
+
 	if (status)
 		goto err_detach_pm_domain;
 
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 7e00efd6a62f..82cf90945bb8 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -135,7 +135,8 @@ enum i2c_alert_protocol {
  * struct i2c_driver - represent an I2C device driver
  * @class: What kind of i2c device we instantiate (for detect)
  * @attach_adapter: Callback for bus addition (deprecated)
- * @probe: Callback for device binding
+ * @probe: Callback for device binding - soon to be deprecated
+ * @probe_new: New callback for device binding
  * @remove: Callback for device unbinding
  * @shutdown: Callback for device shutdown
  * @alert: Alert callback, for example for the SMBus alert protocol
@@ -178,6 +179,11 @@ struct i2c_driver {
 	int (*probe)(struct i2c_client *, const struct i2c_device_id *);
 	int (*remove)(struct i2c_client *);
 
+	/* New driver model interface to aid the seamless removal of the
+	 * current probe()'s, more commonly unused than used second parameter.
+	 */
+	int (*probe_new)(struct i2c_client *);
+
 	/* driver model interfaces that don't relate to enumeration  */
 	void (*shutdown)(struct i2c_client *);
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1516086 — [PATCHv7 05/11] i2c: Export i2c_match_id() for direct use by device drivers

FromKieran Bingham <kieran@ksquared.org.uk>
Date2016-11-07 13:50 +0100
Subject[PATCHv7 05/11] i2c: Export i2c_match_id() for direct use by device drivers
Message-ID<sARx8-3aL-41@gated-at.bofh.it>
In reply to#1516081
From: Lee Jones <lee.jones@linaro.org>

When there was no other way to match a I2C device to driver i2c_match_id()
was exclusively used.  However, now there are other types of tables which
are commonly supplied, matching on an i2c_device_id table is used less
frequently.  Instead of _always_ calling i2c_match_id() from within the
framework, we only need to do so from drivers which have no other way of
matching.  This patch makes i2c_match_id() available to the aforementioned
device drivers.

Acked-by: Grant Likely <grant.likely@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Tested-by: Kieran Bingham <kieran@bingham.xyz>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
---
 drivers/i2c/i2c-core.c | 3 ++-
 include/linux/i2c.h    | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 6439174c0ff5..48237d035246 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -676,7 +676,7 @@ static inline int i2c_acpi_install_space_handler(struct i2c_adapter *adapter)
 
 /* ------------------------------------------------------------------------- */
 
-static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
+const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
 						const struct i2c_client *client)
 {
 	if (!(id && client))
@@ -689,6 +689,7 @@ static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
 	}
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(i2c_match_id);
 
 static int i2c_device_match(struct device *dev, struct device_driver *drv)
 {
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index c0a4a12815aa..7e00efd6a62f 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -243,6 +243,8 @@ struct i2c_client {
 
 extern struct i2c_client *i2c_verify_client(struct device *dev);
 extern struct i2c_adapter *i2c_verify_adapter(struct device *dev);
+extern const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
+					const struct i2c_client *client);
 
 static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
 {
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1516088 — [PATCHv7 08/11] i2c: match vendorless strings on the internal string length

FromKieran Bingham <kieran@ksquared.org.uk>
Date2016-11-07 13:50 +0100
Subject[PATCHv7 08/11] i2c: match vendorless strings on the internal string length
Message-ID<sARx8-3aL-31@gated-at.bofh.it>
In reply to#1516081
If a user provides a shortened string to match a device to the sysfs i2c
interface it will match on the first string that contains that string
prefix.

for example:
  echo a 0x68 > /sys/bus/i2c/devices/i2c-2/new_device
will match as3711, as3722, and ak8975 incorrectly.

Correct this by using sysfs_streq to match the string exactly

Signed-off-by: Kieran Bingham <kieran@bingham.xyz>

---
Changes from v7
 - strncasecmp usage converted to sysfs_streq

 drivers/i2c/i2c-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index c338c8f3b3db..8b93a262e237 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1810,7 +1810,7 @@ i2c_of_match_device_sysfs(const struct of_device_id *matches,
 		else
 			name++;
 
-		if (!strncasecmp(client->name, name, strlen(client->name)))
+		if (sysfs_streq(client->name, name))
 			return matches;
 	}
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1516529 — Re: [PATCHv7 08/11] i2c: match vendorless strings on the internal string length

FromJavier Martinez Canillas <javier@osg.samsung.com>
Date2016-11-07 20:30 +0100
SubjectRe: [PATCHv7 08/11] i2c: match vendorless strings on the internal string length
Message-ID<sAXMd-7uI-7@gated-at.bofh.it>
In reply to#1516088
Hello Kieran,

On 11/07/2016 09:47 AM, Kieran Bingham wrote:
> If a user provides a shortened string to match a device to the sysfs i2c
> interface it will match on the first string that contains that string
> prefix.
> 
> for example:
>   echo a 0x68 > /sys/bus/i2c/devices/i2c-2/new_device
> will match as3711, as3722, and ak8975 incorrectly.
> 
> Correct this by using sysfs_streq to match the string exactly
> 
> Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
> 

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
-- 
Javier Martinez Canillas
Open Source Group
Samsung Research America

[toc] | [prev] | [next] | [standalone]


#1516089 — [PATCHv7 11/11] [TESTPATCH] rtc: convert ds1307 to interim probe_new

FromKieran Bingham <kieran@ksquared.org.uk>
Date2016-11-07 13:50 +0100
Subject[PATCHv7 11/11] [TESTPATCH] rtc: convert ds1307 to interim probe_new
Message-ID<sARx8-3aL-37@gated-at.bofh.it>
In reply to#1516081
Just for testing, specify a maxim,ds1307 device to identify the code path used
when instantiating the driver from userspace.

root@arm:~# echo maxim,ds1307 0x68 > /sys/bus/i2c/devices/i2c-2/new_device
[   49.807383] rtc-ds1307 2-0068: I'm a Maxim ...
[   49.814706] rtc-ds1307 2-0068: rtc core: registered maxim,ds1307 as rtc0
[   49.821813] rtc-ds1307 2-0068: 56 bytes nvram
[   49.826444] i2c i2c-2: new_device: Instantiated device maxim,ds1307 at 0x68

This patch also demonstrates how to obtain data from the id's using the
new methods.
---
 drivers/rtc/rtc-ds1307.c | 54 +++++++++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 23 deletions(-)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 4e31036ee259..a5b744e9716c 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -31,6 +31,7 @@
  */
 enum ds_type {
 	ds_1307,
+	maxim_1307,
 	ds_1337,
 	ds_1338,
 	ds_1339,
@@ -144,6 +145,10 @@ static struct chip_desc chips[last_ds_type] = {
 		.nvram_offset	= 8,
 		.nvram_size	= 56,
 	},
+	[maxim_1307] = {
+		.nvram_offset	= 8,
+		.nvram_size	= 56,
+	},
 	[ds_1337] = {
 		.alarm		= 1,
 	},
@@ -173,23 +178,6 @@ static struct chip_desc chips[last_ds_type] = {
 	},
 };
 
-static const struct i2c_device_id ds1307_id[] = {
-	{ "ds1307", ds_1307 },
-	{ "ds1337", ds_1337 },
-	{ "ds1338", ds_1338 },
-	{ "ds1339", ds_1339 },
-	{ "ds1388", ds_1388 },
-	{ "ds1340", ds_1340 },
-	{ "ds3231", ds_3231 },
-	{ "m41t00", m41t00 },
-	{ "mcp7940x", mcp794xx },
-	{ "mcp7941x", mcp794xx },
-	{ "pt7c4338", ds_1307 },
-	{ "rx8025", rx_8025 },
-	{ "isl12057", ds_1337 },
-	{ }
-};
-MODULE_DEVICE_TABLE(i2c, ds1307_id);
 
 /*----------------------------------------------------------------------*/
 
@@ -1262,13 +1250,20 @@ static void ds1307_clks_register(struct ds1307 *ds1307)
 
 #endif /* CONFIG_COMMON_CLK */
 
-static int ds1307_probe(struct i2c_client *client,
-			const struct i2c_device_id *id)
+static const struct of_device_id ds1307_dt_ids[] = {
+	{ .compatible = "dallas,ds1307", .data = (void *)ds_1307 },
+	{ .compatible = "maxim,ds1307", .data = (void *)maxim_1307 },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, ds1307_dt_ids);
+
+static int ds1307_probe(struct i2c_client *client)
 {
 	struct ds1307		*ds1307;
 	int			err = -ENODEV;
 	int			tmp, wday;
-	struct chip_desc	*chip = &chips[id->driver_data];
+	const struct of_device_id 	*idof;
+	struct chip_desc	*chip;
 	struct i2c_adapter	*adapter = to_i2c_adapter(client->dev.parent);
 	bool			want_irq = false;
 	bool			ds1307_can_wakeup_device = false;
@@ -1294,10 +1289,20 @@ static int ds1307_probe(struct i2c_client *client,
 	if (!ds1307)
 		return -ENOMEM;
 
+	/* If we've got this far, this shouldn't be able to fail - but check anyway for now */
+	idof = i2c_of_match_device(ds1307_dt_ids, client);
+	if (!idof) {
+		dev_err(&client->dev, "Probe failed to find an id entry\n");
+		return -ENODEV;
+	}
+
+	/* Now we can set our chip entry */
+	chip = &chips[(int)idof->data];
+
 	i2c_set_clientdata(client, ds1307);
 
 	ds1307->client	= client;
-	ds1307->type	= id->driver_data;
+	ds1307->type	= (int) idof->data;
 
 	if (!pdata && client->dev.of_node)
 		ds1307_trickle_of_init(client, chip);
@@ -1479,6 +1484,9 @@ static int ds1307_probe(struct i2c_client *client,
 	 */
 	tmp = ds1307->regs[DS1307_REG_SECS];
 	switch (ds1307->type) {
+	case maxim_1307:
+		dev_info(&client->dev, "I'm a Maxim ... \n");
+		/* fallthrough */
 	case ds_1307:
 	case m41t00:
 		/* clock halted?  turn it on, so clock can tick. */
@@ -1678,10 +1686,10 @@ static int ds1307_remove(struct i2c_client *client)
 static struct i2c_driver ds1307_driver = {
 	.driver = {
 		.name	= "rtc-ds1307",
+		.of_match_table = of_match_ptr(ds1307_dt_ids),
 	},
-	.probe		= ds1307_probe,
+	.probe_new	= ds1307_probe,
 	.remove		= ds1307_remove,
-	.id_table	= ds1307_id,
 };
 
 module_i2c_driver(ds1307_driver);
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1516091 — [PATCHv7 02/11] i2c: Add the ability to match device to compatible string without an of_node

FromKieran Bingham <kieran@ksquared.org.uk>
Date2016-11-07 13:50 +0100
Subject[PATCHv7 02/11] i2c: Add the ability to match device to compatible string without an of_node
Message-ID<sARx8-3aL-45@gated-at.bofh.it>
In reply to#1516081
From: Lee Jones <lee.jones@linaro.org>

A great deal of I2C devices are currently matched via DT node name, and
as such the compatible naming convention of '<vendor>,<device>' has gone
somewhat awry - some nodes don't supply one, some supply an arbitrary
string and others the correct device name with an arbitrary vendor prefix.

In an effort to correct this problem we have to supply a mechanism to
match a device by compatible string AND by simple device name.  This
function strips off the '<vendor>,' part of a supplied compatible string
and attempts to match without it.

The plan is to remove this function once all of the compatible strings
for each device have been brought into line.

Acked-by: Grant Likely <grant.likely@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
[Kieran: strnicmp to strncasecmp]
Tested-by: Kieran Bingham <kieran@bingham.xyz>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>

---
changes from v6
 - Rename i2c_of_match_device_strip_vendor to i2c_of_match_device_sysfs

 drivers/i2c/i2c-core.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 86083e5e5520..dcbda850804f 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1769,6 +1769,27 @@ struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node)
 	return adapter;
 }
 EXPORT_SYMBOL(of_get_i2c_adapter_by_node);
+
+static const struct of_device_id*
+i2c_of_match_device_sysfs(const struct of_device_id *matches,
+				  struct i2c_client *client)
+{
+	const char *name;
+
+	for (; matches->compatible[0]; matches++) {
+		name = strchr(matches->compatible, ',');
+		if (!name)
+			name = matches->compatible;
+		else
+			name++;
+
+		if (!strncasecmp(client->name, name, strlen(client->name)))
+			return matches;
+	}
+
+	return NULL;
+}
+
 #else
 static void of_i2c_register_devices(struct i2c_adapter *adap) { }
 #endif /* CONFIG_OF */
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1516095 — [PATCHv7 01/11] i2c: Add pointer dereference protection to i2c_match_id()

FromKieran Bingham <kieran@ksquared.org.uk>
Date2016-11-07 14:00 +0100
Subject[PATCHv7 01/11] i2c: Add pointer dereference protection to i2c_match_id()
Message-ID<sARGT-3e5-27@gated-at.bofh.it>
In reply to#1516081
From: Lee Jones <lee.jones@linaro.org>

Here we're providing dereference protection for i2c_match_id(), which
saves us having to do it each time it's called.  We're also stripping
out the (now) needless checks in i2c_device_match().  This patch paves
the way for other, similar code trimming.

Acked-by: Grant Likely <grant.likely@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Tested-by: Kieran Bingham <kieran@bingham.xyz>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
---
 drivers/i2c/i2c-core.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index b432b64e307a..86083e5e5520 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -679,6 +679,9 @@ static inline int i2c_acpi_install_space_handler(struct i2c_adapter *adapter)
 static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
 						const struct i2c_client *client)
 {
+	if (!(id && client))
+		return NULL;
+
 	while (id->name[0]) {
 		if (strcmp(client->name, id->name) == 0)
 			return id;
@@ -692,8 +695,6 @@ static int i2c_device_match(struct device *dev, struct device_driver *drv)
 	struct i2c_client	*client = i2c_verify_client(dev);
 	struct i2c_driver	*driver;
 
-	if (!client)
-		return 0;
 
 	/* Attempt an OF style match */
 	if (of_driver_match_device(dev, drv))
@@ -704,9 +705,10 @@ static int i2c_device_match(struct device *dev, struct device_driver *drv)
 		return 1;
 
 	driver = to_i2c_driver(drv);
-	/* match on an id table if there is one */
-	if (driver->id_table)
-		return i2c_match_id(driver->id_table, client) != NULL;
+
+	/* Finally an I2C match */
+	if (i2c_match_id(driver->id_table, client))
+		return 1;
 
 	return 0;
 }
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1516097 — [PATCHv7 04/11] i2c: Make I2C ID tables non-mandatory for DT'ed devices

FromKieran Bingham <kieran@ksquared.org.uk>
Date2016-11-07 14:00 +0100
Subject[PATCHv7 04/11] i2c: Make I2C ID tables non-mandatory for DT'ed devices
Message-ID<sARGT-3e5-31@gated-at.bofh.it>
In reply to#1516081
From: Lee Jones <lee.jones@linaro.org>

Currently the I2C framework insists on devices supplying an I2C ID
table.  Many of the devices which do so unnecessarily adding quite a
few wasted lines to kernel code.  This patch allows drivers a means
to 'not' supply the aforementioned table and match on DT match tables
instead.

Acked-by: Grant Likely <grant.likely@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Tested-by: Kieran Bingham <kieran@bingham.xyz>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
---
 drivers/i2c/i2c-core.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 2adf4a1ed7ca..6439174c0ff5 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -697,7 +697,7 @@ static int i2c_device_match(struct device *dev, struct device_driver *drv)
 
 
 	/* Attempt an OF style match */
-	if (of_driver_match_device(dev, drv))
+	if (i2c_of_match_device(drv->of_match_table, client))
 		return 1;
 
 	/* Then ACPI style match */
@@ -923,7 +923,15 @@ static int i2c_device_probe(struct device *dev)
 	}
 
 	driver = to_i2c_driver(dev->driver);
-	if (!driver->probe || !driver->id_table)
+	if (!driver->probe)
+		return -EINVAL;
+
+	/*
+	 * An I2C ID table is not mandatory, if and only if, a suitable Device
+	 * Tree match table entry is supplied for the probing device.
+	 */
+	if (!driver->id_table &&
+	    !i2c_of_match_device(dev->driver->of_match_table, client))
 		return -ENODEV;
 
 	if (client->flags & I2C_CLIENT_WAKE) {
-- 
2.7.4

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web