aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-08-02 06:47:05 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-08-02 06:47:05 -0400
commit97e2551de3f91add297c1dc4c9dc95297eaadf12 (patch)
tree8321578f79167b35e5db2075bd9ed9aba53e24f2
parentb3173c2292fbaf24ff7062d366830b012ed04269 (diff)
parent23b6904442d08b7dbed7622ed33b236d41a3aa8b (diff)
Merge tag 'dev_groups_all_drivers' into driver-core-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>
-rw-r--r--drivers/base/dd.c14
-rw-r--r--include/linux/device.h3
2 files changed, 17 insertions, 0 deletions
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 5e7041ede0d7..55fbc2467b37 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -554,9 +554,16 @@ re_probe:
554 goto probe_failed; 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 if (test_remove) { 562 if (test_remove) {
558 test_remove = false; 563 test_remove = false;
559 564
565 device_remove_groups(dev, drv->dev_groups);
566
560 if (dev->bus->remove) 567 if (dev->bus->remove)
561 dev->bus->remove(dev); 568 dev->bus->remove(dev);
562 else if (drv->remove) 569 else if (drv->remove)
@@ -584,6 +591,11 @@ re_probe:
584 drv->bus->name, __func__, dev_name(dev), drv->name); 591 drv->bus->name, __func__, dev_name(dev), drv->name);
585 goto done; 592 goto done;
586 593
594dev_groups_failed:
595 if (dev->bus->remove)
596 dev->bus->remove(dev);
597 else if (drv->remove)
598 drv->remove(dev);
587probe_failed: 599probe_failed:
588 if (dev->bus) 600 if (dev->bus)
589 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, 601 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
@@ -1143,6 +1155,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)
1143 1155
1144 pm_runtime_put_sync(dev); 1156 pm_runtime_put_sync(dev);
1145 1157
1158 device_remove_groups(dev, drv->dev_groups);
1159
1146 if (dev->bus && dev->bus->remove) 1160 if (dev->bus && dev->bus->remove)
1147 dev->bus->remove(dev); 1161 dev->bus->remove(dev);
1148 else if (drv->remove) 1162 else if (drv->remove)
diff --git a/include/linux/device.h b/include/linux/device.h
index 63a3aafabcd6..23efaff5f10c 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -391,6 +391,8 @@ enum probe_type {
391 * @resume: Called to bring a device from sleep mode. 391 * @resume: Called to bring a device from sleep mode.
392 * @groups: Default attributes that get created by the driver core 392 * @groups: Default attributes that get created by the driver core
393 * automatically. 393 * automatically.
394 * @dev_groups: Additional attributes attached to device instance once the
395 * it is bound to the driver.
394 * @pm: Power management operations of the device which matched 396 * @pm: Power management operations of the device which matched
395 * this driver. 397 * this driver.
396 * @coredump: Called when sysfs entry is written to. The device driver 398 * @coredump: Called when sysfs entry is written to. The device driver
@@ -427,6 +429,7 @@ struct device_driver {
427 int (*suspend) (struct device *dev, pm_message_t state); 429 int (*suspend) (struct device *dev, pm_message_t state);
428 int (*resume) (struct device *dev); 430 int (*resume) (struct device *dev);
429 const struct attribute_group **groups; 431 const struct attribute_group **groups;
432 const struct attribute_group **dev_groups;
430 433
431 const struct dev_pm_ops *pm; 434 const struct dev_pm_ops *pm;
432 void (*coredump) (struct device *dev); 435 void (*coredump) (struct device *dev);