The patch titled drivers/base: check errors has been added to the -mm tree. Its filename is drivers-base-check-errors.patch See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find out what to do about this ------------------------------------------------------ Subject: drivers/base: check errors From: Andrew Morton <akpm@xxxxxxxx> urrrrghhhhh. Try to plug most of it. Gave up in one place due to lack of an obvious way to back out of klist_add_tail(). That needs revisiting. Much more needs doing. Cc: "Randy.Dunlap" <rdunlap@xxxxxxxxxxxx> Cc: Greg KH <greg@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxx> --- drivers/base/base.h | 2 drivers/base/bus.c | 103 +++++++++++++++++++++++++-------------- drivers/base/dd.c | 37 ++++++++++---- include/linux/device.h | 8 +-- 4 files changed, 100 insertions(+), 50 deletions(-) diff -puN drivers/base/dd.c~drivers-base-check-errors drivers/base/dd.c --- a/drivers/base/dd.c~drivers-base-check-errors +++ a/drivers/base/dd.c @@ -38,17 +38,29 @@ * * This function must be called with @dev->sem held. */ -void device_bind_driver(struct device * dev) +int device_bind_driver(struct device *dev) { - if (klist_node_attached(&dev->knode_driver)) - return; + int ret; + + if (klist_node_attached(&dev->knode_driver)) { + printk(KERN_WARNING "%s: device %s already bound\n", + __FUNCTION__, kobject_name(&dev->kobj)); + return 0; + } pr_debug("bound device '%s' to driver '%s'\n", dev->bus_id, dev->driver->name); klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); - sysfs_create_link(&dev->driver->kobj, &dev->kobj, + ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, kobject_name(&dev->kobj)); - sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver"); + if (ret == 0) { + ret = sysfs_create_link(&dev->kobj, &dev->driver->kobj, + "driver"); + if (ret) + sysfs_remove_link(&dev->driver->kobj, + kobject_name(&dev->kobj)); + } + return ret; } /** @@ -91,7 +103,11 @@ int driver_probe_device(struct device_dr goto ProbeFailed; } } - device_bind_driver(dev); + if (device_bind_driver(dev)) { + printk(KERN_ERR "%s: device_bind_driver(%s) failed\n", + __FUNCTION__, dev->bus_id); + /* How does undo a ->probe? We're screwed. */ + } ret = 1; pr_debug("%s: Bound Device %s to Driver %s\n", drv->bus->name, dev->bus_id, drv->name); @@ -139,8 +155,9 @@ int device_attach(struct device * dev) down(&dev->sem); if (dev->driver) { - device_bind_driver(dev); - ret = 1; + ret = device_bind_driver(dev); + if (ret == 0) + ret = 1; } else ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); up(&dev->sem); @@ -182,9 +199,9 @@ static int __driver_attach(struct device * returns 0 and the @dev->driver is set, we've found a * compatible pair. */ -void driver_attach(struct device_driver * drv) +int driver_attach(struct device_driver * drv) { - bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); + return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); } /** diff -puN drivers/base/bus.c~drivers-base-check-errors drivers/base/bus.c --- a/drivers/base/bus.c~drivers-base-check-errors +++ a/drivers/base/bus.c @@ -371,12 +371,20 @@ int bus_add_device(struct device * dev) if (bus) { pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); error = device_add_attrs(bus, dev); - if (!error) { - sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id); - sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "subsystem"); - sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus"); - } + if (error) + goto out; + error = sysfs_create_link(&bus->devices.kobj, + &dev->kobj, dev->bus_id); + if (error) + goto out; + error = sysfs_create_link(&dev->kobj, + &dev->bus->subsys.kset.kobj, "subsystem"); + if (error) + goto out; + error = sysfs_create_link(&dev->kobj, + &dev->bus->subsys.kset.kobj, "bus"); } +out: return error; } @@ -386,14 +394,17 @@ int bus_add_device(struct device * dev) * * - Try to attach to driver. */ -void bus_attach_device(struct device * dev) +int bus_attach_device(struct device * dev) { - struct bus_type * bus = dev->bus; + struct bus_type *bus = dev->bus; + int ret = 0; if (bus) { - device_attach(dev); - klist_add_tail(&dev->knode_bus, &bus->klist_devices); + ret = device_attach(dev); + if (ret == 0) + klist_add_tail(&dev->knode_bus, &bus->klist_devices); } + return ret; } /** @@ -455,10 +466,17 @@ static void driver_remove_attrs(struct b * Thanks to drivers making their tables __devinit, we can't allow manual * bind and unbind from userspace unless CONFIG_HOTPLUG is enabled. */ -static void add_bind_files(struct device_driver *drv) +static int __must_check add_bind_files(struct device_driver *drv) { - driver_create_file(drv, &driver_attr_unbind); - driver_create_file(drv, &driver_attr_bind); + int ret; + + ret = driver_create_file(drv, &driver_attr_unbind); + if (ret == 0) { + ret = driver_create_file(drv, &driver_attr_bind); + if (ret) + driver_remove_file(drv, &driver_attr_unbind); + } + return ret; } static void remove_bind_files(struct device_driver *drv) @@ -476,7 +494,7 @@ static inline void remove_bind_files(str * @drv: driver. * */ -int bus_add_driver(struct device_driver * drv) +int bus_add_driver(struct device_driver *drv) { struct bus_type * bus = get_bus(drv->bus); int error = 0; @@ -484,27 +502,39 @@ int bus_add_driver(struct device_driver if (bus) { pr_debug("bus %s: add driver %s\n", bus->name, drv->name); error = kobject_set_name(&drv->kobj, "%s", drv->name); - if (error) { - put_bus(bus); - return error; - } + if (error) + goto out_put_bus; drv->kobj.kset = &bus->drivers; - if ((error = kobject_register(&drv->kobj))) { - put_bus(bus); - return error; - } + if ((error = kobject_register(&drv->kobj))) + goto out_put_bus; - driver_attach(drv); + error = driver_attach(drv); + if (error) + goto out_unregister; klist_add_tail(&drv->knode_bus, &bus->klist_drivers); module_add_driver(drv->owner, drv); - driver_add_attrs(bus, drv); - add_bind_files(drv); + error = driver_add_attrs(bus, drv); + if (error) { + /* How the hell do we get out of this pickle? Give up */ + printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", + __FUNCTION__, drv->name); + } + error = add_bind_files(drv); + if (error) { + /* Ditto */ + printk(KERN_ERR "%s: add_bind_files(%s) failed\n", + __FUNCTION__, drv->name); + } } return error; +out_unregister: + kobject_unregister(&drv->kobj); +out_put_bus: + put_bus(bus); + return error; } - /** * bus_remove_driver - delete driver from bus's knowledge. * @drv: driver. @@ -530,16 +560,19 @@ void bus_remove_driver(struct device_dri /* Helper for bus_rescan_devices's iter */ -static int bus_rescan_devices_helper(struct device *dev, void *data) +static int __must_check bus_rescan_devices_helper(struct device *dev, + void *data) { + int ret = 0; + if (!dev->driver) { if (dev->parent) /* Needed for USB */ down(&dev->parent->sem); - device_attach(dev); + ret = device_attach(dev); if (dev->parent) up(&dev->parent->sem); } - return 0; + return ret; } /** @@ -550,9 +583,9 @@ static int bus_rescan_devices_helper(str * attached and rescan it against existing drivers to see if it matches * any by calling device_attach() for the unbound devices. */ -void bus_rescan_devices(struct bus_type * bus) +int bus_rescan_devices(struct bus_type * bus) { - bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); + return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); } /** @@ -564,7 +597,7 @@ void bus_rescan_devices(struct bus_type * to use if probing criteria changed during a devices lifetime and * driver attachment should change accordingly. */ -void device_reprobe(struct device *dev) +int device_reprobe(struct device *dev) { if (dev->driver) { if (dev->parent) /* Needed for USB */ @@ -573,14 +606,14 @@ void device_reprobe(struct device *dev) if (dev->parent) up(&dev->parent->sem); } - - bus_rescan_devices_helper(dev, NULL); + return bus_rescan_devices_helper(dev, NULL); } EXPORT_SYMBOL_GPL(device_reprobe); -struct bus_type * get_bus(struct bus_type * bus) +struct bus_type *get_bus(struct bus_type *bus) { - return bus ? container_of(subsys_get(&bus->subsys), struct bus_type, subsys) : NULL; + return bus ? container_of(subsys_get(&bus->subsys), + struct bus_type, subsys) : NULL; } void put_bus(struct bus_type * bus) diff -puN include/linux/device.h~drivers-base-check-errors include/linux/device.h --- a/include/linux/device.h~drivers-base-check-errors +++ a/include/linux/device.h @@ -63,7 +63,7 @@ struct bus_type { extern int __must_check bus_register(struct bus_type * bus); extern void bus_unregister(struct bus_type * bus); -extern void bus_rescan_devices(struct bus_type * bus); +extern int __must_check bus_rescan_devices(struct bus_type * bus); /* iterator helpers for buses */ @@ -391,11 +391,11 @@ extern int device_rename(struct device * * Manual binding of a device to driver. See drivers/base/bus.c * for information on use. */ -extern void device_bind_driver(struct device * dev); +extern int __must_check device_bind_driver(struct device *dev); extern void device_release_driver(struct device * dev); extern int __must_check device_attach(struct device * dev); -extern void driver_attach(struct device_driver * drv); -extern void device_reprobe(struct device *dev); +extern int __must_check driver_attach(struct device_driver *drv); +extern int __must_check device_reprobe(struct device *dev); /* * Easy functions for dynamically creating devices on the fly diff -puN /dev/null /dev/null diff -puN drivers/base/base.h~drivers-base-check-errors drivers/base/base.h --- a/drivers/base/base.h~drivers-base-check-errors +++ a/drivers/base/base.h @@ -16,7 +16,7 @@ extern int cpu_dev_init(void); extern int attribute_container_init(void); extern int bus_add_device(struct device * dev); -extern void bus_attach_device(struct device * dev); +extern int __must_check bus_attach_device(struct device * dev); extern void bus_remove_device(struct device * dev); extern struct bus_type *get_bus(struct bus_type * bus); extern void put_bus(struct bus_type * bus); _ Patches currently in -mm which might be from akpm@xxxxxxxx are origin.patch alloc_fdtable-expansion-fix.patch struct-file-leakage-tweak.patch disable-debugging-version-of-write_lock.patch acpi-asus-s3-resume-fix-fix.patch sony_apci-resume.patch kauditd_thread-warning-fix.patch revert-gregkh-driver-class_device_rename-remove.patch revert-gregkh-driver-network-class_device-to-device.patch add-__must_check-to-device-management-code.patch add-config_enable_must_check.patch v4l-dev2-handle-__must_check.patch videodev-check-return-values.patch git-geode-fixup.patch git-gfs2.patch git-ia64.patch git-ia64-fixup.patch git-ieee1394-fixup.patch git-input.patch git-input-list_for_each_entry-fix.patch git-input-list_for_each_entry-fix-fix.patch sane-menuconfig-colours.patch git-klibc.patch git-hdrcleanup-vs-git-klibc-on-ia64.patch git-hdrcleanup-vs-git-klibc-on-ia64-2.patch git-libata-all.patch sata-is-bust-on-s390.patch e1000-irq-naming-update.patch 8139cp-printk-fix.patch 82596-section-fixes.patch ac3200-section-fixes.patch cops-section-fix.patch cs89x0-section-fix.patch at1700-section-fix.patch e2100-section-fix.patch eepro-section-fix.patch eexpress-section-fix.patch es3210-section-fix.patch eth16i-section-fix.patch lance-section-fix.patch lne390-section-fix.patch ni52-section-fix.patch ibmtr-section-fix.patch smctr-section-fix.patch wd-section-fix.patch ni65-section-fix.patch seeq8005-section-fix.patch winbond-840-section-fix.patch fealnx-section-fix.patch sundance-section-fix.patch drivers-net-ns83820c-add-paramter-to-disable-auto.patch git-pcmcia-fixup.patch git-powerpc-briq_panel-Kconfig-fix.patch git-sas.patch git-serial.patch serial-fix-uart_bug_txen-test.patch revert-gregkh-pci-pci-test-that-drivers-properly-call-pci_set_master.patch revert-VIA-quirk-fixup-additional-PCI-IDs.patch revert-PCI-quirk-VIA-IRQ-fixup-should-only-run-for-VIA-southbridges.patch pcie-check-and-return-bus_register-errors-fix.patch git-s390-fixup.patch git-scsi-rc-fixes.patch NCR_D700-section-fix.patch fix-panic-when-reinserting-adaptec-pcmcia-scsi-card-tidy.patch areca-raid-linux-scsi-driver.patch areca-raid-linux-scsi-driver-update7-fix.patch git-scsi-target-fixup.patch sparc64-of_device_register-error-checking-fix.patch pm-usb-hcds-use-pm_event_prethaw-fix.patch kill-usb-kconfig-warning.patch rtl8150_disconnect-needs-tasklet_kill.patch git-supertrak-fixup.patch bcm43xx-opencoded-locking.patch sleazy-fpu-feature-x86_64-support.patch x86_64-wire-up-oops_enter-oops_exit.patch adix-tree-rcu-lockless-readside-update-tidy.patch mm-tracking-shared-dirty-pages-checks.patch mm-tracking-shared-dirty-pages-wimp.patch convert-i386-numa-kva-space-to-bootmem-tidy.patch reduce-max_nr_zones-make-display-of-highmem-counters-conditional-on-config_highmem-tidy.patch reduce-max_nr_zones-use-enum-to-define-zones-reformat-and-comment-cleanup.patch reduce-max_nr_zones-remove-display-of-counters-for-unconfigured-zones-s390-fix.patch out-of-memory-notifier-tidy.patch acx1xx-wireless-driver.patch tiacx-pci-build-fix.patch tiacx-ia64-fix.patch tiacx-build-fix.patch binfmt_elf-consistently-use-loff_t.patch swsusp-write-timer.patch swsusp-write-speedup.patch swsusp-read-timer.patch swsusp-read-speedup.patch swsusp-read-speedup-fix.patch swsusp-read-speedup-cleanup.patch swsusp-read-speedup-cleanup-2.patch deprecate-smbfs-in-favour-of-cifs.patch edac-new-opteron-athlon64-memory-controller-driver-tidy.patch x86-microcode-microcode-driver-cleanup-tidy.patch x86-microcode-add-sysfs-and-hotplug-support-fix.patch eisa-bus-modalias-attributes-support-1-fix-git-kbuild-fix.patch add-address_space_operationsbatch_write.patch add-address_space_operationsbatch_write-fix.patch alloc_fdtable-cleanup.patch revert-pcmcia-make-ide_cs-work-with-the-memory-space-of-cf-cards-if-io-space-is-not-available.patch del_timer_sync-add-cpu_relax.patch rtc-subsystem-add-isl1208-support-tweaks.patch add-probe_kernel_address.patch x86-use-probe_kernel_address-in-handle_bug.patch kthread-convert-loopc-to-kthread-race-fix.patch kthread-convert-loopc-to-kthread-race-fix-fix.patch reiserfs-on-demand-bitmap-loading.patch per-task-delay-accounting-taskstats-interface.patch per-task-delay-accounting-taskstats-interface-fix.patch per-task-delay-accounting-proc-export-of-aggregated-block-i-o-delays.patch delay-accounting-taskstats-interface-send-tgid-once.patch per-task-delay-accounting-taskstats-interface-control-exit-data-through-cpumasks-fix.patch task-watchers-task-watchers.patch task-watchers-add-support-for-per-task-watchers.patch swap_prefetch-vs-zoned-counters.patch ecryptfs-mmap-operations.patch ecryptfs-alpha-build-fix.patch ecryptfs-more-elegant-aes-key-size-manipulation.patch ecryptfs-get_sb_dev-fix.patch namespaces-add-nsproxy-dont-include-compileh.patch namespaces-utsname-switch-to-using-uts-namespaces.patch namespaces-utsname-use-init_utsname-when-appropriate.patch namespaces-utsname-implement-utsname-namespaces.patch namespaces-utsname-sysctl-hack.patch ipc-namespace-core.patch readahead-sysctl-parameters-fix.patch make-copy_from_user_inatomic-not-zero-the-tail-on-i386-vs-reiser4.patch reiser4-hardirq-include-fix.patch reiser4-run-truncate_inode_pages-in-reiser4_delete_inode.patch reiser4-get_sb_dev-fix.patch reiser4-vs-zoned-allocator.patch hpt3xx-rework-rate-filtering-tidy.patch genirq-convert-the-i386-architecture-to-irq-chips.patch genirq-x86_64-irq-reenable-migrating-irqs-to-other-cpus.patch genirq-msi-simplify-msi-enable-and-disable.patch genirq-ia64-irq-dynamic-irq-support.patch genirq-msi-only-build-msi-apicc-on-ia64-fix.patch genirq-i386-irq-remove-the-msi-assumption-that-irq-==-vector.patch add-hypertransport-capability-defines-fix.patch nr_blockdev_pages-in_interrupt-warning.patch device-suspend-debug.patch revert-tty-buffering-comment-out-debug-code.patch slab-leaks3-default-y.patch x86-kmap_atomic-debugging.patch jmicron-warning-fix.patch blockdevc-check-errors.patch drivers-base-check-errors.patch - To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html