From: Guenter Roeck <linux@roeck-us.net>
To: Kangjie Lu <kjlu@umn.edu>
Cc: pakki001@umn.edu, Jean Delvare <jdelvare@suse.com>,
linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] hwmon: (lm80) fix a missing check of bus read in lm80 probe
Date: Fri, 21 Dec 2018 15:38:36 -0800 [thread overview]
Message-ID: <20181221233836.GA17485@roeck-us.net> (raw)
In-Reply-To: <20181221191039.1519-1-kjlu@umn.edu>
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);
prev parent reply other threads:[~2018-12-21 23:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181221233836.GA17485@roeck-us.net \
--to=linux@roeck-us.net \
--cc=jdelvare@suse.com \
--cc=kjlu@umn.edu \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pakki001@umn.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox