public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hwmon: max31790: fix dereference of ERR_PTR
@ 2015-09-16 14:02 Sudip Mukherjee
  2015-09-16 14:09 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Sudip Mukherjee @ 2015-09-16 14:02 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck; +Cc: linux-kernel, lm-sensors, Sudip Mukherjee

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>
---
 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);
-- 
1.9.1


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

* Re: [PATCH] hwmon: max31790: fix dereference of ERR_PTR
  2015-09-16 14:02 [PATCH] hwmon: max31790: fix dereference of ERR_PTR Sudip Mukherjee
@ 2015-09-16 14:09 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2015-09-16 14:09 UTC (permalink / raw)
  To: Sudip Mukherjee, Jean Delvare; +Cc: linux-kernel, lm-sensors

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);
>


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

end of thread, other threads:[~2015-09-16 14:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-16 14:02 [PATCH] hwmon: max31790: fix dereference of ERR_PTR Sudip Mukherjee
2015-09-16 14:09 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox