Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'dev_groups_all_drivers' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core into usb-next

dev_groups added to struct driver

Persistent tag for others to pull this branch from

This is the first patch in a longer series that adds 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.

See:
https://lore.kernel.org/r/20190731124349.4474-2-gregkh@linuxfoundation.org
for details on this patch, and examples of how to use it in other
drivers.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+17
+14
drivers/base/dd.c
··· 554 554 goto probe_failed; 555 555 } 556 556 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 + 557 562 if (test_remove) { 558 563 test_remove = false; 564 + 565 + device_remove_groups(dev, drv->dev_groups); 559 566 560 567 if (dev->bus->remove) 561 568 dev->bus->remove(dev); ··· 591 584 drv->bus->name, __func__, dev_name(dev), drv->name); 592 585 goto done; 593 586 587 + dev_groups_failed: 588 + if (dev->bus->remove) 589 + dev->bus->remove(dev); 590 + else if (drv->remove) 591 + drv->remove(dev); 594 592 probe_failed: 595 593 if (dev->bus) 596 594 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, ··· 1125 1113 dev); 1126 1114 1127 1115 pm_runtime_put_sync(dev); 1116 + 1117 + device_remove_groups(dev, drv->dev_groups); 1128 1118 1129 1119 if (dev->bus && dev->bus->remove) 1130 1120 dev->bus->remove(dev);
+3
include/linux/device.h
··· 262 262 * @resume: Called to bring a device from sleep mode. 263 263 * @groups: Default attributes that get created by the driver core 264 264 * automatically. 265 + * @dev_groups: Additional attributes attached to device instance once the 266 + * it is bound to the driver. 265 267 * @pm: Power management operations of the device which matched 266 268 * this driver. 267 269 * @coredump: Called when sysfs entry is written to. The device driver ··· 298 296 int (*suspend) (struct device *dev, pm_message_t state); 299 297 int (*resume) (struct device *dev); 300 298 const struct attribute_group **groups; 299 + const struct attribute_group **dev_groups; 301 300 302 301 const struct dev_pm_ops *pm; 303 302 void (*coredump) (struct device *dev);