aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2007-08-12 14:43:55 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-10-12 17:51:06 -0400
commit7ac1cf4a87f446c130f7d8a4fe7e519f532a11de (patch)
tree7dc4b1bfe3e932f22ea0f0769fe20a772fb13d5a /drivers
parent5c5daf657cb5f963a38413f2852279d7a3843144 (diff)
Driver core: add uevent file for bus and driver
This has been in the SuSE kernels for some time now. Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/base/bus.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 0a8d075f3e6c..6768a01e210b 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -610,6 +610,17 @@ static inline int add_probe_files(struct bus_type *bus) { return 0; }
610static inline void remove_probe_files(struct bus_type *bus) {} 610static inline void remove_probe_files(struct bus_type *bus) {}
611#endif 611#endif
612 612
613static ssize_t driver_uevent_store(struct device_driver *drv,
614 const char *buf, size_t count)
615{
616 enum kobject_action action;
617
618 if (kobject_action_type(buf, count, &action) == 0)
619 kobject_uevent(&drv->kobj, action);
620 return count;
621}
622static DRIVER_ATTR(uevent, S_IWUSR, NULL, driver_uevent_store);
623
613/** 624/**
614 * bus_add_driver - Add a driver to the bus. 625 * bus_add_driver - Add a driver to the bus.
615 * @drv: driver. 626 * @drv: driver.
@@ -640,6 +651,11 @@ int bus_add_driver(struct device_driver *drv)
640 klist_add_tail(&drv->knode_bus, &bus->klist_drivers); 651 klist_add_tail(&drv->knode_bus, &bus->klist_drivers);
641 module_add_driver(drv->owner, drv); 652 module_add_driver(drv->owner, drv);
642 653
654 error = driver_create_file(drv, &driver_attr_uevent);
655 if (error) {
656 printk(KERN_ERR "%s: uevent attr (%s) failed\n",
657 __FUNCTION__, drv->name);
658 }
643 error = driver_add_attrs(bus, drv); 659 error = driver_add_attrs(bus, drv);
644 if (error) { 660 if (error) {
645 /* How the hell do we get out of this pickle? Give up */ 661 /* How the hell do we get out of this pickle? Give up */
@@ -677,6 +693,7 @@ void bus_remove_driver(struct device_driver * drv)
677 693
678 remove_bind_files(drv); 694 remove_bind_files(drv);
679 driver_remove_attrs(drv->bus, drv); 695 driver_remove_attrs(drv->bus, drv);
696 driver_remove_file(drv, &driver_attr_uevent);
680 klist_remove(&drv->knode_bus); 697 klist_remove(&drv->knode_bus);
681 pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name); 698 pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name);
682 driver_detach(drv); 699 driver_detach(drv);
@@ -804,6 +821,17 @@ static void klist_devices_put(struct klist_node *n)
804 put_device(dev); 821 put_device(dev);
805} 822}
806 823
824static ssize_t bus_uevent_store(struct bus_type *bus,
825 const char *buf, size_t count)
826{
827 enum kobject_action action;
828
829 if (kobject_action_type(buf, count, &action) == 0)
830 kobject_uevent(&bus->subsys.kobj, action);
831 return count;
832}
833static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store);
834
807/** 835/**
808 * bus_register - register a bus with the system. 836 * bus_register - register a bus with the system.
809 * @bus: bus. 837 * @bus: bus.
@@ -828,6 +856,10 @@ int bus_register(struct bus_type * bus)
828 if (retval) 856 if (retval)
829 goto out; 857 goto out;
830 858
859 retval = bus_create_file(bus, &bus_attr_uevent);
860 if (retval)
861 goto bus_uevent_fail;
862
831 kobject_set_name(&bus->devices.kobj, "devices"); 863 kobject_set_name(&bus->devices.kobj, "devices");
832 bus->devices.kobj.parent = &bus->subsys.kobj; 864 bus->devices.kobj.parent = &bus->subsys.kobj;
833 retval = kset_register(&bus->devices); 865 retval = kset_register(&bus->devices);
@@ -863,6 +895,8 @@ bus_probe_files_fail:
863bus_drivers_fail: 895bus_drivers_fail:
864 kset_unregister(&bus->devices); 896 kset_unregister(&bus->devices);
865bus_devices_fail: 897bus_devices_fail:
898 bus_remove_file(bus, &bus_attr_uevent);
899bus_uevent_fail:
866 subsystem_unregister(&bus->subsys); 900 subsystem_unregister(&bus->subsys);
867out: 901out:
868 return retval; 902 return retval;
@@ -882,6 +916,7 @@ void bus_unregister(struct bus_type * bus)
882 remove_probe_files(bus); 916 remove_probe_files(bus);
883 kset_unregister(&bus->drivers); 917 kset_unregister(&bus->drivers);
884 kset_unregister(&bus->devices); 918 kset_unregister(&bus->devices);
919 bus_remove_file(bus, &bus_attr_uevent);
885 subsystem_unregister(&bus->subsys); 920 subsystem_unregister(&bus->subsys);
886} 921}
887 922