public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Sudip Mukherjee <sudipm.mukherjee@gmail.com>,
	Jean Delvare <jdelvare@suse.com>
Cc: linux-kernel@vger.kernel.org, lm-sensors@lm-sensors.org
Subject: Re: [PATCH] hwmon: max31790: fix dereference of ERR_PTR
Date: Wed, 16 Sep 2015 07:09:39 -0700	[thread overview]
Message-ID: <55F97823.2030307@roeck-us.net> (raw)
In-Reply-To: <1442412179-1547-1-git-send-email-sudipm.mukherjee@gmail.com>

On 09/16/2015 07:02 AM, Sudip Mukherjee wrote:
> max31790_update_device() return the error code in ERR_PTR. We were
> checking if it has returned error or not but before checking we have
> dereferenced it.
>
> Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>

Good catch. Applied.

Thanks,
Guenter

> ---
>   drivers/hwmon/max31790.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c
> index f129668..69c0ac8 100644
> --- a/drivers/hwmon/max31790.c
> +++ b/drivers/hwmon/max31790.c
> @@ -174,12 +174,12 @@ static ssize_t get_fan(struct device *dev,
>   {
>   	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
>   	struct max31790_data *data = max31790_update_device(dev);
> -	int sr = get_tach_period(data->fan_dynamics[attr->index]);
> -	int rpm;
> +	int sr, rpm;
>
>   	if (IS_ERR(data))
>   		return PTR_ERR(data);
>
> +	sr = get_tach_period(data->fan_dynamics[attr->index]);
>   	rpm = RPM_FROM_REG(data->tach[attr->index], sr);
>
>   	return sprintf(buf, "%d\n", rpm);
> @@ -190,12 +190,12 @@ static ssize_t get_fan_target(struct device *dev,
>   {
>   	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
>   	struct max31790_data *data = max31790_update_device(dev);
> -	int sr = get_tach_period(data->fan_dynamics[attr->index]);
> -	int rpm;
> +	int sr, rpm;
>
>   	if (IS_ERR(data))
>   		return PTR_ERR(data);
>
> +	sr = get_tach_period(data->fan_dynamics[attr->index]);
>   	rpm = RPM_FROM_REG(data->target_count[attr->index], sr);
>
>   	return sprintf(buf, "%d\n", rpm);
>


      reply	other threads:[~2015-09-16 14:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-16 14:02 [PATCH] hwmon: max31790: fix dereference of ERR_PTR Sudip Mukherjee
2015-09-16 14:09 ` 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=55F97823.2030307@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=jdelvare@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lm-sensors@lm-sensors.org \
    --cc=sudipm.mukherjee@gmail.com \
    /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