Skip to content

Commit 23b6904

Browse files
dtorgregkh
authored andcommitted
driver core: add dev_groups to all drivers
Add the ability for the driver core to create and remove a list of attribute groups automatically when the device is bound/unbound from a specific driver. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Tested-by: Richard Gong <richard.gong@linux.intel.com> Link: https://lore.kernel.org/r/20190731124349.4474-2-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5f9e832 commit 23b6904

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎drivers/base/dd.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,16 @@ static int really_probe(struct device *dev, struct device_driver *drv)
554554
goto probe_failed;
555555
}
556556

557+
if (device_add_groups(dev, drv->dev_groups)) {
558+
dev_err(dev, "device_add_groups() failed\n");
559+
goto dev_groups_failed;
560+
}
561+
557562
if (test_remove) {
558563
test_remove = false;
559564

565+
device_remove_groups(dev, drv->dev_groups);
566+
560567
if (dev->bus->remove)
561568
dev->bus->remove(dev);
562569
else if (drv->remove)
@@ -584,6 +591,11 @@ static int really_probe(struct device *dev, struct device_driver *drv)
584591
drv->bus->name, __func__, dev_name(dev), drv->name);
585592
goto done;
586593

594+
dev_groups_failed:
595+
if (dev->bus->remove)
596+
dev->bus->remove(dev);
597+
else if (drv->remove)
598+
drv->remove(dev);
587599
probe_failed:
588600
if (dev->bus)
589601
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
@@ -1114,6 +1126,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)
11141126

11151127
pm_runtime_put_sync(dev);
11161128

1129+
device_remove_groups(dev, drv->dev_groups);
1130+
11171131
if (dev->bus && dev->bus->remove)
11181132
dev->bus->remove(dev);
11191133
else if (drv->remove)

‎include/linux/device.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ enum probe_type {
262262
* @resume: Called to bring a device from sleep mode.
263263
* @groups: Default attributes that get created by the driver core
264264
* automatically.
265+
* @dev_groups: Additional attributes attached to device instance once the
266+
* it is bound to the driver.
265267
* @pm: Power management operations of the device which matched
266268
* this driver.
267269
* @coredump: Called when sysfs entry is written to. The device driver
@@ -296,6 +298,7 @@ struct device_driver {
296298
int (*suspend) (struct device *dev, pm_message_t state);
297299
int (*resume) (struct device *dev);
298300
const struct attribute_group **groups;
301+
const struct attribute_group **dev_groups;
299302

300303
const struct dev_pm_ops *pm;
301304
void (*coredump) (struct device *dev);

0 commit comments

Comments
 (0)