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

Merge tag 'driver-core-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core

Pull driver core updates from Greg KH:
"Here is the "big" set of driver core patches for 4.21-rc1.

It's not really big, just a number of small changes for some reported
issues, some documentation updates to hopefully make it harder for
people to abuse the driver model, and some other minor cleanups.

All of these have been in linux-next for a while with no reported
issues"

* tag 'driver-core-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core:
mm, memory_hotplug: update a comment in unregister_memory()
component: convert to DEFINE_SHOW_ATTRIBUTE
sysfs: Disable lockdep for driver bind/unbind files
driver core: Add missing dev->bus->need_parent_lock checks
kobject: return error code if writing /sys/.../uevent fails
driver core: Move async_synchronize_full call
driver core: platform: Respect return code of platform_device_register_full()
kref/kobject: Improve documentation
drivers/base/memory.c: Use DEVICE_ATTR_RO and friends
driver core: Replace simple_strto{l,ul} by kstrtou{l,ul}
kernfs: Improve kernfs_notify() poll notification latency
kobject: Fix warnings in lib/kobject_uevent.c
kobject: drop unnecessary cast "%llu" for u64
driver core: fix comments for device_block_probing()
driver core: Replace simple_strtol by kstrtoint

+113 -104
+7 -3
Documentation/kobject.txt
··· 279 279 One important point cannot be overstated: every kobject must have a 280 280 release() method, and the kobject must persist (in a consistent state) 281 281 until that method is called. If these constraints are not met, the code is 282 - flawed. Note that the kernel will warn you if you forget to provide a 282 + flawed. Note that the kernel will warn you if you forget to provide a 283 283 release() method. Do not try to get rid of this warning by providing an 284 - "empty" release function; you will be mocked mercilessly by the kobject 285 - maintainer if you attempt this. 284 + "empty" release function. 285 + 286 + If all your cleanup function needs to do is call kfree(), then you must 287 + create a wrapper function which uses container_of() to upcast to the correct 288 + type (as shown in the example above) and then calls kfree() on the overall 289 + structure. 286 290 287 291 Note, the name of the kobject is available in the release function, but it 288 292 must NOT be changed within this callback. Otherwise there will be a memory
+13 -6
drivers/base/bus.c
··· 31 31 32 32 #define to_drv_attr(_attr) container_of(_attr, struct driver_attribute, attr) 33 33 34 + #define DRIVER_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \ 35 + struct driver_attribute driver_attr_##_name = \ 36 + __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) 34 37 35 38 static int __must_check bus_rescan_devices_helper(struct device *dev, 36 39 void *data); ··· 198 195 bus_put(bus); 199 196 return err; 200 197 } 201 - static DRIVER_ATTR_WO(unbind); 198 + static DRIVER_ATTR_IGNORE_LOCKDEP(unbind, S_IWUSR, NULL, unbind_store); 202 199 203 200 /* 204 201 * Manually attach a device to a driver. ··· 234 231 bus_put(bus); 235 232 return err; 236 233 } 237 - static DRIVER_ATTR_WO(bind); 234 + static DRIVER_ATTR_IGNORE_LOCKDEP(bind, S_IWUSR, NULL, bind_store); 238 235 239 236 static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf) 240 237 { ··· 614 611 static ssize_t uevent_store(struct device_driver *drv, const char *buf, 615 612 size_t count) 616 613 { 617 - kobject_synth_uevent(&drv->p->kobj, buf, count); 618 - return count; 614 + int rc; 615 + 616 + rc = kobject_synth_uevent(&drv->p->kobj, buf, count); 617 + return rc ? rc : count; 619 618 } 620 619 static DRIVER_ATTR_WO(uevent); 621 620 ··· 833 828 static ssize_t bus_uevent_store(struct bus_type *bus, 834 829 const char *buf, size_t count) 835 830 { 836 - kobject_synth_uevent(&bus->p->subsys.kobj, buf, count); 837 - return count; 831 + int rc; 832 + 833 + rc = kobject_synth_uevent(&bus->p->subsys.kobj, buf, count); 834 + return rc ? rc : count; 838 835 } 839 836 static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store); 840 837
+1 -11
drivers/base/component.c
··· 85 85 return 0; 86 86 } 87 87 88 - static int component_devices_open(struct inode *inode, struct file *file) 89 - { 90 - return single_open(file, component_devices_show, inode->i_private); 91 - } 92 - 93 - static const struct file_operations component_devices_fops = { 94 - .open = component_devices_open, 95 - .read = seq_read, 96 - .llseek = seq_lseek, 97 - .release = single_release, 98 - }; 88 + DEFINE_SHOW_ATTRIBUTE(component_devices); 99 89 100 90 static int __init component_debug_init(void) 101 91 {
+22 -10
drivers/base/core.c
··· 815 815 const char *buf, size_t size) 816 816 { 817 817 struct dev_ext_attribute *ea = to_ext_attr(attr); 818 - char *end; 819 - unsigned long new = simple_strtoul(buf, &end, 0); 820 - if (end == buf) 821 - return -EINVAL; 818 + int ret; 819 + unsigned long new; 820 + 821 + ret = kstrtoul(buf, 0, &new); 822 + if (ret) 823 + return ret; 822 824 *(unsigned long *)(ea->var) = new; 823 825 /* Always return full write size even if we didn't consume all */ 824 826 return size; ··· 841 839 const char *buf, size_t size) 842 840 { 843 841 struct dev_ext_attribute *ea = to_ext_attr(attr); 844 - char *end; 845 - long new = simple_strtol(buf, &end, 0); 846 - if (end == buf || new > INT_MAX || new < INT_MIN) 842 + int ret; 843 + long new; 844 + 845 + ret = kstrtol(buf, 0, &new); 846 + if (ret) 847 + return ret; 848 + 849 + if (new > INT_MAX || new < INT_MIN) 847 850 return -EINVAL; 848 851 *(int *)(ea->var) = new; 849 852 /* Always return full write size even if we didn't consume all */ ··· 918 911 else if (dev->class && dev->class->dev_release) 919 912 dev->class->dev_release(dev); 920 913 else 921 - WARN(1, KERN_ERR "Device '%s' does not have a release() " 922 - "function, it is broken and must be fixed.\n", 914 + WARN(1, KERN_ERR "Device '%s' does not have a release() function, it is broken and must be fixed. See Documentation/kobject.txt.\n", 923 915 dev_name(dev)); 924 916 kfree(p); 925 917 } ··· 1094 1088 static ssize_t uevent_store(struct device *dev, struct device_attribute *attr, 1095 1089 const char *buf, size_t count) 1096 1090 { 1097 - if (kobject_synth_uevent(&dev->kobj, buf, count)) 1091 + int rc; 1092 + 1093 + rc = kobject_synth_uevent(&dev->kobj, buf, count); 1094 + 1095 + if (rc) { 1098 1096 dev_err(dev, "uevent: failed to send synthetic uevent\n"); 1097 + return rc; 1098 + } 1099 1099 1100 1100 return count; 1101 1101 }
+11 -8
drivers/base/dd.c
··· 179 179 } 180 180 181 181 /** 182 - * device_block_probing() - Block/defere device's probes 182 + * device_block_probing() - Block/defer device's probes 183 183 * 184 184 * It will disable probing of devices and defer their probes instead. 185 185 */ ··· 223 223 static int deferred_probe_timeout = -1; 224 224 static int __init deferred_probe_timeout_setup(char *str) 225 225 { 226 - deferred_probe_timeout = simple_strtol(str, NULL, 10); 226 + int timeout; 227 + 228 + if (!kstrtoint(str, 10, &timeout)) 229 + deferred_probe_timeout = timeout; 227 230 return 1; 228 231 } 229 232 __setup("deferred_probe_timeout=", deferred_probe_timeout_setup); ··· 456 453 if (defer_all_probes) { 457 454 /* 458 455 * Value of defer_all_probes can be set only by 459 - * device_defer_all_probes_enable() which, in turn, will call 456 + * device_block_probing() which, in turn, will call 460 457 * wait_for_device_probe() right after that to avoid any races. 461 458 */ 462 459 dev_dbg(dev, "Driver %s force probe deferral\n", drv->name); ··· 931 928 932 929 drv = dev->driver; 933 930 if (drv) { 934 - if (driver_allows_async_probing(drv)) 935 - async_synchronize_full(); 936 - 937 931 while (device_links_busy(dev)) { 938 932 device_unlock(dev); 939 - if (parent) 933 + if (parent && dev->bus->need_parent_lock) 940 934 device_unlock(parent); 941 935 942 936 device_links_unbind_consumers(dev); 943 - if (parent) 937 + if (parent && dev->bus->need_parent_lock) 944 938 device_lock(parent); 945 939 946 940 device_lock(dev); ··· 1035 1035 { 1036 1036 struct device_private *dev_prv; 1037 1037 struct device *dev; 1038 + 1039 + if (driver_allows_async_probing(drv)) 1040 + async_synchronize_full(); 1038 1041 1039 1042 for (;;) { 1040 1043 spin_lock(&drv->p->klist_devices.k_lock);
+37 -44
drivers/base/memory.c
··· 109 109 * uses. 110 110 */ 111 111 112 - static ssize_t show_mem_start_phys_index(struct device *dev, 113 - struct device_attribute *attr, char *buf) 112 + static ssize_t phys_index_show(struct device *dev, 113 + struct device_attribute *attr, char *buf) 114 114 { 115 115 struct memory_block *mem = to_memory_block(dev); 116 116 unsigned long phys_index; ··· 122 122 /* 123 123 * Show whether the section of memory is likely to be hot-removable 124 124 */ 125 - static ssize_t show_mem_removable(struct device *dev, 126 - struct device_attribute *attr, char *buf) 125 + static ssize_t removable_show(struct device *dev, struct device_attribute *attr, 126 + char *buf) 127 127 { 128 128 unsigned long i, pfn; 129 129 int ret = 1; ··· 146 146 /* 147 147 * online, offline, going offline, etc. 148 148 */ 149 - static ssize_t show_mem_state(struct device *dev, 150 - struct device_attribute *attr, char *buf) 149 + static ssize_t state_show(struct device *dev, struct device_attribute *attr, 150 + char *buf) 151 151 { 152 152 struct memory_block *mem = to_memory_block(dev); 153 153 ssize_t len = 0; ··· 286 286 return 0; 287 287 288 288 /* 289 - * If we are called from store_mem_state(), online_type will be 289 + * If we are called from state_store(), online_type will be 290 290 * set >= 0 Otherwise we were called from the device online 291 291 * attribute and need to set the online_type. 292 292 */ ··· 315 315 return memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); 316 316 } 317 317 318 - static ssize_t 319 - store_mem_state(struct device *dev, 320 - struct device_attribute *attr, const char *buf, size_t count) 318 + static ssize_t state_store(struct device *dev, struct device_attribute *attr, 319 + const char *buf, size_t count) 321 320 { 322 321 struct memory_block *mem = to_memory_block(dev); 323 322 int ret, online_type; ··· 373 374 * s.t. if I offline all of these sections I can then 374 375 * remove the physical device? 375 376 */ 376 - static ssize_t show_phys_device(struct device *dev, 377 + static ssize_t phys_device_show(struct device *dev, 377 378 struct device_attribute *attr, char *buf) 378 379 { 379 380 struct memory_block *mem = to_memory_block(dev); ··· 394 395 } 395 396 } 396 397 397 - static ssize_t show_valid_zones(struct device *dev, 398 + static ssize_t valid_zones_show(struct device *dev, 398 399 struct device_attribute *attr, char *buf) 399 400 { 400 401 struct memory_block *mem = to_memory_block(dev); ··· 434 435 435 436 return strlen(buf); 436 437 } 437 - static DEVICE_ATTR(valid_zones, 0444, show_valid_zones, NULL); 438 + static DEVICE_ATTR_RO(valid_zones); 438 439 #endif 439 440 440 - static DEVICE_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL); 441 - static DEVICE_ATTR(state, 0644, show_mem_state, store_mem_state); 442 - static DEVICE_ATTR(phys_device, 0444, show_phys_device, NULL); 443 - static DEVICE_ATTR(removable, 0444, show_mem_removable, NULL); 441 + static DEVICE_ATTR_RO(phys_index); 442 + static DEVICE_ATTR_RW(state); 443 + static DEVICE_ATTR_RO(phys_device); 444 + static DEVICE_ATTR_RO(removable); 444 445 445 446 /* 446 447 * Block size attribute stuff 447 448 */ 448 - static ssize_t 449 - print_block_size(struct device *dev, struct device_attribute *attr, 450 - char *buf) 449 + static ssize_t block_size_bytes_show(struct device *dev, 450 + struct device_attribute *attr, char *buf) 451 451 { 452 452 return sprintf(buf, "%lx\n", get_memory_block_size()); 453 453 } 454 454 455 - static DEVICE_ATTR(block_size_bytes, 0444, print_block_size, NULL); 455 + static DEVICE_ATTR_RO(block_size_bytes); 456 456 457 457 /* 458 458 * Memory auto online policy. 459 459 */ 460 460 461 - static ssize_t 462 - show_auto_online_blocks(struct device *dev, struct device_attribute *attr, 463 - char *buf) 461 + static ssize_t auto_online_blocks_show(struct device *dev, 462 + struct device_attribute *attr, char *buf) 464 463 { 465 464 if (memhp_auto_online) 466 465 return sprintf(buf, "online\n"); ··· 466 469 return sprintf(buf, "offline\n"); 467 470 } 468 471 469 - static ssize_t 470 - store_auto_online_blocks(struct device *dev, struct device_attribute *attr, 471 - const char *buf, size_t count) 472 + static ssize_t auto_online_blocks_store(struct device *dev, 473 + struct device_attribute *attr, 474 + const char *buf, size_t count) 472 475 { 473 476 if (sysfs_streq(buf, "online")) 474 477 memhp_auto_online = true; ··· 480 483 return count; 481 484 } 482 485 483 - static DEVICE_ATTR(auto_online_blocks, 0644, show_auto_online_blocks, 484 - store_auto_online_blocks); 486 + static DEVICE_ATTR_RW(auto_online_blocks); 485 487 486 488 /* 487 489 * Some architectures will have custom drivers to do this, and ··· 489 493 * and will require this interface. 490 494 */ 491 495 #ifdef CONFIG_ARCH_MEMORY_PROBE 492 - static ssize_t 493 - memory_probe_store(struct device *dev, struct device_attribute *attr, 494 - const char *buf, size_t count) 496 + static ssize_t probe_store(struct device *dev, struct device_attribute *attr, 497 + const char *buf, size_t count) 495 498 { 496 499 u64 phys_addr; 497 500 int nid, ret; ··· 520 525 return ret; 521 526 } 522 527 523 - static DEVICE_ATTR(probe, S_IWUSR, NULL, memory_probe_store); 528 + static DEVICE_ATTR_WO(probe); 524 529 #endif 525 530 526 531 #ifdef CONFIG_MEMORY_FAILURE ··· 529 534 */ 530 535 531 536 /* Soft offline a page */ 532 - static ssize_t 533 - store_soft_offline_page(struct device *dev, 534 - struct device_attribute *attr, 535 - const char *buf, size_t count) 537 + static ssize_t soft_offline_page_store(struct device *dev, 538 + struct device_attribute *attr, 539 + const char *buf, size_t count) 536 540 { 537 541 int ret; 538 542 u64 pfn; ··· 547 553 } 548 554 549 555 /* Forcibly offline a page, including killing processes. */ 550 - static ssize_t 551 - store_hard_offline_page(struct device *dev, 552 - struct device_attribute *attr, 553 - const char *buf, size_t count) 556 + static ssize_t hard_offline_page_store(struct device *dev, 557 + struct device_attribute *attr, 558 + const char *buf, size_t count) 554 559 { 555 560 int ret; 556 561 u64 pfn; ··· 562 569 return ret ? ret : count; 563 570 } 564 571 565 - static DEVICE_ATTR(soft_offline_page, S_IWUSR, NULL, store_soft_offline_page); 566 - static DEVICE_ATTR(hard_offline_page, S_IWUSR, NULL, store_hard_offline_page); 572 + static DEVICE_ATTR_WO(soft_offline_page); 573 + static DEVICE_ATTR_WO(hard_offline_page); 567 574 #endif 568 575 569 576 /* ··· 732 739 { 733 740 BUG_ON(memory->dev.bus != &memory_subsys); 734 741 735 - /* drop the ref. we got in remove_memory_block() */ 742 + /* drop the ref. we got in remove_memory_section() */ 736 743 put_device(&memory->dev); 737 744 device_unregister(&memory->dev); 738 745 }
+2 -2
drivers/base/platform.c
··· 234 234 */ 235 235 void platform_device_put(struct platform_device *pdev) 236 236 { 237 - if (pdev) 237 + if (!IS_ERR_OR_NULL(pdev)) 238 238 put_device(&pdev->dev); 239 239 } 240 240 EXPORT_SYMBOL_GPL(platform_device_put); ··· 447 447 { 448 448 int i; 449 449 450 - if (pdev) { 450 + if (!IS_ERR_OR_NULL(pdev)) { 451 451 device_del(&pdev->dev); 452 452 453 453 if (pdev->id_auto) {
+11 -12
fs/kernfs/file.c
··· 857 857 static void kernfs_notify_workfn(struct work_struct *work) 858 858 { 859 859 struct kernfs_node *kn; 860 - struct kernfs_open_node *on; 861 860 struct kernfs_super_info *info; 862 861 repeat: 863 862 /* pop one off the notify_list */ ··· 869 870 kernfs_notify_list = kn->attr.notify_next; 870 871 kn->attr.notify_next = NULL; 871 872 spin_unlock_irq(&kernfs_notify_lock); 872 - 873 - /* kick poll */ 874 - spin_lock_irq(&kernfs_open_node_lock); 875 - 876 - on = kn->attr.open; 877 - if (on) { 878 - atomic_inc(&on->event); 879 - wake_up_interruptible(&on->poll); 880 - } 881 - 882 - spin_unlock_irq(&kernfs_open_node_lock); 883 873 884 874 /* kick fsnotify */ 885 875 mutex_lock(&kernfs_mutex); ··· 922 934 { 923 935 static DECLARE_WORK(kernfs_notify_work, kernfs_notify_workfn); 924 936 unsigned long flags; 937 + struct kernfs_open_node *on; 925 938 926 939 if (WARN_ON(kernfs_type(kn) != KERNFS_FILE)) 927 940 return; 928 941 942 + /* kick poll immediately */ 943 + spin_lock_irqsave(&kernfs_open_node_lock, flags); 944 + on = kn->attr.open; 945 + if (on) { 946 + atomic_inc(&on->event); 947 + wake_up_interruptible(&on->poll); 948 + } 949 + spin_unlock_irqrestore(&kernfs_open_node_lock, flags); 950 + 951 + /* schedule work to kick fsnotify */ 929 952 spin_lock_irqsave(&kernfs_notify_lock, flags); 930 953 if (!kn->attr.notify_next) { 931 954 kernfs_get(kn);
+1 -4
include/linux/kref.h
··· 53 53 * @release: pointer to the function that will clean up the object when the 54 54 * last reference to the object is released. 55 55 * This pointer is required, and it is not acceptable to pass kfree 56 - * in as this function. If the caller does pass kfree to this 57 - * function, you will be publicly mocked mercilessly by the kref 58 - * maintainer, and anyone else who happens to notice it. You have 59 - * been warned. 56 + * in as this function. 60 57 * 61 58 * Decrement the refcount, and if 0, call release(). 62 59 * Return 1 if the object was removed, otherwise return 0. Beware, if this
+4 -2
kernel/module.c
··· 1208 1208 struct module_kobject *mk, 1209 1209 const char *buffer, size_t count) 1210 1210 { 1211 - kobject_synth_uevent(&mk->kobj, buffer, count); 1212 - return count; 1211 + int rc; 1212 + 1213 + rc = kobject_synth_uevent(&mk->kobj, buffer, count); 1214 + return rc ? rc : count; 1213 1215 } 1214 1216 1215 1217 struct module_attribute module_uevent =
+1 -1
lib/kobject.c
··· 639 639 kobject_name(kobj), kobj, __func__, kobj->parent); 640 640 641 641 if (t && !t->release) 642 - pr_debug("kobject: '%s' (%p): does not have a release() function, it is broken and must be fixed.\n", 642 + pr_debug("kobject: '%s' (%p): does not have a release() function, it is broken and must be fixed. See Documentation/kobject.txt.\n", 643 643 kobject_name(kobj), kobj); 644 644 645 645 /* send "remove" if the caller did not do it but sent "add" */
+3 -1
lib/kobject_uevent.c
··· 240 240 ops = kobj_ns_ops(kobj); 241 241 if (ops) { 242 242 const void *init_ns, *ns; 243 + 243 244 ns = kobj->ktype->namespace(kobj); 244 245 init_ns = ops->initial_ns(); 245 246 return ns != init_ns; ··· 391 390 ops = kobj_ns_ops(kobj); 392 391 if (!ops && kobj->kset) { 393 392 struct kobject *ksobj = &kobj->kset->kobj; 393 + 394 394 if (ksobj->parent != NULL) 395 395 ops = kobj_ns_ops(ksobj->parent); 396 396 } ··· 581 579 582 580 mutex_lock(&uevent_sock_mutex); 583 581 /* we will send an event, so request a new sequence number */ 584 - retval = add_uevent_var(env, "SEQNUM=%llu", (unsigned long long)++uevent_seqnum); 582 + retval = add_uevent_var(env, "SEQNUM=%llu", ++uevent_seqnum); 585 583 if (retval) { 586 584 mutex_unlock(&uevent_sock_mutex); 587 585 goto exit;