2010-11-09 08:38:07

by Axel Lin

[permalink] [raw]
Subject: [PATCH v2] hwmon: (gpio-fan) Fix fan_ctrl_init error path

In current implementation, the sysfs entries is not removed before return -ENODEV.

Creating the sysfs attribute should be the last thing done by the function,
after all the rest has been successful.
Otherwise there is a small window during which user-space can access the attribute
but the driver isn't ready to deal with the requests.

Fix it by moving sysfs_create_group to be the last thing done by the function.

Signed-off-by: Axel Lin <[email protected]>
---
drivers/hwmon/gpio-fan.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c
index aa701a1..f141a1d 100644
--- a/drivers/hwmon/gpio-fan.c
+++ b/drivers/hwmon/gpio-fan.c
@@ -376,10 +376,6 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data,
}
}

- err = sysfs_create_group(&pdev->dev.kobj, &gpio_fan_ctrl_group);
- if (err)
- goto err_free_gpio;
-
fan_data->num_ctrl = num_ctrl;
fan_data->ctrl = ctrl;
fan_data->num_speed = pdata->num_speed;
@@ -391,6 +387,10 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data,
goto err_free_gpio;
}

+ err = sysfs_create_group(&pdev->dev.kobj, &gpio_fan_ctrl_group);
+ if (err)
+ goto err_free_gpio;
+
return 0;

err_free_gpio:
--
1.7.2



2010-11-09 09:41:42

by Simon Guinot

[permalink] [raw]
Subject: Re: [lm-sensors] [PATCH v2] hwmon: (gpio-fan) Fix fan_ctrl_init error path

On Tue, Nov 09, 2010 at 04:41:48PM +0800, Axel Lin wrote:
> In current implementation, the sysfs entries is not removed before return -ENODEV.
>
> Creating the sysfs attribute should be the last thing done by the function,
> after all the rest has been successful.
> Otherwise there is a small window during which user-space can access the attribute
> but the driver isn't ready to deal with the requests.
>
> Fix it by moving sysfs_create_group to be the last thing done by the function.
>
> Signed-off-by: Axel Lin <[email protected]>

Thanks for the patch.

Acked-by: Simon Guinot <[email protected]>

> ---
> drivers/hwmon/gpio-fan.c | 8 ++++----
> 1 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c
> index aa701a1..f141a1d 100644
> --- a/drivers/hwmon/gpio-fan.c
> +++ b/drivers/hwmon/gpio-fan.c
> @@ -376,10 +376,6 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data,
> }
> }
>
> - err = sysfs_create_group(&pdev->dev.kobj, &gpio_fan_ctrl_group);
> - if (err)
> - goto err_free_gpio;
> -
> fan_data->num_ctrl = num_ctrl;
> fan_data->ctrl = ctrl;
> fan_data->num_speed = pdata->num_speed;
> @@ -391,6 +387,10 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data,
> goto err_free_gpio;
> }
>
> + err = sysfs_create_group(&pdev->dev.kobj, &gpio_fan_ctrl_group);
> + if (err)
> + goto err_free_gpio;
> +
> return 0;
>
> err_free_gpio:
> --
> 1.7.2
>
>
>
>
> _______________________________________________
> lm-sensors mailing list
> [email protected]
> http://lists.lm-sensors.org/mailman/listinfo/lm-sensors


Attachments:
(No filename) (1.60 kB)
signature.asc (198.00 B)
Digital signature
Download all attachments

2010-11-09 18:21:56

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v2] hwmon: (gpio-fan) Fix fan_ctrl_init error path

On Tue, 2010-11-09 at 03:41 -0500, Axel Lin wrote:
> In current implementation, the sysfs entries is not removed before return -ENODEV.
>
> Creating the sysfs attribute should be the last thing done by the function,
> after all the rest has been successful.
> Otherwise there is a small window during which user-space can access the attribute
> but the driver isn't ready to deal with the requests.
>
> Fix it by moving sysfs_create_group to be the last thing done by the function.
>
> Signed-off-by: Axel Lin <[email protected]>

Applied.

Thanks,
Guenter