Skip to contentSkip to conversation

hwmon: (pc87427) Move sysfs file removal

PATCH In review Jean Delvare 2 participants 3 messages Aug 11, 2010 – Aug 12, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 6/6 hwmon: (pc87427) Move sysfs file removal

The sysfs file removal code is the same in the probe error path and in the remove function, so move it to a separate function to avoid code duplication.

---
 drivers/hwmon/pc87427.c |   58 +++++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 32 deletions(-)
drivers/hwmon/pc87427.c +26 -32
@@ -1045,6 +1045,29 @@ static void __devinit pc87427_init_devic
 	}
 }
 
+static void pc87427_remove_files(struct device *dev)
+{
+	struct pc87427_data *data = dev_get_drvdata(dev);
+	int i;
+
+	device_remove_file(dev, &dev_attr_name);
+	for (i = 0; i < 8; i++) {
+		if (!(data->fan_enabled & (1 << i)))
+			continue;
+		sysfs_remove_group(&dev->kobj, &pc87427_group_fan[i]);
+	}
+	for (i = 0; i < 4; i++) {
+		if (!(data->pwm_enabled & (1 << i)))
+			continue;
+		sysfs_remove_group(&dev->kobj, &pc87427_group_pwm[i]);
+	}
+	for (i = 0; i < 6; i++) {
+		if (!(data->temp_enabled & (1 << i)))
+			continue;
+		sysfs_remove_group(&dev->kobj, &pc87427_group_temp[i]);
+	}
+}
+
 static int __devinit pc87427_probe(struct platform_device *pdev)
 {
 	struct pc87427_sio_data *sio_data = pdev->dev.platform_data;
@@ -1110,21 +1133,7 @@ static int __devinit pc87427_probe(struc
 	return 0;
 
 exit_remove_files:
-	for (i = 0; i < 8; i++) {
-		if (!(data->fan_enabled & (1 << i)))
-			continue;
-		sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]);
-	}
-	for (i = 0; i < 4; i++) {
-		if (!(data->pwm_enabled & (1 << i)))
-			continue;
-		sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_pwm[i]);
-	}
-	for (i = 0; i < 6; i++) {
-		if (!(data->temp_enabled & (1 << i)))
-			continue;
-		sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_temp[i]);
-	}
+	pc87427_remove_files(&pdev->dev);
 exit_release_region:
 	pc87427_release_regions(pdev, res_count);
 exit_kfree:
@@ -1137,27 +1146,12 @@ exit:
 static int __devexit pc87427_remove(struct platform_device *pdev)
 {
 	struct pc87427_data *data = platform_get_drvdata(pdev);
-	int i, res_count;
+	int res_count;
 
 	res_count = (data->address[0] != 0) + (data->address[1] != 0);
 
 	hwmon_device_unregister(data->hwmon_dev);
-	device_remove_file(&pdev->dev, &dev_attr_name);
-	for (i = 0; i < 8; i++) {
-		if (!(data->fan_enabled & (1 << i)))
-			continue;
-		sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]);
-	}
-	for (i = 0; i < 4; i++) {
-		if (!(data->pwm_enabled & (1 << i)))
-			continue;
-		sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_pwm[i]);
-	}
-	for (i = 0; i < 6; i++) {
-		if (!(data->temp_enabled & (1 << i)))
-			continue;
-		sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_temp[i]);
-	}
+	pc87427_remove_files(&pdev->dev);
 	platform_set_drvdata(pdev, NULL);
 	kfree(data);
 
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Acked-by on v1 6/6
#1 lore raw

Re: [lm-sensors] [PATCH 6/6] hwmon: (pc87427) Move sysfs file

Quoted 5 lines · Jean Delvare

The sysfs file removal code is the same in the probe error path and in the remove function, so move it to a separate function to avoid code duplication.

Another minor question below.

Quoted 7 lines
---
 drivers/hwmon/pc87427.c |   58 +++++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 32 deletions(-)

drivers/hwmon/pc87427.c static void __devinit pc87427_init_devic · line 1053

Quoted 9 lines
drivers/hwmon/pc87427.c +6 -0
@@ -1045,6 +1045,29 @@ static void __devinit pc87427_init_devic
 	}
 }
 
+static void pc87427_remove_files(struct device *dev)
+{
+	struct pc87427_data *data = dev_get_drvdata(dev);
+	int i;
+
+	device_remove_file(dev, &dev_attr_name);

device_remove_file() is not called in the error path. Does that matter ?

Quoted 64 lines
drivers/hwmon/pc87427.c +19 -26
+	for (i = 0; i < 8; i++) {
+		if (!(data->fan_enabled & (1 << i)))
+			continue;
+		sysfs_remove_group(&dev->kobj, &pc87427_group_fan[i]);
+	}
+	for (i = 0; i < 4; i++) {
+		if (!(data->pwm_enabled & (1 << i)))
+			continue;
+		sysfs_remove_group(&dev->kobj, &pc87427_group_pwm[i]);
+	}
+	for (i = 0; i < 6; i++) {
+		if (!(data->temp_enabled & (1 << i)))
+			continue;
+		sysfs_remove_group(&dev->kobj, &pc87427_group_temp[i]);
+	}
+}
+
 static int __devinit pc87427_probe(struct platform_device *pdev)
 {
 	struct pc87427_sio_data *sio_data = pdev->dev.platform_data;
@@ -1110,21 +1133,7 @@ static int __devinit pc87427_probe(struc
 	return 0;
 
 exit_remove_files:
-	for (i = 0; i < 8; i++) {
-		if (!(data->fan_enabled & (1 << i)))
-			continue;
-		sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]);
-	}
-	for (i = 0; i < 4; i++) {
-		if (!(data->pwm_enabled & (1 << i)))
-			continue;
-		sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_pwm[i]);
-	}
-	for (i = 0; i < 6; i++) {
-		if (!(data->temp_enabled & (1 << i)))
-			continue;
-		sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_temp[i]);
-	}
+	pc87427_remove_files(&pdev->dev);
 exit_release_region:
 	pc87427_release_regions(pdev, res_count);
 exit_kfree:
@@ -1137,27 +1146,12 @@ exit:
 static int __devexit pc87427_remove(struct platform_device *pdev)
 {
 	struct pc87427_data *data = platform_get_drvdata(pdev);
-	int i, res_count;
+	int res_count;
 
 	res_count = (data->address[0] != 0) + (data->address[1] != 0);
 
 	hwmon_device_unregister(data->hwmon_dev);
-	device_remove_file(&pdev->dev, &dev_attr_name);
-	for (i = 0; i < 8; i++) {
-		if (!(data->fan_enabled & (1 << i)))
-			continue;
-		sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]);
-	}
-	for (i = 0; i < 4; i++) {
-		if (!(data->pwm_enabled & (1 << i)))
-			continue;
-		sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_pwm[i]);

drivers/hwmon/pc87427.c exit: · line 1157

Quoted 10 lines
drivers/hwmon/pc87427.c +1 -6
-	}
-	for (i = 0; i < 6; i++) {
-		if (!(data->temp_enabled & (1 << i)))
-			continue;
-		sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_temp[i]);
-	}
+	pc87427_remove_files(&pdev->dev);
 	platform_set_drvdata(pdev, NULL);
 	kfree(data);
 

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

#2 lore raw

Re: [lm-sensors] [PATCH 6/6] hwmon: (pc87427) Move sysfs file

In reply to Jean Delvare
Quoted 21 lines · Guenter Roeck
Quoted 5 lines · Jean Delvare

The sysfs file removal code is the same in the probe error path and in the remove function, so move it to a separate function to avoid code duplication.

Another minor question below.

Quoted 10 lines
---
 drivers/hwmon/pc87427.c |   58 +++++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 32 deletions(-)
drivers/hwmon/pc87427.c +0 -0
@@ -1045,6 +1045,29 @@ static void __devinit pc87427_init_devic
 	}
 }
 
Quoted 8 lines

drivers/hwmon/pc87427.c static void __devinit pc87427_init_devic · line 1053

Quoted 6 lines
drivers/hwmon/pc87427.c +6 -0
+static void pc87427_remove_files(struct device *dev)
+{
+	struct pc87427_data *data = dev_get_drvdata(dev);
+	int i;
+
+	device_remove_file(dev, &dev_attr_name);

device_remove_file() is not called in the error path. Does that matter ?

No it doesn't matter. It's always OK to remove files that do not exist. In fact, I could even remove all the tests on data->*_enabled below, it would still work fine.

Quoted 17 lines
Quoted 17 lines
drivers/hwmon/pc87427.c +16 -0
+	for (i = 0; i < 8; i++) {
+		if (!(data->fan_enabled & (1 << i)))
+			continue;
+		sysfs_remove_group(&dev->kobj, &pc87427_group_fan[i]);
+	}
+	for (i = 0; i < 4; i++) {
+		if (!(data->pwm_enabled & (1 << i)))
+			continue;
+		sysfs_remove_group(&dev->kobj, &pc87427_group_pwm[i]);
+	}
+	for (i = 0; i < 6; i++) {
+		if (!(data->temp_enabled & (1 << i)))
+			continue;
+		sysfs_remove_group(&dev->kobj, &pc87427_group_temp[i]);
+	}
+}
Signature · 6 lines
Jean Delvare

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