Skip to contentSkip to conversation

driver core: remove final user of devm_device_add_groups()

PATCH In review Greg Kroah-Hartman 5 participants 13 messages Jul 4, 2023 – Jul 5, 2023

Subsystems (2)
lore
Share & tools
lore

Greg Kroah-Hartman

author maintainer
#0 lore raw

cover driver core: remove final user of devm_device_add_groups()

In the 6.5-rc1 merge window, a new user of devm_device_add_groups() snuck in before I had a chance to remove it from the tree. This series removes that user (and cleans up a global variable in the oxp-sensor driver), and removes the call from the tree entirely.

Guenter, feel free to take these through your hwmon tree, or I can take them through my driver-core tree if you want me to.

Greg Kroah-Hartman (3):
hwmon: (oxp-sensors): remove static board variable
hwmon: (oxp-sensors): move to use dev_groups from platform device driver core: remove devm_device_add_groups()

 drivers/base/core.c         | 45 --------------------
 drivers/hwmon/oxp-sensors.c | 82 +++++++++++++++++++++----------------
 include/linux/device.h      |  2 -
 3 files changed, 47 insertions(+), 82 deletions(-)
Signature · 1 line
2.41.0
author maintainer
#9 lore raw

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

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 <[email protected]>
Cc Guenter Roeck <[email protected]>
---
 drivers/hwmon/oxp-sensors.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)
drivers/hwmon/oxp-sensors.c +23 -14
index 3bcba0c476c4..34e561ba9e8b 100644
@@ -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,
 };
Signature · 1 line
2.41.0
author maintainer
#1 lore raw

PATCH 1/3 hwmon: (oxp-sensors): remove static board variable

In reply to Greg Kroah-Hartman

Drivers should not have a single static variable for the type of device they are bound to. While this driver is really going to only have one device at a time in the system, remove the static variable and instead, look up the device type when needed.

Cc Joaquín Ignacio Aramendía <[email protected]>
Cc Guenter Roeck <[email protected]>
---
 drivers/hwmon/oxp-sensors.c | 47 ++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 22 deletions(-)
drivers/hwmon/oxp-sensors.c +25 -22
index e1a907cae820..3bcba0c476c4 100644
@@ -48,10 +48,9 @@ enum oxp_board {
 	oxp_mini_amd,
 	oxp_mini_amd_a07,
 	oxp_mini_amd_pro,
+	UNKNOWN,
 };
 
-static enum oxp_board board;
-
 /* Fan reading and PWM */
 #define OXP_SENSOR_FAN_REG		0x76 /* Fan reading is 2 registers long */
 #define OXP_SENSOR_PWM_ENABLE_REG	0x4A /* PWM enable is 1 register long */
@@ -136,6 +135,24 @@ static const struct dmi_system_id dmi_table[] = {
 	{},
 };
 
+static enum oxp_board get_board_type(void)
+{
+	const struct dmi_system_id *dmi_entry;
+
+	/*
+	 * Have to check for AMD processor here because DMI strings are the
+	 * same between Intel and AMD boards, the only way to tell them apart
+	 * is the CPU.
+	 * Intel boards seem to have different EC registers and values to
+	 * read/write.
+	 */
+	dmi_entry = dmi_first_match(dmi_table);
+	if (!dmi_entry || boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
+		return UNKNOWN;
+
+	return (enum oxp_board)(unsigned long)dmi_entry->driver_data;
+}
+
 /* Helper functions to handle EC read/write */
 static int read_from_ec(u8 reg, int size, long *val)
 {
@@ -182,7 +199,7 @@ static int tt_toggle_enable(void)
 	u8 reg;
 	u8 val;
 
-	switch (board) {
+	switch (get_board_type()) {
 	case oxp_mini_amd_a07:
 		reg = OXP_OLD_TURBO_SWITCH_REG;
 		val = OXP_OLD_TURBO_TAKE_VAL;
@@ -203,7 +220,7 @@ static int tt_toggle_disable(void)
 	u8 reg;
 	u8 val;
 
-	switch (board) {
+	switch (get_board_type()) {
 	case oxp_mini_amd_a07:
 		reg = OXP_OLD_TURBO_SWITCH_REG;
 		val = OXP_OLD_TURBO_RETURN_VAL;
@@ -249,7 +266,7 @@ static ssize_t tt_toggle_show(struct device *dev,
 	u8 reg;
 	long val;
 
-	switch (board) {
+	switch (get_board_type()) {
 	case oxp_mini_amd_a07:
 		reg = OXP_OLD_TURBO_SWITCH_REG;
 		break;
@@ -315,7 +332,7 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 			ret = read_from_ec(OXP_SENSOR_PWM_REG, 1, val);
 			if (ret)
 				return ret;
-			switch (board) {
+			switch (get_board_type()) {
 			case aya_neo_2:
 			case aya_neo_air:
 			case aya_neo_air_pro:
@@ -357,7 +374,7 @@ static int oxp_platform_write(struct device *dev, enum hwmon_sensor_types type,
 		case hwmon_pwm_input:
 			if (val < 0 || val > 255)
 				return -EINVAL;
-			switch (board) {
+			switch (get_board_type()) {
 			case aya_neo_2:
 			case aya_neo_air:
 			case aya_neo_air_pro:
@@ -412,25 +429,11 @@ static const struct hwmon_chip_info oxp_ec_chip_info = {
 /* Initialization logic */
 static int oxp_platform_probe(struct platform_device *pdev)
 {
-	const struct dmi_system_id *dmi_entry;
 	struct device *dev = &pdev->dev;
 	struct device *hwdev;
 	int ret;
 
-	/*
-	 * Have to check for AMD processor here because DMI strings are the
-	 * same between Intel and AMD boards, the only way to tell them apart
-	 * is the CPU.
-	 * Intel boards seem to have different EC registers and values to
-	 * read/write.
-	 */
-	dmi_entry = dmi_first_match(dmi_table);
-	if (!dmi_entry || boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
-		return -ENODEV;
-
-	board = (enum oxp_board)(unsigned long)dmi_entry->driver_data;
-
-	switch (board) {
+	switch (get_board_type()) {
 	case aok_zoe_a1:
 	case oxp_mini_amd_a07:
 	case oxp_mini_amd_pro:
Signature · 1 line
2.41.0
author maintainer
#10 lore raw

PATCH 3/3 driver core: remove devm_device_add_groups()

In reply to Greg Kroah-Hartman

There is no more in-kernel users of this function, and no driver should ever be using it, so remove it from the kernel.

Cc Dmitry Torokhov <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/base/core.c    | 45 ------------------------------------------
 include/linux/device.h |  2 --
 2 files changed, 47 deletions(-)
drivers/base/core.c +0 -45
index 3dff5037943e..94187c0b577d 100644
@@ -2748,15 +2748,6 @@ static void devm_attr_group_remove(struct device *dev, void *res)
 	sysfs_remove_group(&dev->kobj, group);
 }
 
-static void devm_attr_groups_remove(struct device *dev, void *res)
-{
-	union device_attr_group_devres *devres = res;
-	const struct attribute_group **groups = devres->groups;
-
-	dev_dbg(dev, "%s: removing groups %p\n", __func__, groups);
-	sysfs_remove_groups(&dev->kobj, groups);
-}
-
 /**
  * devm_device_add_group - given a device, create a managed attribute group
  * @dev:	The device to create the group for
@@ -2789,42 +2780,6 @@ int devm_device_add_group(struct device *dev, const struct attribute_group *grp)
 }
 EXPORT_SYMBOL_GPL(devm_device_add_group);
 
-/**
- * devm_device_add_groups - create a bunch of managed attribute groups
- * @dev:	The device to create the group for
- * @groups:	The attribute groups to create, NULL terminated
- *
- * This function creates a bunch of managed attribute groups.  If an error
- * occurs when creating a group, all previously created groups will be
- * removed, unwinding everything back to the original state when this
- * function was called.  It will explicitly warn and error if any of the
- * attribute files being created already exist.
- *
- * Returns 0 on success or error code from sysfs_create_group on failure.
- */
-int devm_device_add_groups(struct device *dev,
-			   const struct attribute_group **groups)
-{
-	union device_attr_group_devres *devres;
-	int error;
-
-	devres = devres_alloc(devm_attr_groups_remove,
-			      sizeof(*devres), GFP_KERNEL);
-	if (!devres)
-		return -ENOMEM;
-
-	error = sysfs_create_groups(&dev->kobj, groups);
-	if (error) {
-		devres_free(devres);
-		return error;
-	}
-
-	devres->groups = groups;
-	devres_add(dev, devres);
-	return 0;
-}
-EXPORT_SYMBOL_GPL(devm_device_add_groups);
-
 static int device_add_attrs(struct device *dev)
 {
 	const struct class *class = dev->class;
include/linux/device.h +0 -2
index 66c13965153d..6dd087e4223d 100644
@@ -1164,8 +1164,6 @@ static inline void device_remove_group(struct device *dev,
 	return device_remove_groups(dev, groups);
 }
 
-int __must_check devm_device_add_groups(struct device *dev,
-					const struct attribute_group **groups);
 int __must_check devm_device_add_group(struct device *dev,
 				       const struct attribute_group *grp);
 
Signature · 1 line
2.41.0
maintainer
#2 lore raw

Re: [PATCH 1/3] hwmon: (oxp-sensors): remove static board variable

In reply to Greg Kroah-Hartman
Quoted 5 lines · Greg Kroah-Hartman

Drivers should not have a single static variable for the type of device they are bound to. While this driver is really going to only have one device at a time in the system, remove the static variable and instead, look up the device type when needed.

This is expensive. I think it would be much better to just move the board type detection into the init code and not instantiate the driver in the fist place if the board type is unknown.

We can handle the static variable separately if it really bothers you that much.

Quoted 108 lines
Cc Joaquín Ignacio Aramendía <[email protected]>
Cc Guenter Roeck <[email protected]>
---
  drivers/hwmon/oxp-sensors.c | 47 ++++++++++++++++++++-----------------
  1 file changed, 25 insertions(+), 22 deletions(-)
drivers/hwmon/oxp-sensors.c +24 -13
index e1a907cae820..3bcba0c476c4 100644
@@ -48,10 +48,9 @@ enum oxp_board {
  	oxp_mini_amd,
  	oxp_mini_amd_a07,
  	oxp_mini_amd_pro,
+	UNKNOWN,
  };
 
-static enum oxp_board board;
-
  /* Fan reading and PWM */
  #define OXP_SENSOR_FAN_REG		0x76 /* Fan reading is 2 registers long */
  #define OXP_SENSOR_PWM_ENABLE_REG	0x4A /* PWM enable is 1 register long */
@@ -136,6 +135,24 @@ static const struct dmi_system_id dmi_table[] = {
  	{},
  };
 
+static enum oxp_board get_board_type(void)
+{
+	const struct dmi_system_id *dmi_entry;
+
+	/*
+	 * Have to check for AMD processor here because DMI strings are the
+	 * same between Intel and AMD boards, the only way to tell them apart
+	 * is the CPU.
+	 * Intel boards seem to have different EC registers and values to
+	 * read/write.
+	 */
+	dmi_entry = dmi_first_match(dmi_table);
+	if (!dmi_entry || boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
+		return UNKNOWN;
+
+	return (enum oxp_board)(unsigned long)dmi_entry->driver_data;
+}
+
  /* Helper functions to handle EC read/write */
  static int read_from_ec(u8 reg, int size, long *val)
  {
@@ -182,7 +199,7 @@ static int tt_toggle_enable(void)
  	u8 reg;
  	u8 val;
 
-	switch (board) {
+	switch (get_board_type()) {
  	case oxp_mini_amd_a07:
  		reg = OXP_OLD_TURBO_SWITCH_REG;
  		val = OXP_OLD_TURBO_TAKE_VAL;
@@ -203,7 +220,7 @@ static int tt_toggle_disable(void)
  	u8 reg;
  	u8 val;
 
-	switch (board) {
+	switch (get_board_type()) {
  	case oxp_mini_amd_a07:
  		reg = OXP_OLD_TURBO_SWITCH_REG;
  		val = OXP_OLD_TURBO_RETURN_VAL;
@@ -249,7 +266,7 @@ static ssize_t tt_toggle_show(struct device *dev,
  	u8 reg;
  	long val;
 
-	switch (board) {
+	switch (get_board_type()) {
  	case oxp_mini_amd_a07:
  		reg = OXP_OLD_TURBO_SWITCH_REG;
  		break;
@@ -315,7 +332,7 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
  			ret = read_from_ec(OXP_SENSOR_PWM_REG, 1, val);
  			if (ret)
  				return ret;
-			switch (board) {
+			switch (get_board_type()) {
  			case aya_neo_2:
  			case aya_neo_air:
  			case aya_neo_air_pro:
@@ -357,7 +374,7 @@ static int oxp_platform_write(struct device *dev, enum hwmon_sensor_types type,
  		case hwmon_pwm_input:
  			if (val < 0 || val > 255)
  				return -EINVAL;
-			switch (board) {
+			switch (get_board_type()) {
  			case aya_neo_2:
  			case aya_neo_air:
  			case aya_neo_air_pro:
@@ -412,25 +429,11 @@ static const struct hwmon_chip_info oxp_ec_chip_info = {
  /* Initialization logic */
  static int oxp_platform_probe(struct platform_device *pdev)
  {
-	const struct dmi_system_id *dmi_entry;
  	struct device *dev = &pdev->dev;
  	struct device *hwdev;
  	int ret;
 
-	/*
-	 * Have to check for AMD processor here because DMI strings are the
-	 * same between Intel and AMD boards, the only way to tell them apart
-	 * is the CPU.
-	 * Intel boards seem to have different EC registers and values to

drivers/hwmon/oxp-sensors.c static const struct hwmon_chip_info oxp_ec_chip_info = { · line 436

Quoted 10 lines
drivers/hwmon/oxp-sensors.c +1 -9
-	 * read/write.
-	 */
-	dmi_entry = dmi_first_match(dmi_table);
-	if (!dmi_entry || boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
-		return -ENODEV;
-
-	board = (enum oxp_board)(unsigned long)dmi_entry->driver_data;
-
-	switch (board) {
+	switch (get_board_type()) {

This now always registers the hwmon device, which really should not happen.

Guenter

Quoted 3 lines
drivers/hwmon/oxp-sensors.c +0 -0
  	case aok_zoe_a1:
  	case oxp_mini_amd_a07:
  	case oxp_mini_amd_pro:
author maintainer
#3 lore raw

Re: [PATCH 1/3] hwmon: (oxp-sensors): remove static board variable

Quoted 10 lines · Guenter Roeck
Quoted 5 lines · Greg Kroah-Hartman

Drivers should not have a single static variable for the type of device they are bound to. While this driver is really going to only have one device at a time in the system, remove the static variable and instead, look up the device type when needed.

This is expensive. I think it would be much better to just move the board type detection into the init code and not instantiate the driver in the fist place if the board type is unknown.

The board type detection is all over the place in the driver, it's not just for "unknown" types, so how about just saving the board type at probe time and using it then for all other places?

Quoted 2 lines

We can handle the static variable separately if it really bothers you that much.

I did this change to make patch 2/3 more "obvious" what is happening when the in_visible() callback happens, so that you don't have to worry about the saved value or not. But this whole patch isn't really needed if you don't mind the lookup just happening in the in_visible() callback for the first time.

thanks,

greg k-h

maintainer
#4 lore raw

Re: [PATCH 1/3] hwmon: (oxp-sensors): remove static board variable

Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines · Guenter Roeck
Quoted 5 lines · Greg Kroah-Hartman

Drivers should not have a single static variable for the type of device they are bound to. While this driver is really going to only have one device at a time in the system, remove the static variable and instead, look up the device type when needed.

Quoted 8 lines
Quoted 3 lines

This is expensive. I think it would be much better to just move the board type detection into the init code and not instantiate the driver in the fist place if the board type is unknown.

The board type detection is all over the place in the driver, it's not just for "unknown" types, so how about just saving the board type at probe time and using it then for all other places?

I must be missing something. The current code detects the board type only once, in the probe function. Otherwise the static variable is used. You are replacing it with repeated calls to get_board_type(). The whole point of the static variable is to avoid the cost of repeated calls to dmi_first_match().

Quoted 9 lines
Quoted 2 lines

We can handle the static variable separately if it really bothers you that much.

I did this change to make patch 2/3 more "obvious" what is happening when the in_visible() callback happens, so that you don't have to worry about the saved value or not. But this whole patch isn't really needed if you don't mind the lookup just happening in the in_visible() callback for the first time.

That would at least be a minimal change, and just add one extra lookup which is only called once (or zero, if it is used to save the board type).

As I said, my solution would be to move the board type detection into the init function and not instantiate the driver in the first place if the probe function would bail out anyway. Personally I'd keep the static variable for simplicity, but if you really dislike it that much, we could pass it around in platform and later driver data. But it seems to me that this could (and should) be a separate patch that doesn't have to be hurried in.

Thanks,
Guenter

maintainer Acked-by on v1 3/3
#11 lore raw

Re: [PATCH 3/3] driver core: remove devm_device_add_groups()

In reply to Greg Kroah-Hartman
Quoted 7 lines · Greg Kroah-Hartman

There is no more in-kernel users of this function, and no driver should ever be using it, so remove it from the kernel.

Cc Dmitry Torokhov <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Quoted 84 lines
---
 drivers/base/core.c    | 45 ------------------------------------------
 include/linux/device.h |  2 --
 2 files changed, 47 deletions(-)
drivers/base/core.c +0 -45
index 3dff5037943e..94187c0b577d 100644
@@ -2748,15 +2748,6 @@ static void devm_attr_group_remove(struct device *dev, void *res)
        sysfs_remove_group(&dev->kobj, group);
 }
 
-static void devm_attr_groups_remove(struct device *dev, void *res)
-{
-       union device_attr_group_devres *devres = res;
-       const struct attribute_group **groups = devres->groups;
-
-       dev_dbg(dev, "%s: removing groups %p\n", __func__, groups);
-       sysfs_remove_groups(&dev->kobj, groups);
-}
-
 /**
  * devm_device_add_group - given a device, create a managed attribute group
  * @dev:       The device to create the group for
@@ -2789,42 +2780,6 @@ int devm_device_add_group(struct device *dev, const struct attribute_group *grp)
 }
 EXPORT_SYMBOL_GPL(devm_device_add_group);
 
-/**
- * devm_device_add_groups - create a bunch of managed attribute groups
- * @dev:       The device to create the group for
- * @groups:    The attribute groups to create, NULL terminated
- *
- * This function creates a bunch of managed attribute groups.  If an error
- * occurs when creating a group, all previously created groups will be
- * removed, unwinding everything back to the original state when this
- * function was called.  It will explicitly warn and error if any of the
- * attribute files being created already exist.
- *
- * Returns 0 on success or error code from sysfs_create_group on failure.
- */
-int devm_device_add_groups(struct device *dev,
-                          const struct attribute_group **groups)
-{
-       union device_attr_group_devres *devres;
-       int error;
-
-       devres = devres_alloc(devm_attr_groups_remove,
-                             sizeof(*devres), GFP_KERNEL);
-       if (!devres)
-               return -ENOMEM;
-
-       error = sysfs_create_groups(&dev->kobj, groups);
-       if (error) {
-               devres_free(devres);
-               return error;
-       }
-
-       devres->groups = groups;
-       devres_add(dev, devres);
-       return 0;
-}
-EXPORT_SYMBOL_GPL(devm_device_add_groups);
-
 static int device_add_attrs(struct device *dev)
 {
        const struct class *class = dev->class;
include/linux/device.h +0 -3
index 66c13965153d..6dd087e4223d 100644
@@ -1164,8 +1164,6 @@ static inline void device_remove_group(struct device *dev,
        return device_remove_groups(dev, groups);
 }
 
-int __must_check devm_device_add_groups(struct device *dev,
-                                       const struct attribute_group **groups);
 int __must_check devm_device_add_group(struct device *dev,
                                       const struct attribute_group *grp);
 
--

2.41.0

author maintainer
#5 lore raw

Re: [PATCH 1/3] hwmon: (oxp-sensors): remove static board variable

In reply to Guenter Roeck
Quoted 18 lines · Guenter Roeck
Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines · Guenter Roeck
Quoted 5 lines · Greg Kroah-Hartman

Drivers should not have a single static variable for the type of device they are bound to. While this driver is really going to only have one device at a time in the system, remove the static variable and instead, look up the device type when needed.

Quoted 8 lines
Quoted 3 lines

This is expensive. I think it would be much better to just move the board type detection into the init code and not instantiate the driver in the fist place if the board type is unknown.

The board type detection is all over the place in the driver, it's not just for "unknown" types, so how about just saving the board type at probe time and using it then for all other places?

Quoted 5 lines

I must be missing something. The current code detects the board type only once, in the probe function. Otherwise the static variable is used. You are replacing it with repeated calls to get_board_type(). The whole point of the static variable is to avoid the cost of repeated calls to dmi_first_match().

Ah, ok, yes, I was refering to the fact that the driver relies on the detection of the device type in lots of different places (and doesn't ever error out from the detection call.)

Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

We can handle the static variable separately if it really bothers you that much.

I did this change to make patch 2/3 more "obvious" what is happening when the in_visible() callback happens, so that you don't have to worry about the saved value or not. But this whole patch isn't really needed if you don't mind the lookup just happening in the in_visible() callback for the first time.

Quoted 2 lines

That would at least be a minimal change, and just add one extra lookup which is only called once (or zero, if it is used to save the board type).

Ok, I'll switch it up, but really, it's just a simple table lookup loop, and none of the detection calls are on a "hot path" that I can determine. Or am I missing something?

Quoted 3 lines

As I said, my solution would be to move the board type detection into the init function and not instantiate the driver in the first place if the probe function would bail out anyway.

That's not the case today, the only way the probe function would fail today is if the registering of the sysfs files fail. It does not matter if the board detection call passes or not.

Quoted 5 lines

Personally I'd keep
the static variable for simplicity, but if you really dislike it that much, we could pass it around in platform and later driver data. But it seems to me that this could (and should) be a separate patch that doesn't have to be hurried in.

Fair enough, let me rework this and resend a v2 series when I get a chance soon.

thanks for the review.

greg k-h

maintainer
#6 lore raw

Re: [PATCH 1/3] hwmon: (oxp-sensors): remove static board variable

Quoted 25 lines · Greg Kroah-Hartman
Quoted 18 lines · Guenter Roeck
Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines · Guenter Roeck
Quoted 5 lines · Greg Kroah-Hartman

Drivers should not have a single static variable for the type of device they are bound to. While this driver is really going to only have one device at a time in the system, remove the static variable and instead, look up the device type when needed.

Quoted 8 lines
Quoted 3 lines

This is expensive. I think it would be much better to just move the board type detection into the init code and not instantiate the driver in the fist place if the board type is unknown.

The board type detection is all over the place in the driver, it's not just for "unknown" types, so how about just saving the board type at probe time and using it then for all other places?

Quoted 5 lines

I must be missing something. The current code detects the board type only once, in the probe function. Otherwise the static variable is used. You are replacing it with repeated calls to get_board_type(). The whole point of the static variable is to avoid the cost of repeated calls to dmi_first_match().

Quoted 4 lines

Ah, ok, yes, I was refering to the fact that the driver relies on the detection of the device type in lots of different places (and doesn't ever error out from the detection call.)

I am lost again. Current code:

        dmi_entry = dmi_first_match(dmi_table);
        if (!dmi_entry || boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
                return -ENODEV;
Quoted 17 lines
Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

We can handle the static variable separately if it really bothers you that much.

I did this change to make patch 2/3 more "obvious" what is happening when the in_visible() callback happens, so that you don't have to worry about the saved value or not. But this whole patch isn't really needed if you don't mind the lookup just happening in the in_visible() callback for the first time.

Quoted 2 lines

That would at least be a minimal change, and just add one extra lookup which is only called once (or zero, if it is used to save the board type).

Ok, I'll switch it up, but really, it's just a simple table lookup loop, and none of the detection calls are on a "hot path" that I can determine. Or am I missing something?

Quoted 8 lines
Quoted 3 lines

As I said, my solution would be to move the board type detection into the init function and not instantiate the driver in the first place if the probe function would bail out anyway.

That's not the case today, the only way the probe function would fail today is if the registering of the sysfs files fail. It does not matter if the board detection call passes or not.

Again,

        dmi_entry = dmi_first_match(dmi_table);
        if (!dmi_entry || boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
                return -ENODEV;
                ^^^^^^^^^^^^^^^

What am I missing ?

Guenter

author maintainer
#7 lore raw

Re: [PATCH 1/3] hwmon: (oxp-sensors): remove static board variable

Quoted 65 lines · Guenter Roeck
Quoted 25 lines · Greg Kroah-Hartman
Quoted 18 lines · Guenter Roeck
Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines · Guenter Roeck
Quoted 5 lines · Greg Kroah-Hartman

Drivers should not have a single static variable for the type of device they are bound to. While this driver is really going to only have one device at a time in the system, remove the static variable and instead, look up the device type when needed.

Quoted 8 lines
Quoted 3 lines

This is expensive. I think it would be much better to just move the board type detection into the init code and not instantiate the driver in the fist place if the board type is unknown.

The board type detection is all over the place in the driver, it's not just for "unknown" types, so how about just saving the board type at probe time and using it then for all other places?

Quoted 5 lines

I must be missing something. The current code detects the board type only once, in the probe function. Otherwise the static variable is used. You are replacing it with repeated calls to get_board_type(). The whole point of the static variable is to avoid the cost of repeated calls to dmi_first_match().

Quoted 4 lines

Ah, ok, yes, I was refering to the fact that the driver relies on the detection of the device type in lots of different places (and doesn't ever error out from the detection call.)

I am lost again. Current code:

        dmi_entry = dmi_first_match(dmi_table);
        if (!dmi_entry || boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
                return -ENODEV;
Quoted 17 lines
Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

We can handle the static variable separately if it really bothers you that much.

I did this change to make patch 2/3 more "obvious" what is happening when the in_visible() callback happens, so that you don't have to worry about the saved value or not. But this whole patch isn't really needed if you don't mind the lookup just happening in the in_visible() callback for the first time.

Quoted 2 lines

That would at least be a minimal change, and just add one extra lookup which is only called once (or zero, if it is used to save the board type).

Ok, I'll switch it up, but really, it's just a simple table lookup loop, and none of the detection calls are on a "hot path" that I can determine. Or am I missing something?

Quoted 8 lines
Quoted 3 lines

As I said, my solution would be to move the board type detection into the init function and not instantiate the driver in the first place if the probe function would bail out anyway.

That's not the case today, the only way the probe function would fail today is if the registering of the sysfs files fail. It does not matter if the board detection call passes or not.

Quoted 7 lines

Again,

        dmi_entry = dmi_first_match(dmi_table);
        if (!dmi_entry || boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
                return -ENODEV;
                ^^^^^^^^^^^^^^^

What am I missing ?

Nothing, I'm missing it, sorry. Been a long day, let me redo this...

greg k-h

#8 lore raw

Re: [PATCH 1/3] hwmon: (oxp-sensors): remove static board variable

In reply to Guenter Roeck

Hello.

Quoted 11 lines · Greg Kroah-Hartman
Quoted 5 lines

Drivers should not have a single static variable for the type of device they are bound to. While this driver is really going to only have one device at a time in the system, remove the static variable and instead, look up the device type when needed.

This is expensive. I think it would be much better to just move the board type detection into the init code and not instantiate the driver in the fist place if the board type is unknown.

I meant to do this, since the probe function is called only once and is meant for hotpluggable things. But since it works as it is and only loads in supported hardware it didn't seem necessary. Modify what you see fit. And thanks for the attention to the quality of the driver.

Joaquín

Acked-by on v1 3/3
#12 lore raw

Re: [PATCH 3/3] driver core: remove devm_device_add_groups()

In reply to Greg Kroah-Hartman
Quoted 6 lines · Greg Kroah-Hartman

There is no more in-kernel users of this function, and no driver should ever be using it, so remove it from the kernel.

Cc Dmitry Torokhov <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>

Thanks.

Signature · 1 line
Dmitry