Skip to contentSkip to conversation

hwmon: (gpio-fan) Fix fan_ctrl_init error path

PATCH Superseded Axel Lin 3 participants 6 messages Nov 9, 2010 Hardware monitoring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 hwmon: (gpio-fan) Fix fan_ctrl_init error path

Remove sysfs entries before return -ENODEV.

---
 drivers/hwmon/gpio-fan.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/hwmon/gpio-fan.c +3 -1
index aa701a1..d2e66b4 100644
@@ -388,11 +388,13 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data,
 	fan_data->speed_index = get_fan_speed_index(fan_data);
 	if (fan_data->speed_index < 0) {
 		err = -ENODEV;
-		goto err_free_gpio;
+		goto err_remove_sysfs;
 	}
 
 	return 0;
 
+err_remove_sysfs:
+	sysfs_remove_group(&pdev->dev.kobj, &gpio_fan_ctrl_group);
 err_free_gpio:
 	for (i = i - 1; i >= 0; i--)
 		gpio_free(ctrl[i]);
Signature · 1 line
1.7.2
#1 lore raw

Hi Alex,

Quoted 16 lines · Axel Lin

Remove sysfs entries before return -ENODEV.

---
 drivers/hwmon/gpio-fan.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/hwmon/gpio-fan.c +0 -1
index aa701a1..d2e66b4 100644
@@ -388,11 +388,13 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data,
 	fan_data->speed_index = get_fan_speed_index(fan_data);
 	if (fan_data->speed_index < 0) {
 		err = -ENODEV;
-		goto err_free_gpio;

drivers/hwmon/gpio-fan.c static int fan_ctrl_init(struct gpio_fan_data *fan_data, · line 400

Quoted 10 lines
drivers/hwmon/gpio-fan.c +3 -0
+		goto err_remove_sysfs;
 	}
 
 	return 0;
 
+err_remove_sysfs:
+	sysfs_remove_group(&pdev->dev.kobj, &gpio_fan_ctrl_group);
 err_free_gpio:
 	for (i = i - 1; i >= 0; i--)
 		gpio_free(ctrl[i]);

This is certainly better than the current situation, however the fact that you need to do this strongly suggests that the initialization order is wrong in the first place. 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.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to Axel Lin
Quoted 16 lines · Axel Lin

Remove sysfs entries before return -ENODEV.

---
 drivers/hwmon/gpio-fan.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/hwmon/gpio-fan.c +0 -1
index aa701a1..d2e66b4 100644
@@ -388,11 +388,13 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data,
 	fan_data->speed_index = get_fan_speed_index(fan_data);
 	if (fan_data->speed_index < 0) {
 		err = -ENODEV;
-		goto err_free_gpio;

drivers/hwmon/gpio-fan.c static int fan_ctrl_init(struct gpio_fan_data *fan_data, · line 400

Quoted 10 lines
drivers/hwmon/gpio-fan.c +3 -0
+		goto err_remove_sysfs;
 	}
 
 	return 0;
 
+err_remove_sysfs:
+	sysfs_remove_group(&pdev->dev.kobj, &gpio_fan_ctrl_group);
 err_free_gpio:
 	for (i = i - 1; i >= 0; i--)
 		gpio_free(ctrl[i]);

Oh, and while you're here, fan_alarm_init() needs some love as well. There's a "return 0" in the middle which clearly can't be correct.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author
#3 lore raw

2010/11/9 Jean Delvare <[email protected]>:

Quoted 22 lines · Axel Lin
Quoted 21 lines

Remove sysfs entries before return -ENODEV.

---
 drivers/hwmon/gpio-fan.c |    4 +++-

 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/hwmon/gpio-fan.c +1 -1
index aa701a1..d2e66b4 100644
@@ -388,11 +388,13 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data,
       fan_data->speed_index = get_fan_speed_index(fan_data);
       if (fan_data->speed_index < 0) {
               err = -ENODEV;
-             goto err_free_gpio;
+             goto err_remove_sysfs;
       }
 
       return 0;
 
Quoted 8 lines
Quoted 5 lines
drivers/hwmon/gpio-fan.c +2 -0
+err_remove_sysfs:
+     sysfs_remove_group(&pdev->dev.kobj, &gpio_fan_ctrl_group);

 err_free_gpio:
      for (i = i - 1; i >= 0; i--)
              gpio_free(ctrl[i]);

Oh, and while you're here, fan_alarm_init() needs some love as well. There's a "return 0" in the middle which clearly can't be correct.

I think this part is correct. see the comment:
/*
* If the alarm GPIO don't support interrupts, just leave
* without initializing the fail notification support. */

Regards,
Axel

Quoted 4 lines

--
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#4 lore raw
Quoted 31 lines · Axel Lin

2010/11/9 Jean Delvare <[email protected]>:

Quoted 22 lines · Axel Lin
Quoted 21 lines

Remove sysfs entries before return -ENODEV.

---
 drivers/hwmon/gpio-fan.c |    4 +++-

 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/hwmon/gpio-fan.c +1 -1
index aa701a1..d2e66b4 100644
@@ -388,11 +388,13 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data,
       fan_data->speed_index = get_fan_speed_index(fan_data);
       if (fan_data->speed_index < 0) {
               err = -ENODEV;
-             goto err_free_gpio;
+             goto err_remove_sysfs;
       }
 
       return 0;
 
Quoted 8 lines
Quoted 5 lines
drivers/hwmon/gpio-fan.c +2 -0
+err_remove_sysfs:
+     sysfs_remove_group(&pdev->dev.kobj, &gpio_fan_ctrl_group);

 err_free_gpio:
      for (i = i - 1; i >= 0; i--)
              gpio_free(ctrl[i]);

Oh, and while you're here, fan_alarm_init() needs some love as well. There's a "return 0" in the middle which clearly can't be correct.

Quoted 5 lines

I think this part is correct. see the comment:
/*
* If the alarm GPIO don't support interrupts, just leave
* without initializing the fail notification support. */

Oops, my bad. I should have read the comments before blaming the author :(

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#5 lore raw
In reply to Axel Lin
Quoted 31 lines · Axel Lin

2010/11/9 Jean Delvare <[email protected]>:

Quoted 22 lines · Axel Lin
Quoted 21 lines

Remove sysfs entries before return -ENODEV.

---
 drivers/hwmon/gpio-fan.c |    4 +++-

 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/hwmon/gpio-fan.c +1 -1
index aa701a1..d2e66b4 100644
@@ -388,11 +388,13 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data,
       fan_data->speed_index = get_fan_speed_index(fan_data);
       if (fan_data->speed_index < 0) {
               err = -ENODEV;
-             goto err_free_gpio;
+             goto err_remove_sysfs;
       }
 
       return 0;
 
Quoted 8 lines
Quoted 5 lines
drivers/hwmon/gpio-fan.c +2 -0
+err_remove_sysfs:
+     sysfs_remove_group(&pdev->dev.kobj, &gpio_fan_ctrl_group);

 err_free_gpio:
      for (i = i - 1; i >= 0; i--)
              gpio_free(ctrl[i]);

Oh, and while you're here, fan_alarm_init() needs some love as well. There's a "return 0" in the middle which clearly can't be correct.

Quoted 6 lines

I think this part is correct. see the comment:
/*
* If the alarm GPIO don't support interrupts, just leave
* without initializing the fail notification support. */

Yes, GPIO interrupts could not be supported. That's not an error case.

Simon

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors