Skip to contentSkip to conversation

Input: elan_i2c - convert to use dev_groups

PATCH Superseded Greg Kroah-Hartman 2 participants 4 messages Jul 29, 2022 – Aug 2, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: elan_i2c - convert to use dev_groups

The driver core supports the ability to handle the creation and removal of device-specific sysfs files in a race-free manner. Take advantage of that by converting this driver to use this by moving the sysfs attributes into a group and assigning the dev_groups pointer to it.

Cc Dmitry Torokhov <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "jingle.wu" <[email protected]>
---
 drivers/input/mouse/elan_i2c_core.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/input/mouse/elan_i2c_core.c +1 -6
index e1758d5ffe42..d4eb59b55bf1 100644
@@ -1311,12 +1311,6 @@ static int elan_probe(struct i2c_client *client,
 		return error;
 	}
 
-	error = devm_device_add_groups(dev, elan_sysfs_groups);
-	if (error) {
-		dev_err(dev, "failed to create sysfs attributes: %d\n", error);
-		return error;
-	}
-
 	error = input_register_device(data->input);
 	if (error) {
 		dev_err(dev, "failed to register input device: %d\n", error);
@@ -1442,6 +1436,7 @@ static struct i2c_driver elan_driver = {
 		.acpi_match_table = ACPI_PTR(elan_acpi_id),
 		.of_match_table = of_match_ptr(elan_of_match),
 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+		.dev_groups = elan_sysfs_groups,
 	},
 	.probe		= elan_probe,
 	.id_table	= elan_id,
Signature · 1 line
2.37.1
maintainer
#1 lore raw

Hi Greg,

Quoted 4 lines · Greg Kroah-Hartman

The driver core supports the ability to handle the creation and removal of device-specific sysfs files in a race-free manner. Take advantage of that by converting this driver to use this by moving the sysfs attributes into a group and assigning the dev_groups pointer to it.

I obviously like this patch as the less boilerplate code the better, but I am not sure what race are you talking about in the commit message? Could you please elaborate?

Thanks!

Quoted 40 lines
Cc Dmitry Torokhov <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "jingle.wu" <[email protected]>
---
 drivers/input/mouse/elan_i2c_core.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/input/mouse/elan_i2c_core.c +1 -6
index e1758d5ffe42..d4eb59b55bf1 100644
@@ -1311,12 +1311,6 @@ static int elan_probe(struct i2c_client *client,
 		return error;
 	}
 
-	error = devm_device_add_groups(dev, elan_sysfs_groups);
-	if (error) {
-		dev_err(dev, "failed to create sysfs attributes: %d\n", error);
-		return error;
-	}
-
 	error = input_register_device(data->input);
 	if (error) {
 		dev_err(dev, "failed to register input device: %d\n", error);
@@ -1442,6 +1436,7 @@ static struct i2c_driver elan_driver = {
 		.acpi_match_table = ACPI_PTR(elan_acpi_id),
 		.of_match_table = of_match_ptr(elan_of_match),
 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+		.dev_groups = elan_sysfs_groups,
 	},
 	.probe		= elan_probe,
 	.id_table	= elan_id,
Signature · 1 line
2.37.1
Signature · 1 line
Dmitry
#2 lore raw
Quoted 11 lines · Dmitry Torokhov

Hi Greg,

Quoted 4 lines · Greg Kroah-Hartman

The driver core supports the ability to handle the creation and removal of device-specific sysfs files in a race-free manner. Take advantage of that by converting this driver to use this by moving the sysfs attributes into a group and assigning the dev_groups pointer to it.

I obviously like this patch as the less boilerplate code the better, but I am not sure what race are you talking about in the commit message? Could you please elaborate?

The race is normally because the device is announced to userspace before the attributes are added. But you are right, the race is still the same here, the attributes are added after probe succeeds, so it's the same time, so this changelog text is wrong, sorry about that.

I'll rewrite this to just say it's cleaner and simpler with this change and resend it in a few days.

thanks,

greg k-h

#3 lore raw
In reply to Greg Kroah-Hartman
Quoted 12 lines · Greg Kroah-Hartman

The driver core supports the ability to handle the creation and removal of device-specific sysfs files in a race-free manner. Take advantage of that by converting this driver to use this by moving the sysfs attributes into a group and assigning the dev_groups pointer to it.

Cc Dmitry Torokhov <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "jingle.wu" <[email protected]>
Quoted 3 lines
---
 drivers/input/mouse/elan_i2c_core.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

v2 is now here:

	https://lore.kernel.org/r/[email protected]