Explorar o código

watchdog: Add support for creating driver specific sysfs attributes

The Zodiac watchdog driver attaches additional sysfs attributes to the
watchdog device. This has a number of problems: The watchdog device
lifetime differs from the driver lifetime, and the device structure
should therefore not be accessed from drivers. Also, creating sysfs
attributes after driver registration results in a potential race condition
if user space expects the attributes to exist but they don't exist yet.

Add support for creating driver specific sysfs attributes to the watchdog
core to solve the problems.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Guenter Roeck %!s(int64=9) %!d(string=hai) anos
pai
achega
faa584757b

+ 3 - 0
Documentation/watchdog/watchdog-kernel-api.txt

@@ -46,6 +46,7 @@ struct watchdog_device {
 	int id;
 	int id;
 	struct device *dev;
 	struct device *dev;
 	struct device *parent;
 	struct device *parent;
+	const struct attribute_group **groups;
 	const struct watchdog_info *info;
 	const struct watchdog_info *info;
 	const struct watchdog_ops *ops;
 	const struct watchdog_ops *ops;
 	unsigned int bootstatus;
 	unsigned int bootstatus;
@@ -68,6 +69,8 @@ It contains following fields:
 * dev: device under the watchdog class (created by watchdog_register_device).
 * dev: device under the watchdog class (created by watchdog_register_device).
 * parent: set this to the parent device (or NULL) before calling
 * parent: set this to the parent device (or NULL) before calling
   watchdog_register_device.
   watchdog_register_device.
+* groups: List of sysfs attribute groups to create when creating the watchdog
+  device.
 * info: a pointer to a watchdog_info structure. This structure gives some
 * info: a pointer to a watchdog_info structure. This structure gives some
   additional information about the watchdog timer itself. (Like it's unique name)
   additional information about the watchdog timer itself. (Like it's unique name)
 * ops: a pointer to the list of watchdog operations that the watchdog supports.
 * ops: a pointer to the list of watchdog operations that the watchdog supports.

+ 3 - 2
drivers/watchdog/watchdog_dev.c

@@ -744,8 +744,9 @@ int watchdog_dev_register(struct watchdog_device *wdd)
 	if (ret)
 	if (ret)
 		return ret;
 		return ret;
 
 
-	dev = device_create(&watchdog_class, wdd->parent, devno, wdd,
-			    "watchdog%d", wdd->id);
+	dev = device_create_with_groups(&watchdog_class, wdd->parent,
+					devno, wdd, wdd->groups,
+					"watchdog%d", wdd->id);
 	if (IS_ERR(dev)) {
 	if (IS_ERR(dev)) {
 		watchdog_cdev_unregister(wdd);
 		watchdog_cdev_unregister(wdd);
 		return PTR_ERR(dev);
 		return PTR_ERR(dev);

+ 3 - 0
include/linux/watchdog.h

@@ -55,6 +55,8 @@ struct watchdog_ops {
  * @id:		The watchdog's ID. (Allocated by watchdog_register_device)
  * @id:		The watchdog's ID. (Allocated by watchdog_register_device)
  * @dev:	The device for our watchdog
  * @dev:	The device for our watchdog
  * @parent:	The parent bus device
  * @parent:	The parent bus device
+ * @groups:	List of sysfs attribute groups to create when creating the
+ *		watchdog device.
  * @info:	Pointer to a watchdog_info structure.
  * @info:	Pointer to a watchdog_info structure.
  * @ops:	Pointer to the list of watchdog operations.
  * @ops:	Pointer to the list of watchdog operations.
  * @bootstatus:	Status of the watchdog device at boot.
  * @bootstatus:	Status of the watchdog device at boot.
@@ -82,6 +84,7 @@ struct watchdog_device {
 	int id;
 	int id;
 	struct device *dev;
 	struct device *dev;
 	struct device *parent;
 	struct device *parent;
+	const struct attribute_group **groups;
 	const struct watchdog_info *info;
 	const struct watchdog_info *info;
 	const struct watchdog_ops *ops;
 	const struct watchdog_ops *ops;
 	unsigned int bootstatus;
 	unsigned int bootstatus;