hwmon: Introduce hwmon_device_register_for_thermal
authorGuenter Roeck <linux@roeck-us.net>
Wed, 11 May 2022 13:29:59 +0000 (06:29 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 22 May 2022 18:32:31 +0000 (11:32 -0700)
The thermal subsystem registers a hwmon driver without providing
chip or sysfs group information. This is for legacy reasons and
would be difficult to change. At the same time, we want to enforce
that chip information is provided when registering a hwmon device
using hwmon_device_register_with_info(). To enable this, introduce
a special API for use only by the thermal subsystem.

Acked-by: Rafael J . Wysocki <rafael@kernel.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/hwmon.c
include/linux/hwmon.h

index 5915ccfdb7d9af7780c1dc1c5b9bcecee63c9df6..13053a4edc9e1ffa7b78bcb5329e6a672162ef40 100644 (file)
@@ -916,6 +916,31 @@ hwmon_device_register_with_info(struct device *dev, const char *name,
 }
 EXPORT_SYMBOL_GPL(hwmon_device_register_with_info);
 
+/**
+ * hwmon_device_register_for_thermal - register hwmon device for thermal subsystem
+ * @dev: the parent device
+ * @name: hwmon name attribute
+ * @drvdata: driver data to attach to created device
+ *
+ * The use of this function is restricted. It is provided for legacy reasons
+ * and must only be called from the thermal subsystem.
+ *
+ * hwmon_device_unregister() must be called when the device is no
+ * longer needed.
+ *
+ * Returns the pointer to the new device.
+ */
+struct device *
+hwmon_device_register_for_thermal(struct device *dev, const char *name,
+                                 void *drvdata)
+{
+       if (!name || !dev)
+               return ERR_PTR(-EINVAL);
+
+       return __hwmon_device_register(dev, name, drvdata, NULL, NULL);
+}
+EXPORT_SYMBOL_NS_GPL(hwmon_device_register_for_thermal, HWMON_THERMAL);
+
 /**
  * hwmon_device_register - register w/ hwmon
  * @dev: the device to register
index 4efaf06fd2b8cc9785d40b96fd9d83aa0f5ee9f4..14325f93c6b2bbfbe4648d18f057ac23094850b5 100644 (file)
@@ -450,6 +450,9 @@ hwmon_device_register_with_info(struct device *dev,
                                const struct hwmon_chip_info *info,
                                const struct attribute_group **extra_groups);
 struct device *
+hwmon_device_register_for_thermal(struct device *dev, const char *name,
+                                 void *drvdata);
+struct device *
 devm_hwmon_device_register_with_info(struct device *dev,
                                const char *name, void *drvdata,
                                const struct hwmon_chip_info *info,