Skip to contentSkip to conversation

hwmon: Make name attribute mandatory for new APIs

PATCH Superseded Guenter Roeck 2 participants 3 messages Jan 24, 2017 – Jan 25, 2017 Hardware monitoring

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH v2 1/1 hwmon: Make name attribute mandatory for new APIs

It does not make sense to use one of the the new APIs when not even providing a name attribute. Make it mandatory.

---
v2: One should use ERR_PTR where appropriate

 drivers/hwmon/hwmon.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/hwmon/hwmon.c +6 -0
index 0c5660ccdbf4..a408b10d9a86 100644
@@ -651,6 +651,9 @@ hwmon_device_register_with_groups(struct device *dev, const char *name,
 				  void *drvdata,
 				  const struct attribute_group **groups)
 {
+	if (!name)
+		return ERR_PTR(-EINVAL);
+
 	return __hwmon_device_register(dev, name, drvdata, NULL, groups);
 }
 EXPORT_SYMBOL_GPL(hwmon_device_register_with_groups);
@@ -674,6 +677,9 @@ hwmon_device_register_with_info(struct device *dev, const char *name,
 				const struct hwmon_chip_info *chip,
 				const struct attribute_group **extra_groups)
 {
+	if (!name)
+		return ERR_PTR(-EINVAL);
+
 	if (chip && (!chip->ops || !chip->ops->is_visible || !chip->info))
 		return ERR_PTR(-EINVAL);
 
Signature · 1 line
2.7.4
#1 lore raw

Hi Guenter,

Quoted 2 lines · Guenter Roeck

It does not make sense to use one of the the new APIs when not even providing a name attribute. Make it mandatory.

Fully agreed, but...

Quoted 22 lines

---
v2: One should use ERR_PTR where appropriate

 drivers/hwmon/hwmon.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/hwmon/hwmon.c +3 -0
index 0c5660ccdbf4..a408b10d9a86 100644
@@ -651,6 +651,9 @@ hwmon_device_register_with_groups(struct device *dev, const char *name,
 				  void *drvdata,
 				  const struct attribute_group **groups)
 {
+	if (!name)
+		return ERR_PTR(-EINVAL);
+
 	return __hwmon_device_register(dev, name, drvdata, NULL, groups);
 }
 EXPORT_SYMBOL_GPL(hwmon_device_register_with_groups);

drivers/hwmon/hwmon.c hwmon_device_register_with_info(struct device *dev, const char *name, · line 685

Quoted 9 lines
drivers/hwmon/hwmon.c +3 -0
@@ -674,6 +677,9 @@ hwmon_device_register_with_info(struct device *dev, const char *name,
 				const struct hwmon_chip_info *chip,
 				const struct attribute_group **extra_groups)
 {
+	if (!name)
+		return ERR_PTR(-EINVAL);
+
 	if (chip && (!chip->ops || !chip->ops->is_visible || !chip->info))
 		return ERR_PTR(-EINVAL);
 

... this breaks hwmon_device_register(), which calls:

	return hwmon_device_register_with_groups(dev, NULL, NULL, NULL);
	                                              ^^^^
	                                              name

So you would have to change hwmon_device_register() to call __hwmon_device_register() directly first.

Thanks,

Signature · 6 lines
Jean Delvare
SUSE L3 Support

-- 
Jean Delvare
SUSE L3 Support
author maintainer
#2 lore raw
Quoted 42 lines · Jean Delvare

Hi Guenter,

Quoted 2 lines · Guenter Roeck

It does not make sense to use one of the the new APIs when not even providing a name attribute. Make it mandatory.

Fully agreed, but...

Quoted 22 lines

---
v2: One should use ERR_PTR where appropriate

 drivers/hwmon/hwmon.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/hwmon/hwmon.c +3 -0
index 0c5660ccdbf4..a408b10d9a86 100644
@@ -651,6 +651,9 @@ hwmon_device_register_with_groups(struct device *dev, const char *name,
 				  void *drvdata,
 				  const struct attribute_group **groups)
 {
+	if (!name)
+		return ERR_PTR(-EINVAL);
+
 	return __hwmon_device_register(dev, name, drvdata, NULL, groups);
 }
 EXPORT_SYMBOL_GPL(hwmon_device_register_with_groups);

drivers/hwmon/hwmon.c hwmon_device_register_with_info(struct device *dev, const char *name, · line 685

Quoted 9 lines
drivers/hwmon/hwmon.c +3 -0
@@ -674,6 +677,9 @@ hwmon_device_register_with_info(struct device *dev, const char *name,
 				const struct hwmon_chip_info *chip,
 				const struct attribute_group **extra_groups)
 {
+	if (!name)
+		return ERR_PTR(-EINVAL);
+
 	if (chip && (!chip->ops || !chip->ops->is_visible || !chip->info))
 		return ERR_PTR(-EINVAL);
 

... this breaks hwmon_device_register(), which calls:

Quoted 7 lines
	return hwmon_device_register_with_groups(dev, NULL, NULL, NULL);
	                                              ^^^^
	                                              name

So you would have to change hwmon_device_register() to call __hwmon_device_register() directly first.

Thanks!

Guenter