Linux-Hwmon Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] hwmon: (lm80) fix a missing check of bus read in lm80 probe
@ 2018-12-21 19:10 Kangjie Lu
  2018-12-21 23:38 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Kangjie Lu @ 2018-12-21 19:10 UTC (permalink / raw)
  To: kjlu; +Cc: pakki001, Jean Delvare, Guenter Roeck, linux-hwmon, linux-kernel

In lm80_probe(), if lm80_read_value() fails, it returns a negative
error number which is stored to data->fan[f_min] and will be further
used. We should avoid using the data if the read fails.

The fix checks if lm80_read_value() fails, and if so, returns with the
error number.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/hwmon/lm80.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
index d91333557f04..85f797501aaf 100644
--- a/drivers/hwmon/lm80.c
+++ b/drivers/hwmon/lm80.c
@@ -627,6 +627,7 @@ static int lm80_probe(struct i2c_client *client,
 	struct device *dev = &client->dev;
 	struct device *hwmon_dev;
 	struct lm80_data *data;
+	int rv;
 
 	data = devm_kzalloc(dev, sizeof(struct lm80_data), GFP_KERNEL);
 	if (!data)
@@ -639,8 +640,14 @@ static int lm80_probe(struct i2c_client *client,
 	lm80_init_client(client);
 
 	/* A few vars need to be filled upon startup */
-	data->fan[f_min][0] = lm80_read_value(client, LM80_REG_FAN_MIN(1));
-	data->fan[f_min][1] = lm80_read_value(client, LM80_REG_FAN_MIN(2));
+	rv = lm80_read_value(client, LM80_REG_FAN_MIN(1));
+	if (rv < 0)
+		return rv;
+	data->fan[f_min][0] = rv;
+	rv = lm80_read_value(client, LM80_REG_FAN_MIN(2));
+	if (rv < 0)
+		return rv;
+	data->fan[f_min][1] = rv;
 
 	hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
 							   data, lm80_groups);
-- 
2.17.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] hwmon: (lm80) fix a missing check of bus read in lm80 probe
  2018-12-21 19:10 [PATCH v2] hwmon: (lm80) fix a missing check of bus read in lm80 probe Kangjie Lu
@ 2018-12-21 23:38 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2018-12-21 23:38 UTC (permalink / raw)
  To: Kangjie Lu; +Cc: pakki001, Jean Delvare, linux-hwmon, linux-kernel

On Fri, Dec 21, 2018 at 01:10:39PM -0600, Kangjie Lu wrote:
> In lm80_probe(), if lm80_read_value() fails, it returns a negative
> error number which is stored to data->fan[f_min] and will be further
> used. We should avoid using the data if the read fails.
> 
> The fix checks if lm80_read_value() fails, and if so, returns with the
> error number.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/lm80.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
> index d91333557f04..85f797501aaf 100644
> --- a/drivers/hwmon/lm80.c
> +++ b/drivers/hwmon/lm80.c
> @@ -627,6 +627,7 @@ static int lm80_probe(struct i2c_client *client,
>  	struct device *dev = &client->dev;
>  	struct device *hwmon_dev;
>  	struct lm80_data *data;
> +	int rv;
>  
>  	data = devm_kzalloc(dev, sizeof(struct lm80_data), GFP_KERNEL);
>  	if (!data)
> @@ -639,8 +640,14 @@ static int lm80_probe(struct i2c_client *client,
>  	lm80_init_client(client);
>  
>  	/* A few vars need to be filled upon startup */
> -	data->fan[f_min][0] = lm80_read_value(client, LM80_REG_FAN_MIN(1));
> -	data->fan[f_min][1] = lm80_read_value(client, LM80_REG_FAN_MIN(2));
> +	rv = lm80_read_value(client, LM80_REG_FAN_MIN(1));
> +	if (rv < 0)
> +		return rv;
> +	data->fan[f_min][0] = rv;
> +	rv = lm80_read_value(client, LM80_REG_FAN_MIN(2));
> +	if (rv < 0)
> +		return rv;
> +	data->fan[f_min][1] = rv;
>  
>  	hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
>  							   data, lm80_groups);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-21 19:10 [PATCH v2] hwmon: (lm80) fix a missing check of bus read in lm80 probe Kangjie Lu
2018-12-21 23:38 ` Guenter Roeck

Linux-Hwmon Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hwmon/0 linux-hwmon/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hwmon linux-hwmon/ https://lore.kernel.org/linux-hwmon \
		linux-hwmon@vger.kernel.org linux-hwmon@archiver.kernel.org
	public-inbox-index linux-hwmon


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hwmon


AGPL code for this site: git clone https://public-inbox.org/ public-inbox