Skip to contentSkip to conversation

iio: light: vcnl4035: fixed chip ID check

PATCH Superseded Frank Li 3 participants 4 messages Apr 27, 2023 – Apr 30, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Frank Li

author maintainer
#0 lore raw

PATCH 1/1 iio: light: vcnl4035: fixed chip ID check

VCNL4035 register(0xE) ID_L and ID_M define as:

ID_L: 0x80
ID_H: 7:6 (0:0)

       5:4 (0:0) slave address = 0x60 (7-bit)
           (0:1) slave address = 0x51 (7-bit)
           (1:0) slave address = 0x40 (7-bit)
           (1:0) slave address = 0x41 (7-bit)
       3:0 Version code default	(0:0:0:0)

So just check ID_L.

Fixes 55707294c4eb ("iio: light: Add support for vishay vcnl4035")
---
 drivers/iio/light/vcnl4035.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/vcnl4035.c +1 -1
index 3ed37f6057fb..8b7769930f3b 100644
@@ -413,7 +413,7 @@ static int vcnl4035_init(struct vcnl4035_data *data)
 		return ret;
 	}
 
-	if (id != VCNL4035_DEV_ID_VAL) {
+	if ((id & 0xff) != VCNL4035_DEV_ID_VAL) {
 		dev_err(&data->client->dev, "Wrong id, got %x, expected %x\n",
 			id, VCNL4035_DEV_ID_VAL);
 		return -ENODEV;
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 11 lines · On Thu, 27 Apr 2023 17:30:37 -0400 Frank Li <[email protected]> wrote:

VCNL4035 register(0xE) ID_L and ID_M define as:

ID_L: 0x80
ID_H: 7:6 (0:0)

       5:4 (0:0) slave address = 0x60 (7-bit)
           (0:1) slave address = 0x51 (7-bit)
           (1:0) slave address = 0x40 (7-bit)
           (1:0) slave address = 0x41 (7-bit)
       3:0 Version code default	(0:0:0:0)

So just check ID_L.

Hi Frank,

Thanks for the fix. A few minor things inline.

Quoted 3 lines
Fixes 55707294c4eb ("iio: light: Add support for vishay vcnl4035")

No blank line here as the Fixes tag is part of the main tag block.

Quoted 1 line

Just to check, the result of this bug is that the driver probe fails if the slave address isn't 0x60?

Quoted 9 lines
---
 drivers/iio/light/vcnl4035.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/vcnl4035.c +0 -0
index 3ed37f6057fb..8b7769930f3b 100644

drivers/iio/light/vcnl4035.c static int vcnl4035_init(struct vcnl4035_data *data) · line 416

Quoted 5 lines
drivers/iio/light/vcnl4035.c +1 -1
@@ -413,7 +413,7 @@ static int vcnl4035_init(struct vcnl4035_data *data)
 		return ret;
 	}
 
-	if (id != VCNL4035_DEV_ID_VAL) {
+	if ((id & 0xff) != VCNL4035_DEV_ID_VAL) {

Please add a define for that 0xff mask and perhaps also use FIELD_GET() to extract the field for comparison with VCNL4035_DEV_ID_VAL. Whilst that isn't being done elsewhere in this driver, the heavy use of set bits means it isn't appropriate anywhere else that I can quickly identify. You'll also need to include linux/bitfield.h if making that change.

Thanks,

Jonathan

Quoted 3 lines
drivers/iio/light/vcnl4035.c +0 -0
 		dev_err(&data->client->dev, "Wrong id, got %x, expected %x\n",
 			id, VCNL4035_DEV_ID_VAL);
 		return -ENODEV;
author maintainer
#2 lore raw
Quoted 44 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, April 30, 2023 12:23 PM
To: Frank Li <[email protected]>
Cc: Lars-Peter Clausen <[email protected]>; Uwe Kleine-König <u.kleine- [email protected]>; Petr Machata <[email protected]>; Heikki Krogerus <[email protected]>; Jean Delvare <[email protected]>; Andy Shevchenko <[email protected]>; Parthiban Nallathambi <[email protected]>; open list:IIO SUBSYSTEM AND DRIVERS <linux- [email protected]>; open list <[email protected]>; [email protected]
Subject: [EXT] Re: [PATCH 1/1] iio: light: vcnl4035: fixed chip ID check

Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button

Quoted 11 lines · On Thu, 27 Apr 2023 17:30:37 -0400 Frank Li <[email protected]> wrote:

VCNL4035 register(0xE) ID_L and ID_M define as:

ID_L: 0x80
ID_H: 7:6 (0:0)

       5:4 (0:0) slave address = 0x60 (7-bit)
           (0:1) slave address = 0x51 (7-bit)
           (1:0) slave address = 0x40 (7-bit)
           (1:0) slave address = 0x41 (7-bit)
       3:0 Version code default       (0:0:0:0)

So just check ID_L.

Hi Frank,

Thanks for the fix. A few minor things inline.

Quoted 3 lines
Fixes 55707294c4eb ("iio: light: Add support for vishay vcnl4035")
Quoted 6 lines

No blank line here as the Fixes tag is part of the main tag block.

Quoted 1 line

Just to check, the result of this bug is that the driver probe fails if the slave address isn't 0x60?

Yes, I get chip which slave address = 0x51.
I will update patch soon.

Quoted 29 lines
Quoted 10 lines
---
 drivers/iio/light/vcnl4035.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/vcnl4035.c +0 -0
index 3ed37f6057fb..8b7769930f3b 100644

drivers/iio/light/vcnl4035.c static int vcnl4035_init(struct vcnl4035_data *data) · line 416

Quoted 5 lines
drivers/iio/light/vcnl4035.c +1 -1
@@ -413,7 +413,7 @@ static int vcnl4035_init(struct vcnl4035_data *data)
              return ret;
      }
 
-     if (id != VCNL4035_DEV_ID_VAL) {
+     if ((id & 0xff) != VCNL4035_DEV_ID_VAL) {

Please add a define for that 0xff mask and perhaps also use FIELD_GET() to extract the field for comparison with VCNL4035_DEV_ID_VAL. Whilst that isn't being done elsewhere in this driver, the heavy use of set bits means it isn't appropriate anywhere else that I can quickly identify. You'll also need to include linux/bitfield.h if making that change.

Thanks,

Jonathan

Quoted 3 lines
drivers/iio/light/vcnl4035.c +0 -0
              dev_err(&data->client->dev, "Wrong id, got %x, expected %x\n",
                      id, VCNL4035_DEV_ID_VAL);
              return -ENODEV;
#3 lore raw
In reply to Frank Li

Le 27/04/2023 à 23:30, Frank Li a écrit :

Quoted 24 lines

VCNL4035 register(0xE) ID_L and ID_M define as:

ID_L: 0x80
ID_H: 7:6 (0:0)

        5:4 (0:0) slave address = 0x60 (7-bit)
            (0:1) slave address = 0x51 (7-bit)
            (1:0) slave address = 0x40 (7-bit)
            (1:0) slave address = 0x41 (7-bit)
        3:0 Version code default	(0:0:0:0)

So just check ID_L.

Fixes 55707294c4eb ("iio: light: Add support for vishay vcnl4035")
---
  drivers/iio/light/vcnl4035.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/vcnl4035.c +0 -0
index 3ed37f6057fb..8b7769930f3b 100644

drivers/iio/light/vcnl4035.c static int vcnl4035_init(struct vcnl4035_data *data) · line 418

Quoted 7 lines
drivers/iio/light/vcnl4035.c +1 -1
@@ -413,7 +413,7 @@ static int vcnl4035_init(struct vcnl4035_data *data)
  		return ret;
  	}
 
-	if (id != VCNL4035_DEV_ID_VAL) {
+	if ((id & 0xff) != VCNL4035_DEV_ID_VAL) {
  		dev_err(&data->client->dev, "Wrong id, got %x, expected %x\n",
  			id, VCNL4035_DEV_ID_VAL);

Hi,
should the error message be updated as well?

Cj

Quoted 1 line
drivers/iio/light/vcnl4035.c +0 -0
  		return -ENODEV;