diff mbox series

[2/3] hwmon: (oxp-sensors): move to use dev_groups from platform device

Message ID 20230704131715.44454-7-gregkh@linuxfoundation.org (mailing list archive)
State Changes Requested
Headers show
Series driver core: remove final user of devm_device_add_groups() | expand

Commit Message

Greg KH July 4, 2023, 1:17 p.m. UTC
A driver should not be manually adding groups in its probe function (it
will race with userspace), so replace the call to
devm_device_add_groups() to use the platform dev_groups callback
instead.

This is the last in-kernel user of devm_device_add_groups(), so it can
be successfully removed at this point in time.

Cc: Joaquín Ignacio Aramendía <samsagax@gmail.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: linux-hwmon@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/hwmon/oxp-sensors.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c
index 3bcba0c476c4..34e561ba9e8b 100644
--- a/drivers/hwmon/oxp-sensors.c
+++ b/drivers/hwmon/oxp-sensors.c
@@ -408,12 +408,33 @@  static const struct hwmon_channel_info * const oxp_platform_sensors[] = {
 	NULL,
 };
 
+static umode_t oxp_ec_is_visible(struct kobject *kobj, struct attribute *attr, int n)
+{
+	switch (get_board_type()) {
+	case aok_zoe_a1:
+	case oxp_mini_amd_a07:
+	case oxp_mini_amd_pro:
+		return attr->mode;
+	default:
+		break;
+	}
+	return 0;
+}
+
 static struct attribute *oxp_ec_attrs[] = {
 	&dev_attr_tt_toggle.attr,
 	NULL
 };
 
-ATTRIBUTE_GROUPS(oxp_ec);
+static struct attribute_group oxp_ec_attribute_group = {
+	.is_visible = oxp_ec_is_visible,
+	.attrs = oxp_ec_attrs,
+};
+
+static const struct attribute_group *oxp_ec_groups[] = {
+	&oxp_ec_attribute_group,
+	NULL
+};
 
 static const struct hwmon_ops oxp_ec_hwmon_ops = {
 	.is_visible = oxp_ec_hwmon_is_visible,
@@ -431,19 +452,6 @@  static int oxp_platform_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct device *hwdev;
-	int ret;
-
-	switch (get_board_type()) {
-	case aok_zoe_a1:
-	case oxp_mini_amd_a07:
-	case oxp_mini_amd_pro:
-		ret = devm_device_add_groups(dev, oxp_ec_groups);
-		if (ret)
-			return ret;
-		break;
-	default:
-		break;
-	}
 
 	hwdev = devm_hwmon_device_register_with_info(dev, "oxpec", NULL,
 						     &oxp_ec_chip_info, NULL);
@@ -454,6 +462,7 @@  static int oxp_platform_probe(struct platform_device *pdev)
 static struct platform_driver oxp_platform_driver = {
 	.driver = {
 		.name = "oxp-platform",
+		.dev_groups = oxp_ec_groups,
 	},
 	.probe = oxp_platform_probe,
 };