Skip to contentSkip to conversation

hwmon/pmbus: use simple i2c probe function

PATCH Guenter Roeck 2 participants 4 messages Aug 7, 2020 – Aug 8, 2020

Subsystems (2)
lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw
Quoted 27 lines · Stephen Kitt

pmbus_do_probe doesn't use the id information provided in its second argument, so this can be removed, which then allows using the single-parameter i2c probe function ("probe_new") for probes.

This avoids scanning the identifier tables during probes.

Drivers which didn't use the id are converted as-is; drivers which did are modified as follows:

* if the information in i2c_client is sufficient, that's used instead (client->name);
* configured v. probed comparisons are performed by comparing the configured name to the detected name, instead of the ids; this involves strcmp but is still cheaper than comparing all the device names when scanning the tables;
* anything else is handled by calling i2c_match_id() with the same level of error-handling (if any) as before.

---
Changes since v1:
- i2c_device_id declarations are left unchanged;
- all drivers are converted, using client info or i2c_match_id().
Changes since v2:
- updated the documentation;
- fixed unbalanced braces around the modified else in ibm-cffps.c.

[ ... ]

Review static int ltc2978_probe(struct i2c_client *client, · line 672

Quoted 13 lines
(quoted diff) +2 -3
-static int ltc2978_probe(struct i2c_client *client,
-			 const struct i2c_device_id *id)
+static int ltc2978_probe(struct i2c_client *client)
 {
 	int i, chip_id;
 	struct ltc2978_data *data;
@@ -670,10 +669,10 @@ static int ltc2978_probe(struct i2c_client *client,
 		return chip_id;
 
 	data->id = chip_id;
-	if (data->id != id->driver_data)
+	if (strcmp(client->name, ltc2978_id[data->id].name) != 0)

I was about to apply this patch, but this is problematic: It assumes that __stringify(id) == ltc2978_id[id].name and that ltc2978_id[id].driver_data == id. While that is curently the case (as far as I can see), it is still unsafe. I think it would be much safer to use i2c_match_id() here.

Thanks,
Guenter

#1 lore raw
Quoted 11 lines · Guenter Roeck
Quoted 10 lines · Stephen Kitt
(quoted diff) +1 -2
-static int ltc2978_probe(struct i2c_client *client,
-			 const struct i2c_device_id *id)
+static int ltc2978_probe(struct i2c_client *client)
 {
 	int i, chip_id;
 	struct ltc2978_data *data;
@@ -670,10 +669,10 @@ static int ltc2978_probe(struct i2c_client *client,
 		return chip_id;
 
Quoted 8 lines

Review static int ltc2978_probe(struct i2c_client *client, · line 672

Quoted 3 lines
(quoted diff) +1 -1
 	data->id = chip_id;
-	if (data->id != id->driver_data)
+	if (strcmp(client->name, ltc2978_id[data->id].name) != 0)  

I was about to apply this patch, but this is problematic: It assumes that __stringify(id) == ltc2978_id[id].name and that ltc2978_id[id].driver_data == id. While that is curently the case (as far as I can see), it is still unsafe. I think it would be much safer to use i2c_match_id() here.

I’m not following the __stringify assumption, but I do get your point about the driver_data being a valid index into the array; that was already baked into the code, as

		dev_warn(&client->dev,
			 "Device mismatch: Configured %s, detected %s\n",
			 client->name,
			 ltc2978_id[data->id].name);

but I’ll fix both.

Similar assumptions are present in other drivers here IIRC, I’ll fix those too.

Regards,

Stephen

#2 lore raw
Quoted 21 lines · Stephen Kitt
Quoted 11 lines · Guenter Roeck
Quoted 10 lines · Stephen Kitt
(quoted diff) +1 -2
-static int ltc2978_probe(struct i2c_client *client,
-			 const struct i2c_device_id *id)
+static int ltc2978_probe(struct i2c_client *client)
 {
 	int i, chip_id;
 	struct ltc2978_data *data;
@@ -670,10 +669,10 @@ static int ltc2978_probe(struct i2c_client
 *client, return chip_id;
 
Quoted 8 lines

Review static int ltc2978_probe(struct i2c_client · line 672

Quoted 3 lines
(quoted diff) +1 -1
 	data->id = chip_id;
-	if (data->id != id->driver_data)
+	if (strcmp(client->name, ltc2978_id[data->id].name) != 0)    

I was about to apply this patch, but this is problematic: It assumes that __stringify(id) == ltc2978_id[id].name and that ltc2978_id[id].driver_data == id. While that is curently the case (as far as I can see), it is still unsafe. I think it would be much safer to use i2c_match_id() here.

Quoted 1 line

I’m not following the __stringify assumption

[...]

I get it, the code assumes there’s a bijection between the set of names and the set of driver_data values. So effectively we can’t log the detected name based on the chip_id...

Regards,

Stephen

author maintainer
#3 lore raw
Quoted 23 lines · Stephen Kitt
Quoted 21 lines · Stephen Kitt
Quoted 19 lines · Guenter Roeck

Review static int ltc2978_probe(struct i2c_client · line 672

Quoted 13 lines · Stephen Kitt
(quoted diff) +2 -3
-static int ltc2978_probe(struct i2c_client *client,
-			 const struct i2c_device_id *id)
+static int ltc2978_probe(struct i2c_client *client)
 {
 	int i, chip_id;
 	struct ltc2978_data *data;
@@ -670,10 +669,10 @@ static int ltc2978_probe(struct i2c_client
 *client, return chip_id;
 
 	data->id = chip_id;
-	if (data->id != id->driver_data)
+	if (strcmp(client->name, ltc2978_id[data->id].name) != 0)    

I was about to apply this patch, but this is problematic: It assumes that __stringify(id) == ltc2978_id[id].name and that ltc2978_id[id].driver_data == id. While that is curently the case (as far as I can see), it is still unsafe. I think it would be much safer to use i2c_match_id() here.

Quoted 6 lines
Quoted 1 line

I’m not following the __stringify assumption

[...]

I get it, the code assumes there’s a bijection between the set of names and the set of driver_data values. So effectively we can’t log the detected name based on the chip_id...

Exactly.

Thanks,
Guenter