hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/base/bus.c
....@@ -9,6 +9,7 @@
99 */
1010
1111 #include <linux/async.h>
12
+#include <linux/device/bus.h>
1213 #include <linux/device.h>
1314 #include <linux/module.h>
1415 #include <linux/errno.h>
....@@ -226,12 +227,12 @@
226227 }
227228 static DRIVER_ATTR_IGNORE_LOCKDEP(bind, S_IWUSR, NULL, bind_store);
228229
229
-static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf)
230
+static ssize_t drivers_autoprobe_show(struct bus_type *bus, char *buf)
230231 {
231
- return sprintf(buf, "%d\n", bus->p->drivers_autoprobe);
232
+ return sysfs_emit(buf, "%d\n", bus->p->drivers_autoprobe);
232233 }
233234
234
-static ssize_t store_drivers_autoprobe(struct bus_type *bus,
235
+static ssize_t drivers_autoprobe_store(struct bus_type *bus,
235236 const char *buf, size_t count)
236237 {
237238 if (buf[0] == '0')
....@@ -241,7 +242,7 @@
241242 return count;
242243 }
243244
244
-static ssize_t store_drivers_probe(struct bus_type *bus,
245
+static ssize_t drivers_probe_store(struct bus_type *bus,
245246 const char *buf, size_t count)
246247 {
247248 struct device *dev;
....@@ -323,8 +324,8 @@
323324 * return to the caller and not iterate over any more devices.
324325 */
325326 struct device *bus_find_device(struct bus_type *bus,
326
- struct device *start, void *data,
327
- int (*match)(struct device *dev, void *data))
327
+ struct device *start, const void *data,
328
+ int (*match)(struct device *dev, const void *data))
328329 {
329330 struct klist_iter i;
330331 struct device *dev;
....@@ -341,30 +342,6 @@
341342 return dev;
342343 }
343344 EXPORT_SYMBOL_GPL(bus_find_device);
344
-
345
-static int match_name(struct device *dev, void *data)
346
-{
347
- const char *name = data;
348
-
349
- return sysfs_streq(name, dev_name(dev));
350
-}
351
-
352
-/**
353
- * bus_find_device_by_name - device iterator for locating a particular device of a specific name
354
- * @bus: bus type
355
- * @start: Device to begin with
356
- * @name: name of the device to match
357
- *
358
- * This is similar to the bus_find_device() function above, but it handles
359
- * searching by a name automatically, no need to write another strcmp matching
360
- * function.
361
- */
362
-struct device *bus_find_device_by_name(struct bus_type *bus,
363
- struct device *start, const char *name)
364
-{
365
- return bus_find_device(bus, start, (void *)name, match_name);
366
-}
367
-EXPORT_SYMBOL_GPL(bus_find_device_by_name);
368345
369346 /**
370347 * subsys_find_device_by_id - find a device with a specific enumeration number
....@@ -576,9 +553,8 @@
576553 driver_remove_file(drv, &driver_attr_unbind);
577554 }
578555
579
-static BUS_ATTR(drivers_probe, S_IWUSR, NULL, store_drivers_probe);
580
-static BUS_ATTR(drivers_autoprobe, S_IWUSR | S_IRUGO,
581
- show_drivers_autoprobe, store_drivers_autoprobe);
556
+static BUS_ATTR_WO(drivers_probe);
557
+static BUS_ATTR_RW(drivers_autoprobe);
582558
583559 static int add_probe_files(struct bus_type *bus)
584560 {
....@@ -645,7 +621,7 @@
645621 if (drv->bus->p->drivers_autoprobe) {
646622 error = driver_attach(drv);
647623 if (error)
648
- goto out_unregister;
624
+ goto out_del_list;
649625 }
650626 module_add_driver(drv->owner, drv);
651627
....@@ -672,6 +648,8 @@
672648
673649 return 0;
674650
651
+out_del_list:
652
+ klist_del(&priv->knode_bus);
675653 out_unregister:
676654 kobject_put(&priv->kobj);
677655 /* drv->p is freed in driver_release() */
....@@ -806,7 +784,14 @@
806784 rc = kobject_synth_uevent(&bus->p->subsys.kobj, buf, count);
807785 return rc ? rc : count;
808786 }
809
-static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store);
787
+/*
788
+ * "open code" the old BUS_ATTR() macro here. We want to use BUS_ATTR_WO()
789
+ * here, but can not use it as earlier in the file we have
790
+ * DEVICE_ATTR_WO(uevent), which would cause a clash with the with the store
791
+ * function name.
792
+ */
793
+static struct bus_attribute bus_attr_uevent = __ATTR(uevent, S_IWUSR, NULL,
794
+ bus_uevent_store);
810795
811796 /**
812797 * bus_register - register a driver-core subsystem