diff mbox

[PATCHv7,07/11] i2c: match dt-style device names from sysfs interface

Message ID 1478522866-29620-8-git-send-email-kieran@bingham.xyz
State Accepted
Headers show

Commit Message

Kieran Bingham Nov. 7, 2016, 12:47 p.m. UTC
A user can choose to instantiate a device on an i2c bus using the sysfs
interface by providing a string and address to match and communicate
with the device on the bus. Presently this string is only matched
against the old i2c device id style strings, even in the presence of
full device tree compatible strings with vendor prefixes.

Providing a vendor-prefixed string to the sysfs interface will not match
against the device tree of_match_device() calls as there is no device
tree node to parse from the sysfs interface.

Convert i2c_of_match_device_strip_vendor() such that it can match both
vendor prefixed and stripped compatible strings on the sysfs interface.

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

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

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

Comments

Javier Martinez Canillas Nov. 7, 2016, 7:10 p.m. UTC | #1
Hello Kieran,

On 11/07/2016 09:47 AM, Kieran Bingham wrote:
> A user can choose to instantiate a device on an i2c bus using the sysfs
> interface by providing a string and address to match and communicate
> with the device on the bus. Presently this string is only matched
> against the old i2c device id style strings, even in the presence of
> full device tree compatible strings with vendor prefixes.
> 
> Providing a vendor-prefixed string to the sysfs interface will not match
> against the device tree of_match_device() calls as there is no device
> tree node to parse from the sysfs interface.
> 
> Convert i2c_of_match_device_strip_vendor() such that it can match both
> vendor prefixed and stripped compatible strings on the sysfs interface.
> 
> Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
>

Patch looks good to me.

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

Best regards,
Wolfram Sang Nov. 14, 2016, 10:27 p.m. UTC | #2
On Mon, Nov 07, 2016 at 12:47:42PM +0000, Kieran Bingham wrote:
> A user can choose to instantiate a device on an i2c bus using the sysfs
> interface by providing a string and address to match and communicate
> with the device on the bus. Presently this string is only matched
> against the old i2c device id style strings, even in the presence of
> full device tree compatible strings with vendor prefixes.
> 
> Providing a vendor-prefixed string to the sysfs interface will not match
> against the device tree of_match_device() calls as there is no device
> tree node to parse from the sysfs interface.
> 
> Convert i2c_of_match_device_strip_vendor() such that it can match both

The function name here is the old one...

> vendor prefixed and stripped compatible strings on the sysfs interface.
> 
> Signed-off-by: Kieran Bingham <kieran@bingham.xyz>

... and in patch 2, the sentence "remove this function if all drivers
are converted" is obsolete, too, since we need this function always for
sysfs.

This make me wonder if we shouldn't squash this patch also in into patch
2 (like I suggested for the next one), and create a best-of-all-worlds
commit message from these three patches?

Opinions?
Kieran Bingham Nov. 15, 2016, 9:48 a.m. UTC | #3
On 14/11/16 22:27, Wolfram Sang wrote:
> On Mon, Nov 07, 2016 at 12:47:42PM +0000, Kieran Bingham wrote:
>> A user can choose to instantiate a device on an i2c bus using the sysfs
>> interface by providing a string and address to match and communicate
>> with the device on the bus. Presently this string is only matched
>> against the old i2c device id style strings, even in the presence of
>> full device tree compatible strings with vendor prefixes.
>>
>> Providing a vendor-prefixed string to the sysfs interface will not match
>> against the device tree of_match_device() calls as there is no device
>> tree node to parse from the sysfs interface.
>>
>> Convert i2c_of_match_device_strip_vendor() such that it can match both
> 
> The function name here is the old one...
> 
>> vendor prefixed and stripped compatible strings on the sysfs interface.
>>
>> Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
> 
> ... and in patch 2, the sentence "remove this function if all drivers
> are converted" is obsolete, too, since we need this function always for
> sysfs.
> 
> This make me wonder if we shouldn't squash this patch also in into patch
> 2 (like I suggested for the next one), and create a best-of-all-worlds
> commit message from these three patches?
> 
> Opinions?

That's fine with me - My main reason for keeping them separate during
posting was so that the changes I had made could be seen - but yes - I
think they probably are eligible for squashing.
diff mbox

Patch

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 3d377598647a..c338c8f3b3db 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1795,6 +1795,15 @@  i2c_of_match_device_sysfs(const struct of_device_id *matches,
 	const char *name;
 
 	for (; matches->compatible[0]; matches++) {
+		/*
+		 * Adding devices through the i2c sysfs interface provides us
+		 * a string to match which may be compatible with the device
+		 * tree compatible strings, however with no actual of_node the
+		 * of_match_device() will not match
+		 */
+		if (sysfs_streq(client->name, matches->compatible))
+			return matches;
+
 		name = strchr(matches->compatible, ',');
 		if (!name)
 			name = matches->compatible;