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 <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
Signed-off-by: Wim Van Sebroeck <[email protected]>
This commit is contained in:
Guenter Roeck 2016-01-03 15:11:56 -08:00 • committed by Wim Van Sebroeck
commit faa584757b
3 changed files with 9 additions and 2 deletions

View file

@ -744,8 +744,9 @@ int watchdog_dev_register(struct watchdog_device *wdd)
if (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)) {
watchdog_cdev_unregister(wdd);
return PTR_ERR(dev);