2017-03-23 15:04:32

by Arnd Bergmann

[permalink] [raw]
Subject: [PATCH] hwmon: asus_atk0110.c fix uninitialized data access

The latest gcc-7 snapshot adds a warning to point out that when
atk_read_value_old or atk_read_value_new fails, we copy
uninitialized data into sensor->cached_value:

drivers/hwmon/asus_atk0110.c: In function 'atk_input_show':
drivers/hwmon/asus_atk0110.c:651:26: error: 'value' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Adding an error check avoids this. All versions of the driver
are affected.

Fixes: 2c03d07ad54d ("hwmon: Add Asus ATK0110 support")
Signed-off-by: Arnd Bergmann <[email protected]>
---
drivers/hwmon/asus_atk0110.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
index cccef87963e0..975c43d446f8 100644
--- a/drivers/hwmon/asus_atk0110.c
+++ b/drivers/hwmon/asus_atk0110.c
@@ -646,6 +646,9 @@ static int atk_read_value(struct atk_sensor_data *sensor, u64 *value)
else
err = atk_read_value_new(sensor, value);

+ if (err)
+ return err;
+
sensor->is_valid = true;
sensor->last_updated = jiffies;
sensor->cached_value = *value;
--
2.9.0


2017-03-23 15:33:00

by Luca Tettamanti

[permalink] [raw]
Subject: Re: [PATCH] hwmon: asus_atk0110.c fix uninitialized data access

On 23 March 2017 at 16:03, Arnd Bergmann <[email protected]> wrote:
> The latest gcc-7 snapshot adds a warning to point out that when
> atk_read_value_old or atk_read_value_new fails, we copy
> uninitialized data into sensor->cached_value:
>
> drivers/hwmon/asus_atk0110.c: In function 'atk_input_show':
> drivers/hwmon/asus_atk0110.c:651:26: error: 'value' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Ops, thanks for catching this.

>
> Adding an error check avoids this. All versions of the driver
> are affected.
>
> Fixes: 2c03d07ad54d ("hwmon: Add Asus ATK0110 support")
> Signed-off-by: Arnd Bergmann <[email protected]>
Reviewed-by: Luca Tettamanti <[email protected]>


> ---
> drivers/hwmon/asus_atk0110.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
> index cccef87963e0..975c43d446f8 100644
> --- a/drivers/hwmon/asus_atk0110.c
> +++ b/drivers/hwmon/asus_atk0110.c
> @@ -646,6 +646,9 @@ static int atk_read_value(struct atk_sensor_data *sensor, u64 *value)
> else
> err = atk_read_value_new(sensor, value);
>
> + if (err)
> + return err;
> +
> sensor->is_valid = true;
> sensor->last_updated = jiffies;
> sensor->cached_value = *value;
> --
> 2.9.0
>

2017-03-23 20:26:10

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH] hwmon: asus_atk0110.c fix uninitialized data access

On Thu, Mar 23, 2017 at 04:03:11PM +0100, Arnd Bergmann wrote:
> The latest gcc-7 snapshot adds a warning to point out that when
> atk_read_value_old or atk_read_value_new fails, we copy
> uninitialized data into sensor->cached_value:
>
> drivers/hwmon/asus_atk0110.c: In function 'atk_input_show':
> drivers/hwmon/asus_atk0110.c:651:26: error: 'value' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
> Adding an error check avoids this. All versions of the driver
> are affected.
>
Nice catch!

Applied, thanks.

Guenter

> Fixes: 2c03d07ad54d ("hwmon: Add Asus ATK0110 support")
> Signed-off-by: Arnd Bergmann <[email protected]>
> ---
> drivers/hwmon/asus_atk0110.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
> index cccef87963e0..975c43d446f8 100644
> --- a/drivers/hwmon/asus_atk0110.c
> +++ b/drivers/hwmon/asus_atk0110.c
> @@ -646,6 +646,9 @@ static int atk_read_value(struct atk_sensor_data *sensor, u64 *value)
> else
> err = atk_read_value_new(sensor, value);
>
> + if (err)
> + return err;
> +
> sensor->is_valid = true;
> sensor->last_updated = jiffies;
> sensor->cached_value = *value;
> --
> 2.9.0
>