lkml.org 
[lkml]   [2021]   [Feb]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2] hwmon: lm75: Handle broken device nodes gracefully
From
Date
On 2/2/21 6:21 AM, Matwey V. Kornilov wrote:
> There is a logical flaw in lm75_probe() function introduced in
>
> commit e97a45f1b460 ("hwmon: (lm75) Add OF device ID table")
>
> Note, that of_device_get_match_data() returns NULL when no match
> found. This is the case when OF node exists but has unknown

is found.

> compatible line, while the module is still loaded via i2c
> detection.
>
> arch/powerpc/boot/dts/fsl/p2041rdb.dts:
>
> lm75b@48 {
> compatible = "nxp,lm75a";
> reg = <0x48>;
> };
>
> In this case, the sensor is mistakenly considered as ADT75 variant.
>
> Fixes: e97a45f1b460 ("hwmon: (lm75) Add OF device ID table")
> Signed-off-by: Matwey V. Kornilov <matwey@sai.msu.ru>
> ---
> drivers/hwmon/lm75.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
> index e447febd121a..130ad5042107 100644
> --- a/drivers/hwmon/lm75.c
> +++ b/drivers/hwmon/lm75.c
> @@ -561,9 +561,15 @@ static int lm75_probe(struct i2c_client *client)
> int status, err;
> enum lm75_type kind;
>
> - if (client->dev.of_node)
> - kind = (enum lm75_type)of_device_get_match_data(&client->dev);
> - else
> + if (dev->of_node) {
> + const struct of_device_id *match =
> + of_match_device(dev->driver->of_match_table, dev);
> +
> + if (!match)
> + return -ENODEV;
> +
> + kind = (enum lm75_type)(match->data);
> + } else
> kind = i2c_match_id(lm75_ids, client)->driver_data;
>

else needs to be in { } to match if.

Guenter

> if (!i2c_check_functionality(client->adapter,
>

\
 
 \ /
  Last update: 2021-02-02 17:15    [W:0.106 / U:1.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site