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

Merge tag 'driver-core-6.9-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 and kernfs changes for 6.9-rc1.

Nothing all that crazy here, just some good updates that include:

- automatic attribute group hiding from Dan Williams (he fixed up my
horrible attempt at doing this.)

- kobject lock contention fixes from Eric Dumazet

- driver core cleanups from Andy

- kernfs rcu work from Tejun

- fw_devlink changes to resolve some reported issues

- other minor changes, all details in the shortlog

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

* tag 'driver-core-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (28 commits)
device: core: Log warning for devices pending deferred probe on timeout
driver: core: Use dev_* instead of pr_* so device metadata is added
driver: core: Log probe failure as error and with device metadata
of: property: fw_devlink: Add support for "post-init-providers" property
driver core: Add FWLINK_FLAG_IGNORE to completely ignore a fwnode link
driver core: Adds flags param to fwnode_link_add()
debugfs: fix wait/cancellation handling during remove
device property: Don't use "proxy" headers
device property: Move enum dev_dma_attr to fwnode.h
driver core: Move fw_devlink stuff to where it belongs
driver core: Drop unneeded 'extern' keyword in fwnode.h
firmware_loader: Suppress warning on FW_OPT_NO_WARN flag
sysfs:Addresses documentation in sysfs_merge_group and sysfs_unmerge_group.
firmware_loader: introduce __free() cleanup hanler
platform-msi: Remove usage of the deprecated ida_simple_xx() API
sysfs: Introduce DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE()
sysfs: Document new "group visible" helpers
sysfs: Fix crash on empty group attributes array
sysfs: Introduce a mechanism to hide static attribute_groups
sysfs: Introduce a mechanism to hide static attribute_groups
...

+387 -177
+2 -2
drivers/base/component.c
··· 751 751 * component_bind_all(). See also &struct component_ops. 752 752 * 753 753 * @subcomponent must be nonzero and is used to differentiate between multiple 754 - * components registerd on the same device @dev. These components are match 754 + * components registered on the same device @dev. These components are match 755 755 * using component_match_add_typed(). 756 756 * 757 757 * The component needs to be unregistered at driver unload/disconnect by ··· 781 781 * The component needs to be unregistered at driver unload/disconnect by 782 782 * calling component_del(). 783 783 * 784 - * See also component_add_typed() for a variant that allows multipled different 784 + * See also component_add_typed() for a variant that allows multiple different 785 785 * components on the same device. 786 786 */ 787 787 int component_add(struct device *dev, const struct component_ops *ops)
+69 -3
drivers/base/core.c
··· 92 92 return 0; 93 93 } 94 94 95 - int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup) 95 + int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup, 96 + u8 flags) 96 97 { 97 98 int ret; 98 99 99 100 mutex_lock(&fwnode_link_lock); 100 - ret = __fwnode_link_add(con, sup, 0); 101 + ret = __fwnode_link_add(con, sup, flags); 101 102 mutex_unlock(&fwnode_link_lock); 102 103 return ret; 103 104 } ··· 1012 1011 return NULL; 1013 1012 1014 1013 list_for_each_entry(link, &fwnode->suppliers, c_hook) 1015 - if (!(link->flags & FWLINK_FLAG_CYCLE)) 1014 + if (!(link->flags & 1015 + (FWLINK_FLAG_CYCLE | FWLINK_FLAG_IGNORE))) 1016 1016 return link->supplier; 1017 1017 1018 1018 return NULL; ··· 1873 1871 device_links_write_unlock(); 1874 1872 } 1875 1873 1874 + #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev) 1876 1875 1877 1876 static bool fwnode_init_without_drv(struct fwnode_handle *fwnode) 1878 1877 { ··· 1902 1899 } 1903 1900 1904 1901 return false; 1902 + } 1903 + 1904 + /** 1905 + * fwnode_is_ancestor_of - Test if @ancestor is ancestor of @child 1906 + * @ancestor: Firmware which is tested for being an ancestor 1907 + * @child: Firmware which is tested for being the child 1908 + * 1909 + * A node is considered an ancestor of itself too. 1910 + * 1911 + * Return: true if @ancestor is an ancestor of @child. Otherwise, returns false. 1912 + */ 1913 + static bool fwnode_is_ancestor_of(const struct fwnode_handle *ancestor, 1914 + const struct fwnode_handle *child) 1915 + { 1916 + struct fwnode_handle *parent; 1917 + 1918 + if (IS_ERR_OR_NULL(ancestor)) 1919 + return false; 1920 + 1921 + if (child == ancestor) 1922 + return true; 1923 + 1924 + fwnode_for_each_parent_node(child, parent) { 1925 + if (parent == ancestor) { 1926 + fwnode_handle_put(parent); 1927 + return true; 1928 + } 1929 + } 1930 + return false; 1931 + } 1932 + 1933 + /** 1934 + * fwnode_get_next_parent_dev - Find device of closest ancestor fwnode 1935 + * @fwnode: firmware node 1936 + * 1937 + * Given a firmware node (@fwnode), this function finds its closest ancestor 1938 + * firmware node that has a corresponding struct device and returns that struct 1939 + * device. 1940 + * 1941 + * The caller is responsible for calling put_device() on the returned device 1942 + * pointer. 1943 + * 1944 + * Return: a pointer to the device of the @fwnode's closest ancestor. 1945 + */ 1946 + static struct device *fwnode_get_next_parent_dev(const struct fwnode_handle *fwnode) 1947 + { 1948 + struct fwnode_handle *parent; 1949 + struct device *dev; 1950 + 1951 + fwnode_for_each_parent_node(fwnode, parent) { 1952 + dev = get_dev_from_fwnode(parent); 1953 + if (dev) { 1954 + fwnode_handle_put(parent); 1955 + return dev; 1956 + } 1957 + } 1958 + return NULL; 1905 1959 } 1906 1960 1907 1961 /** ··· 2022 1962 } 2023 1963 2024 1964 list_for_each_entry(link, &sup_handle->suppliers, c_hook) { 1965 + if (link->flags & FWLINK_FLAG_IGNORE) 1966 + continue; 1967 + 2025 1968 if (__fw_devlink_relax_cycles(con, link->supplier)) { 2026 1969 __fwnode_link_cycle(link); 2027 1970 ret = true; ··· 2102 2039 struct device *sup_dev; 2103 2040 int ret = 0; 2104 2041 u32 flags; 2042 + 2043 + if (link->flags & FWLINK_FLAG_IGNORE) 2044 + return 0; 2105 2045 2106 2046 if (con->fwnode == link->consumer) 2107 2047 flags = fw_devlink_get_flags(link->flags);
+1 -1
drivers/base/cpu.c
··· 366 366 } 367 367 #endif 368 368 369 - struct bus_type cpu_subsys = { 369 + const struct bus_type cpu_subsys = { 370 370 .name = "cpu", 371 371 .dev_name = "cpu", 372 372 .match = cpu_subsys_match,
+15 -17
drivers/base/dd.c
··· 313 313 314 314 mutex_lock(&deferred_probe_mutex); 315 315 list_for_each_entry(p, &deferred_probe_pending_list, deferred_probe) 316 - dev_info(p->device, "deferred probe pending: %s", p->deferred_probe_reason ?: "(reason unknown)\n"); 316 + dev_warn(p->device, "deferred probe pending: %s", p->deferred_probe_reason ?: "(reason unknown)\n"); 317 317 mutex_unlock(&deferred_probe_mutex); 318 318 319 319 fw_devlink_probing_done(); ··· 397 397 static void driver_bound(struct device *dev) 398 398 { 399 399 if (device_is_bound(dev)) { 400 - pr_warn("%s: device %s already bound\n", 401 - __func__, kobject_name(&dev->kobj)); 400 + dev_warn(dev, "%s: device already bound\n", __func__); 402 401 return; 403 402 } 404 403 405 - pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->driver->name, 406 - __func__, dev_name(dev)); 404 + dev_dbg(dev, "driver: '%s': %s: bound to device\n", dev->driver->name, 405 + __func__); 407 406 408 407 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices); 409 408 device_links_driver_bound(dev); ··· 586 587 break; 587 588 case -ENODEV: 588 589 case -ENXIO: 589 - pr_debug("%s: probe of %s rejects match %d\n", 590 - drv->name, dev_name(dev), ret); 590 + dev_dbg(dev, "probe with driver %s rejects match %d\n", 591 + drv->name, ret); 591 592 break; 592 593 default: 593 594 /* driver matched but the probe failed */ 594 - pr_warn("%s: probe of %s failed with error %d\n", 595 - drv->name, dev_name(dev), ret); 595 + dev_err(dev, "probe with driver %s failed with error %d\n", 596 + drv->name, ret); 596 597 break; 597 598 } 598 599 ··· 619 620 if (link_ret == -EPROBE_DEFER) 620 621 return link_ret; 621 622 622 - pr_debug("bus: '%s': %s: probing driver %s with device %s\n", 623 - drv->bus->name, __func__, drv->name, dev_name(dev)); 623 + dev_dbg(dev, "bus: '%s': %s: probing driver %s with device\n", 624 + drv->bus->name, __func__, drv->name); 624 625 if (!list_empty(&dev->devres_head)) { 625 626 dev_crit(dev, "Resources present before probing\n"); 626 627 ret = -EBUSY; ··· 643 644 644 645 ret = driver_sysfs_add(dev); 645 646 if (ret) { 646 - pr_err("%s: driver_sysfs_add(%s) failed\n", 647 - __func__, dev_name(dev)); 647 + dev_err(dev, "%s: driver_sysfs_add failed\n", __func__); 648 648 goto sysfs_failed; 649 649 } 650 650 ··· 704 706 dev->pm_domain->sync(dev); 705 707 706 708 driver_bound(dev); 707 - pr_debug("bus: '%s': %s: bound device %s to driver %s\n", 708 - drv->bus->name, __func__, dev_name(dev), drv->name); 709 + dev_dbg(dev, "bus: '%s': %s: bound device to driver %s\n", 710 + drv->bus->name, __func__, drv->name); 709 711 goto done; 710 712 711 713 dev_sysfs_state_synced_failed: ··· 784 786 return -EBUSY; 785 787 786 788 dev->can_match = true; 787 - pr_debug("bus: '%s': %s: matched device %s with driver %s\n", 788 - drv->bus->name, __func__, dev_name(dev), drv->name); 789 + dev_dbg(dev, "bus: '%s': %s: matched device with driver %s\n", 790 + drv->bus->name, __func__, drv->name); 789 791 790 792 pm_runtime_get_suppliers(dev); 791 793 if (dev->parent)
+10 -6
drivers/base/firmware_loader/main.c
··· 551 551 file_size_ptr, 552 552 READING_FIRMWARE); 553 553 if (rc < 0) { 554 - if (rc != -ENOENT) 555 - dev_warn(device, "loading %s failed with error %d\n", 556 - path, rc); 557 - else 558 - dev_dbg(device, "loading %s failed for no such file or directory.\n", 559 - path); 554 + if (!(fw_priv->opt_flags & FW_OPT_NO_WARN)) { 555 + if (rc != -ENOENT) 556 + dev_warn(device, 557 + "loading %s failed with error %d\n", 558 + path, rc); 559 + else 560 + dev_dbg(device, 561 + "loading %s failed for no such file or directory.\n", 562 + path); 563 + } 560 564 continue; 561 565 } 562 566 size = rc;
+3 -3
drivers/base/platform-msi.c
··· 174 174 if (!datap) 175 175 return -ENOMEM; 176 176 177 - datap->devid = ida_simple_get(&platform_msi_devid_ida, 178 - 0, 1 << DEV_ID_SHIFT, GFP_KERNEL); 177 + datap->devid = ida_alloc_max(&platform_msi_devid_ida, 178 + (1 << DEV_ID_SHIFT) - 1, GFP_KERNEL); 179 179 if (datap->devid < 0) { 180 180 err = datap->devid; 181 181 kfree(datap); ··· 193 193 struct platform_msi_priv_data *data = dev->msi.data->platform_data; 194 194 195 195 dev->msi.data->platform_data = NULL; 196 - ida_simple_remove(&platform_msi_devid_ida, data->devid); 196 + ida_free(&platform_msi_devid_ida, data->devid); 197 197 kfree(data); 198 198 } 199 199
+6 -61
drivers/base/property.c
··· 7 7 * Mika Westerberg <mika.westerberg@linux.intel.com> 8 8 */ 9 9 10 - #include <linux/acpi.h> 10 + #include <linux/device.h> 11 + #include <linux/err.h> 11 12 #include <linux/export.h> 12 - #include <linux/kernel.h> 13 + #include <linux/kconfig.h> 13 14 #include <linux/of.h> 14 - #include <linux/of_address.h> 15 - #include <linux/of_graph.h> 16 - #include <linux/of_irq.h> 17 15 #include <linux/property.h> 18 16 #include <linux/phy.h> 17 + #include <linux/slab.h> 18 + #include <linux/string.h> 19 + #include <linux/types.h> 19 20 20 21 struct fwnode_handle *__dev_fwnode(struct device *dev) 21 22 { ··· 701 700 EXPORT_SYMBOL_GPL(fwnode_get_next_parent); 702 701 703 702 /** 704 - * fwnode_get_next_parent_dev - Find device of closest ancestor fwnode 705 - * @fwnode: firmware node 706 - * 707 - * Given a firmware node (@fwnode), this function finds its closest ancestor 708 - * firmware node that has a corresponding struct device and returns that struct 709 - * device. 710 - * 711 - * The caller is responsible for calling put_device() on the returned device 712 - * pointer. 713 - * 714 - * Return: a pointer to the device of the @fwnode's closest ancestor. 715 - */ 716 - struct device *fwnode_get_next_parent_dev(const struct fwnode_handle *fwnode) 717 - { 718 - struct fwnode_handle *parent; 719 - struct device *dev; 720 - 721 - fwnode_for_each_parent_node(fwnode, parent) { 722 - dev = get_dev_from_fwnode(parent); 723 - if (dev) { 724 - fwnode_handle_put(parent); 725 - return dev; 726 - } 727 - } 728 - return NULL; 729 - } 730 - 731 - /** 732 703 * fwnode_count_parents - Return the number of parents a node has 733 704 * @fwnode: The node the parents of which are to be counted 734 705 * ··· 745 772 return NULL; 746 773 } 747 774 EXPORT_SYMBOL_GPL(fwnode_get_nth_parent); 748 - 749 - /** 750 - * fwnode_is_ancestor_of - Test if @ancestor is ancestor of @child 751 - * @ancestor: Firmware which is tested for being an ancestor 752 - * @child: Firmware which is tested for being the child 753 - * 754 - * A node is considered an ancestor of itself too. 755 - * 756 - * Return: true if @ancestor is an ancestor of @child. Otherwise, returns false. 757 - */ 758 - bool fwnode_is_ancestor_of(const struct fwnode_handle *ancestor, const struct fwnode_handle *child) 759 - { 760 - struct fwnode_handle *parent; 761 - 762 - if (IS_ERR_OR_NULL(ancestor)) 763 - return false; 764 - 765 - if (child == ancestor) 766 - return true; 767 - 768 - fwnode_for_each_parent_node(child, parent) { 769 - if (parent == ancestor) { 770 - fwnode_handle_put(parent); 771 - return true; 772 - } 773 - } 774 - return false; 775 - } 776 775 777 776 /** 778 777 * fwnode_get_next_child_node - Return the next child node handle for a node
+12 -1
drivers/base/swnode.c
··· 6 6 * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com> 7 7 */ 8 8 9 + #include <linux/container_of.h> 9 10 #include <linux/device.h> 10 - #include <linux/kernel.h> 11 + #include <linux/err.h> 12 + #include <linux/export.h> 13 + #include <linux/idr.h> 14 + #include <linux/init.h> 15 + #include <linux/kobject.h> 16 + #include <linux/kstrtox.h> 17 + #include <linux/list.h> 11 18 #include <linux/property.h> 12 19 #include <linux/slab.h> 20 + #include <linux/spinlock.h> 21 + #include <linux/string.h> 22 + #include <linux/sysfs.h> 23 + #include <linux/types.h> 13 24 14 25 #include "base.h" 15 26
+1 -1
drivers/firmware/efi/sysfb_efi.c
··· 336 336 if (!sup_np) 337 337 return 0; 338 338 339 - fwnode_link_add(fwnode, of_fwnode_handle(sup_np)); 339 + fwnode_link_add(fwnode, of_fwnode_handle(sup_np), 0); 340 340 of_node_put(sup_np); 341 341 342 342 return 0;
+12 -3
drivers/of/property.c
··· 1072 1072 } 1073 1073 1074 1074 static void of_link_to_phandle(struct device_node *con_np, 1075 - struct device_node *sup_np) 1075 + struct device_node *sup_np, 1076 + u8 flags) 1076 1077 { 1077 1078 struct device_node *tmp_np = of_node_get(sup_np); 1078 1079 ··· 1092 1091 tmp_np = of_get_next_parent(tmp_np); 1093 1092 } 1094 1093 1095 - fwnode_link_add(of_fwnode_handle(con_np), of_fwnode_handle(sup_np)); 1094 + fwnode_link_add(of_fwnode_handle(con_np), of_fwnode_handle(sup_np), flags); 1096 1095 } 1097 1096 1098 1097 /** ··· 1205 1204 * to a struct device, implement this ops so fw_devlink can use it 1206 1205 * to find the true consumer. 1207 1206 * @optional: Describes whether a supplier is mandatory or not 1207 + * @fwlink_flags: Optional fwnode link flags to use when creating a fwnode link 1208 + * for this property. 1208 1209 * 1209 1210 * Returns: 1210 1211 * parse_prop() return values are ··· 1219 1216 const char *prop_name, int index); 1220 1217 struct device_node *(*get_con_dev)(struct device_node *np); 1221 1218 bool optional; 1219 + u8 fwlink_flags; 1222 1220 }; 1223 1221 1224 1222 DEFINE_SIMPLE_PROP(clocks, "clocks", "#clock-cells") ··· 1251 1247 DEFINE_SIMPLE_PROP(backlight, "backlight", NULL) 1252 1248 DEFINE_SIMPLE_PROP(panel, "panel", NULL) 1253 1249 DEFINE_SIMPLE_PROP(msi_parent, "msi-parent", "#msi-cells") 1250 + DEFINE_SIMPLE_PROP(post_init_providers, "post-init-providers", NULL) 1254 1251 DEFINE_SUFFIX_PROP(regulators, "-supply", NULL) 1255 1252 DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells") 1256 1253 ··· 1362 1357 { .parse_prop = parse_regulators, }, 1363 1358 { .parse_prop = parse_gpio, }, 1364 1359 { .parse_prop = parse_gpios, }, 1360 + { 1361 + .parse_prop = parse_post_init_providers, 1362 + .fwlink_flags = FWLINK_FLAG_IGNORE, 1363 + }, 1365 1364 {} 1366 1365 }; 1367 1366 ··· 1410 1401 : of_node_get(con_np); 1411 1402 matched = true; 1412 1403 i++; 1413 - of_link_to_phandle(con_dev_np, phandle); 1404 + of_link_to_phandle(con_dev_np, phandle, s->fwlink_flags); 1414 1405 of_node_put(phandle); 1415 1406 of_node_put(con_dev_np); 1416 1407 }
+20 -5
fs/debugfs/inode.c
··· 751 751 if ((unsigned long)fsd & DEBUGFS_FSDATA_IS_REAL_FOPS_BIT) 752 752 return; 753 753 754 - /* if we hit zero, just wait for all to finish */ 755 - if (!refcount_dec_and_test(&fsd->active_users)) { 756 - wait_for_completion(&fsd->active_users_drained); 754 + /* if this was the last reference, we're done */ 755 + if (refcount_dec_and_test(&fsd->active_users)) 757 756 return; 758 - } 759 757 760 - /* if we didn't hit zero, try to cancel any we can */ 758 + /* 759 + * If there's still a reference, the code that obtained it can 760 + * be in different states: 761 + * - The common case of not using cancellations, or already 762 + * after debugfs_leave_cancellation(), where we just need 763 + * to wait for debugfs_file_put() which signals the completion; 764 + * - inside a cancellation section, i.e. between 765 + * debugfs_enter_cancellation() and debugfs_leave_cancellation(), 766 + * in which case we need to trigger the ->cancel() function, 767 + * and then wait for debugfs_file_put() just like in the 768 + * previous case; 769 + * - before debugfs_enter_cancellation() (but obviously after 770 + * debugfs_file_get()), in which case we may not see the 771 + * cancellation in the list on the first round of the loop, 772 + * but debugfs_enter_cancellation() signals the completion 773 + * after adding it, so this code gets woken up to call the 774 + * ->cancel() function. 775 + */ 761 776 while (refcount_read(&fsd->active_users)) { 762 777 struct debugfs_cancellation *c; 763 778
+20 -11
fs/kernfs/dir.c
··· 529 529 } 530 530 EXPORT_SYMBOL_GPL(kernfs_get); 531 531 532 + static void kernfs_free_rcu(struct rcu_head *rcu) 533 + { 534 + struct kernfs_node *kn = container_of(rcu, struct kernfs_node, rcu); 535 + 536 + kfree_const(kn->name); 537 + 538 + if (kn->iattr) { 539 + simple_xattrs_free(&kn->iattr->xattrs, NULL); 540 + kmem_cache_free(kernfs_iattrs_cache, kn->iattr); 541 + } 542 + 543 + kmem_cache_free(kernfs_node_cache, kn); 544 + } 545 + 532 546 /** 533 547 * kernfs_put - put a reference count on a kernfs_node 534 548 * @kn: the target kernfs_node ··· 571 557 if (kernfs_type(kn) == KERNFS_LINK) 572 558 kernfs_put(kn->symlink.target_kn); 573 559 574 - kfree_const(kn->name); 575 - 576 - if (kn->iattr) { 577 - simple_xattrs_free(&kn->iattr->xattrs, NULL); 578 - kmem_cache_free(kernfs_iattrs_cache, kn->iattr); 579 - } 580 560 spin_lock(&kernfs_idr_lock); 581 561 idr_remove(&root->ino_idr, (u32)kernfs_ino(kn)); 582 562 spin_unlock(&kernfs_idr_lock); 583 - kmem_cache_free(kernfs_node_cache, kn); 563 + 564 + call_rcu(&kn->rcu, kernfs_free_rcu); 584 565 585 566 kn = parent; 586 567 if (kn) { ··· 584 575 } else { 585 576 /* just released the root kn, free @root too */ 586 577 idr_destroy(&root->ino_idr); 587 - kfree(root); 578 + kfree_rcu(root, rcu); 588 579 } 589 580 } 590 581 EXPORT_SYMBOL_GPL(kernfs_put); ··· 724 715 ino_t ino = kernfs_id_ino(id); 725 716 u32 gen = kernfs_id_gen(id); 726 717 727 - spin_lock(&kernfs_idr_lock); 718 + rcu_read_lock(); 728 719 729 720 kn = idr_find(&root->ino_idr, (u32)ino); 730 721 if (!kn) ··· 748 739 if (unlikely(!__kernfs_active(kn) || !atomic_inc_not_zero(&kn->count))) 749 740 goto err_unlock; 750 741 751 - spin_unlock(&kernfs_idr_lock); 742 + rcu_read_unlock(); 752 743 return kn; 753 744 err_unlock: 754 - spin_unlock(&kernfs_idr_lock); 745 + rcu_read_unlock(); 755 746 return NULL; 756 747 } 757 748
+5 -3
fs/kernfs/file.c
··· 483 483 goto out_put; 484 484 485 485 rc = 0; 486 - of->mmapped = true; 487 - of_on(of)->nr_mmapped++; 488 - of->vm_ops = vma->vm_ops; 486 + if (!of->mmapped) { 487 + of->mmapped = true; 488 + of_on(of)->nr_mmapped++; 489 + of->vm_ops = vma->vm_ops; 490 + } 489 491 vma->vm_ops = &kernfs_vm_ops; 490 492 out_put: 491 493 kernfs_put_active(of->kn);
+2
fs/kernfs/kernfs-internal.h
··· 49 49 struct rw_semaphore kernfs_rwsem; 50 50 struct rw_semaphore kernfs_iattr_rwsem; 51 51 struct rw_semaphore kernfs_supers_rwsem; 52 + 53 + struct rcu_head rcu; 52 54 }; 53 55 54 56 /* +1 to avoid triggering overflow warning when negating it */
+41 -14
fs/sysfs/group.c
··· 31 31 kernfs_remove_by_name(parent, (*bin_attr)->attr.name); 32 32 } 33 33 34 + static umode_t __first_visible(const struct attribute_group *grp, struct kobject *kobj) 35 + { 36 + if (grp->attrs && grp->attrs[0] && grp->is_visible) 37 + return grp->is_visible(kobj, grp->attrs[0], 0); 38 + 39 + if (grp->bin_attrs && grp->bin_attrs[0] && grp->is_bin_visible) 40 + return grp->is_bin_visible(kobj, grp->bin_attrs[0], 0); 41 + 42 + return 0; 43 + } 44 + 34 45 static int create_files(struct kernfs_node *parent, struct kobject *kobj, 35 46 kuid_t uid, kgid_t gid, 36 47 const struct attribute_group *grp, int update) ··· 63 52 kernfs_remove_by_name(parent, (*attr)->name); 64 53 if (grp->is_visible) { 65 54 mode = grp->is_visible(kobj, *attr, i); 55 + mode &= ~SYSFS_GROUP_INVISIBLE; 66 56 if (!mode) 67 57 continue; 68 58 } ··· 93 81 (*bin_attr)->attr.name); 94 82 if (grp->is_bin_visible) { 95 83 mode = grp->is_bin_visible(kobj, *bin_attr, i); 84 + mode &= ~SYSFS_GROUP_INVISIBLE; 96 85 if (!mode) 97 86 continue; 98 87 } ··· 140 127 141 128 kobject_get_ownership(kobj, &uid, &gid); 142 129 if (grp->name) { 130 + umode_t mode = __first_visible(grp, kobj); 131 + 132 + if (mode & SYSFS_GROUP_INVISIBLE) 133 + mode = 0; 134 + else 135 + mode = S_IRWXU | S_IRUGO | S_IXUGO; 136 + 143 137 if (update) { 144 138 kn = kernfs_find_and_get(kobj->sd, grp->name); 145 139 if (!kn) { 146 - pr_warn("Can't update unknown attr grp name: %s/%s\n", 147 - kobj->name, grp->name); 148 - return -EINVAL; 140 + pr_debug("attr grp %s/%s not created yet\n", 141 + kobj->name, grp->name); 142 + /* may have been invisible prior to this update */ 143 + update = 0; 144 + } else if (!mode) { 145 + sysfs_remove_group(kobj, grp); 146 + kernfs_put(kn); 147 + return 0; 149 148 } 150 - } else { 151 - kn = kernfs_create_dir_ns(kobj->sd, grp->name, 152 - S_IRWXU | S_IRUGO | S_IXUGO, 149 + } 150 + 151 + if (!update) { 152 + if (!mode) 153 + return 0; 154 + kn = kernfs_create_dir_ns(kobj->sd, grp->name, mode, 153 155 uid, gid, kobj, NULL); 154 156 if (IS_ERR(kn)) { 155 157 if (PTR_ERR(kn) == -EEXIST) ··· 307 279 if (grp->name) { 308 280 kn = kernfs_find_and_get(parent, grp->name); 309 281 if (!kn) { 310 - WARN(!kn, KERN_WARNING 311 - "sysfs group '%s' not found for kobject '%s'\n", 312 - grp->name, kobject_name(kobj)); 282 + pr_debug("sysfs group '%s' not found for kobject '%s'\n", 283 + grp->name, kobject_name(kobj)); 313 284 return; 314 285 } 315 286 } else { ··· 345 318 EXPORT_SYMBOL_GPL(sysfs_remove_groups); 346 319 347 320 /** 348 - * sysfs_merge_group - merge files into a pre-existing attribute group. 321 + * sysfs_merge_group - merge files into a pre-existing named attribute group. 349 322 * @kobj: The kobject containing the group. 350 323 * @grp: The files to create and the attribute group they belong to. 351 324 * 352 - * This function returns an error if the group doesn't exist or any of the 353 - * files already exist in that group, in which case none of the new files 354 - * are created. 325 + * This function returns an error if the group doesn't exist, the .name field is 326 + * NULL or any of the files already exist in that group, in which case none of 327 + * the new files are created. 355 328 */ 356 329 int sysfs_merge_group(struct kobject *kobj, 357 330 const struct attribute_group *grp) ··· 383 356 EXPORT_SYMBOL_GPL(sysfs_merge_group); 384 357 385 358 /** 386 - * sysfs_unmerge_group - remove files from a pre-existing attribute group. 359 + * sysfs_unmerge_group - remove files from a pre-existing named attribute group. 387 360 * @kobj: The kobject containing the group. 388 361 * @grp: The files to remove and the attribute group they belong to. 389 362 */
+1 -1
include/linux/cpu.h
··· 130 130 static inline int add_cpu(unsigned int cpu) { return 0;} 131 131 132 132 #endif /* CONFIG_SMP */ 133 - extern struct bus_type cpu_subsys; 133 + extern const struct bus_type cpu_subsys; 134 134 135 135 extern int lockdep_is_cpus_held(void); 136 136
+3
include/linux/firmware.h
··· 4 4 5 5 #include <linux/types.h> 6 6 #include <linux/compiler.h> 7 + #include <linux/cleanup.h> 7 8 #include <linux/gfp.h> 8 9 9 10 #define FW_ACTION_NOUEVENT 0 ··· 198 197 #endif 199 198 200 199 int firmware_request_cache(struct device *device, const char *name); 200 + 201 + DEFINE_FREE(firmware, struct firmware *, release_firmware(_T)) 201 202 202 203 #endif
+13 -5
include/linux/fwnode.h
··· 9 9 #ifndef _LINUX_FWNODE_H_ 10 10 #define _LINUX_FWNODE_H_ 11 11 12 - #include <linux/types.h> 13 - #include <linux/list.h> 14 12 #include <linux/bits.h> 15 13 #include <linux/err.h> 14 + #include <linux/list.h> 15 + #include <linux/types.h> 16 + 17 + enum dev_dma_attr { 18 + DEV_DMA_NOT_SUPPORTED, 19 + DEV_DMA_NON_COHERENT, 20 + DEV_DMA_COHERENT, 21 + }; 16 22 17 23 struct fwnode_operations; 18 24 struct device; ··· 59 53 * fwnode link flags 60 54 * 61 55 * CYCLE: The fwnode link is part of a cycle. Don't defer probe. 56 + * IGNORE: Completely ignore this link, even during cycle detection. 62 57 */ 63 58 #define FWLINK_FLAG_CYCLE BIT(0) 59 + #define FWLINK_FLAG_IGNORE BIT(1) 64 60 65 61 struct fwnode_link { 66 62 struct fwnode_handle *supplier; ··· 195 187 if (fwnode_has_op(fwnode, op)) \ 196 188 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \ 197 189 } while (false) 198 - #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev) 199 190 200 191 static inline void fwnode_init(struct fwnode_handle *fwnode, 201 192 const struct fwnode_operations *ops) ··· 216 209 fwnode->flags &= ~FWNODE_FLAG_INITIALIZED; 217 210 } 218 211 219 - extern bool fw_devlink_is_strict(void); 220 - int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup); 212 + int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup, 213 + u8 flags); 221 214 void fwnode_links_purge(struct fwnode_handle *fwnode); 222 215 void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode); 216 + bool fw_devlink_is_strict(void); 223 217 224 218 #endif
+6 -4
include/linux/kernfs.h
··· 206 206 207 207 const void *ns; /* namespace tag */ 208 208 unsigned int hash; /* ns + name hash */ 209 + unsigned short flags; 210 + umode_t mode; 211 + 209 212 union { 210 213 struct kernfs_elem_dir dir; 211 214 struct kernfs_elem_symlink symlink; 212 215 struct kernfs_elem_attr attr; 213 216 }; 214 - 215 - void *priv; 216 217 217 218 /* 218 219 * 64bit unique ID. On 64bit ino setups, id is the ino. On 32bit, ··· 221 220 */ 222 221 u64 id; 223 222 224 - unsigned short flags; 225 - umode_t mode; 223 + void *priv; 226 224 struct kernfs_iattrs *iattr; 225 + 226 + struct rcu_head rcu; 227 227 }; 228 228 229 229 /*
+1 -1
include/linux/kobject.h
··· 38 38 #endif 39 39 40 40 /* counter to tag the uevent, read only except for the kobject core */ 41 - extern u64 uevent_seqnum; 41 + extern atomic64_t uevent_seqnum; 42 42 43 43 /* 44 44 * The actions here must match the index to the string array
+1 -8
include/linux/property.h
··· 11 11 #define _LINUX_PROPERTY_H_ 12 12 13 13 #include <linux/args.h> 14 + #include <linux/array_size.h> 14 15 #include <linux/bits.h> 15 16 #include <linux/fwnode.h> 16 17 #include <linux/stddef.h> ··· 26 25 DEV_PROP_U64, 27 26 DEV_PROP_STRING, 28 27 DEV_PROP_REF, 29 - }; 30 - 31 - enum dev_dma_attr { 32 - DEV_DMA_NOT_SUPPORTED, 33 - DEV_DMA_NON_COHERENT, 34 - DEV_DMA_COHERENT, 35 28 }; 36 29 37 30 const struct fwnode_handle *__dev_fwnode_const(const struct device *dev); ··· 151 156 for (parent = fwnode_get_parent(fwnode); parent; \ 152 157 parent = fwnode_get_next_parent(parent)) 153 158 154 - struct device *fwnode_get_next_parent_dev(const struct fwnode_handle *fwnode); 155 159 unsigned int fwnode_count_parents(const struct fwnode_handle *fwn); 156 160 struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn, 157 161 unsigned int depth); 158 - bool fwnode_is_ancestor_of(const struct fwnode_handle *ancestor, const struct fwnode_handle *child); 159 162 struct fwnode_handle *fwnode_get_next_child_node( 160 163 const struct fwnode_handle *fwnode, struct fwnode_handle *child); 161 164 struct fwnode_handle *fwnode_get_next_available_child_node(
+130 -12
include/linux/sysfs.h
··· 61 61 /** 62 62 * struct attribute_group - data structure used to declare an attribute group. 63 63 * @name: Optional: Attribute group name 64 - * If specified, the attribute group will be created in 65 - * a new subdirectory with this name. 64 + * If specified, the attribute group will be created in a 65 + * new subdirectory with this name. Additionally when a 66 + * group is named, @is_visible and @is_bin_visible may 67 + * return SYSFS_GROUP_INVISIBLE to control visibility of 68 + * the directory itself. 66 69 * @is_visible: Optional: Function to return permissions associated with an 67 - * attribute of the group. Will be called repeatedly for each 68 - * non-binary attribute in the group. Only read/write 70 + * attribute of the group. Will be called repeatedly for 71 + * each non-binary attribute in the group. Only read/write 69 72 * permissions as well as SYSFS_PREALLOC are accepted. Must 70 - * return 0 if an attribute is not visible. The returned value 71 - * will replace static permissions defined in struct attribute. 73 + * return 0 if an attribute is not visible. The returned 74 + * value will replace static permissions defined in struct 75 + * attribute. Use SYSFS_GROUP_VISIBLE() when assigning this 76 + * callback to specify separate _group_visible() and 77 + * _attr_visible() handlers. 72 78 * @is_bin_visible: 73 79 * Optional: Function to return permissions associated with a 74 80 * binary attribute of the group. Will be called repeatedly 75 81 * for each binary attribute in the group. Only read/write 76 - * permissions as well as SYSFS_PREALLOC are accepted. Must 77 - * return 0 if a binary attribute is not visible. The returned 78 - * value will replace static permissions defined in 79 - * struct bin_attribute. 82 + * permissions as well as SYSFS_PREALLOC (and the 83 + * visibility flags for named groups) are accepted. Must 84 + * return 0 if a binary attribute is not visible. The 85 + * returned value will replace static permissions defined 86 + * in struct bin_attribute. If @is_visible is not set, Use 87 + * SYSFS_GROUP_VISIBLE() when assigning this callback to 88 + * specify separate _group_visible() and _attr_visible() 89 + * handlers. 80 90 * @attrs: Pointer to NULL terminated list of attributes. 81 91 * @bin_attrs: Pointer to NULL terminated list of binary attributes. 82 92 * Either attrs or bin_attrs or both must be provided. ··· 101 91 struct bin_attribute **bin_attrs; 102 92 }; 103 93 94 + #define SYSFS_PREALLOC 010000 95 + #define SYSFS_GROUP_INVISIBLE 020000 96 + 97 + /* 98 + * DEFINE_SYSFS_GROUP_VISIBLE(name): 99 + * A helper macro to pair with the assignment of ".is_visible = 100 + * SYSFS_GROUP_VISIBLE(name)", that arranges for the directory 101 + * associated with a named attribute_group to optionally be hidden. 102 + * This allows for static declaration of attribute_groups, and the 103 + * simplification of attribute visibility lifetime that implies, 104 + * without polluting sysfs with empty attribute directories. 105 + * Ex. 106 + * 107 + * static umode_t example_attr_visible(struct kobject *kobj, 108 + * struct attribute *attr, int n) 109 + * { 110 + * if (example_attr_condition) 111 + * return 0; 112 + * else if (ro_attr_condition) 113 + * return 0444; 114 + * return a->mode; 115 + * } 116 + * 117 + * static bool example_group_visible(struct kobject *kobj) 118 + * { 119 + * if (example_group_condition) 120 + * return false; 121 + * return true; 122 + * } 123 + * 124 + * DEFINE_SYSFS_GROUP_VISIBLE(example); 125 + * 126 + * static struct attribute_group example_group = { 127 + * .name = "example", 128 + * .is_visible = SYSFS_GROUP_VISIBLE(example), 129 + * .attrs = &example_attrs, 130 + * }; 131 + * 132 + * Note that it expects <name>_attr_visible and <name>_group_visible to 133 + * be defined. For cases where individual attributes do not need 134 + * separate visibility consideration, only entire group visibility at 135 + * once, see DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(). 136 + */ 137 + #define DEFINE_SYSFS_GROUP_VISIBLE(name) \ 138 + static inline umode_t sysfs_group_visible_##name( \ 139 + struct kobject *kobj, struct attribute *attr, int n) \ 140 + { \ 141 + if (n == 0 && !name##_group_visible(kobj)) \ 142 + return SYSFS_GROUP_INVISIBLE; \ 143 + return name##_attr_visible(kobj, attr, n); \ 144 + } 145 + 146 + /* 147 + * DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(name): 148 + * A helper macro to pair with SYSFS_GROUP_VISIBLE() that like 149 + * DEFINE_SYSFS_GROUP_VISIBLE() controls group visibility, but does 150 + * not require the implementation of a per-attribute visibility 151 + * callback. 152 + * Ex. 153 + * 154 + * static bool example_group_visible(struct kobject *kobj) 155 + * { 156 + * if (example_group_condition) 157 + * return false; 158 + * return true; 159 + * } 160 + * 161 + * DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(example); 162 + * 163 + * static struct attribute_group example_group = { 164 + * .name = "example", 165 + * .is_visible = SYSFS_GROUP_VISIBLE(example), 166 + * .attrs = &example_attrs, 167 + * }; 168 + */ 169 + #define DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(name) \ 170 + static inline umode_t sysfs_group_visible_##name( \ 171 + struct kobject *kobj, struct attribute *a, int n) \ 172 + { \ 173 + if (n == 0 && !name##_group_visible(kobj)) \ 174 + return SYSFS_GROUP_INVISIBLE; \ 175 + return a->mode; \ 176 + } 177 + 178 + /* 179 + * Same as DEFINE_SYSFS_GROUP_VISIBLE, but for groups with only binary 180 + * attributes. If an attribute_group defines both text and binary 181 + * attributes, the group visibility is determined by the function 182 + * specified to is_visible() not is_bin_visible() 183 + */ 184 + #define DEFINE_SYSFS_BIN_GROUP_VISIBLE(name) \ 185 + static inline umode_t sysfs_group_visible_##name( \ 186 + struct kobject *kobj, struct bin_attribute *attr, int n) \ 187 + { \ 188 + if (n == 0 && !name##_group_visible(kobj)) \ 189 + return SYSFS_GROUP_INVISIBLE; \ 190 + return name##_attr_visible(kobj, attr, n); \ 191 + } 192 + 193 + #define DEFINE_SIMPLE_SYSFS_BIN_GROUP_VISIBLE(name) \ 194 + static inline umode_t sysfs_group_visible_##name( \ 195 + struct kobject *kobj, struct bin_attribute *a, int n) \ 196 + { \ 197 + if (n == 0 && !name##_group_visible(kobj)) \ 198 + return SYSFS_GROUP_INVISIBLE; \ 199 + return a->mode; \ 200 + } 201 + 202 + #define SYSFS_GROUP_VISIBLE(fn) sysfs_group_visible_##fn 203 + 104 204 /* 105 205 * Use these macros to make defining attributes easier. 106 206 * See include/linux/device.h for examples.. 107 207 */ 108 - 109 - #define SYSFS_PREALLOC 010000 110 208 111 209 #define __ATTR(_name, _mode, _show, _store) { \ 112 210 .attr = {.name = __stringify(_name), \
+1 -1
kernel/ksysfs.c
··· 39 39 static ssize_t uevent_seqnum_show(struct kobject *kobj, 40 40 struct kobj_attribute *attr, char *buf) 41 41 { 42 - return sysfs_emit(buf, "%llu\n", (unsigned long long)uevent_seqnum); 42 + return sysfs_emit(buf, "%llu\n", (u64)atomic64_read(&uevent_seqnum)); 43 43 } 44 44 KERNEL_ATTR_RO(uevent_seqnum); 45 45
+1 -1
kernel/workqueue.c
··· 7080 7080 __ATTR_NULL, 7081 7081 }; 7082 7082 7083 - static struct bus_type wq_subsys = { 7083 + static const struct bus_type wq_subsys = { 7084 7084 .name = "workqueue", 7085 7085 .dev_groups = wq_sysfs_groups, 7086 7086 };
+11 -13
lib/kobject_uevent.c
··· 30 30 #include <net/net_namespace.h> 31 31 32 32 33 - u64 uevent_seqnum; 33 + atomic64_t uevent_seqnum; 34 34 #ifdef CONFIG_UEVENT_HELPER 35 35 char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH; 36 36 #endif ··· 42 42 43 43 #ifdef CONFIG_NET 44 44 static LIST_HEAD(uevent_sock_list); 45 - #endif 46 - 47 - /* This lock protects uevent_seqnum and uevent_sock_list */ 45 + /* This lock protects uevent_sock_list */ 48 46 static DEFINE_MUTEX(uevent_sock_mutex); 47 + #endif 49 48 50 49 /* the strings here must match the enum in include/linux/kobject.h */ 51 50 static const char *kobject_actions[] = { ··· 314 315 int retval = 0; 315 316 316 317 /* send netlink message */ 318 + mutex_lock(&uevent_sock_mutex); 317 319 list_for_each_entry(ue_sk, &uevent_sock_list, list) { 318 320 struct sock *uevent_sock = ue_sk->sk; 319 321 ··· 334 334 if (retval == -ENOBUFS || retval == -ESRCH) 335 335 retval = 0; 336 336 } 337 + mutex_unlock(&uevent_sock_mutex); 337 338 consume_skb(skb); 338 339 339 340 return retval; ··· 584 583 break; 585 584 } 586 585 587 - mutex_lock(&uevent_sock_mutex); 588 586 /* we will send an event, so request a new sequence number */ 589 - retval = add_uevent_var(env, "SEQNUM=%llu", ++uevent_seqnum); 590 - if (retval) { 591 - mutex_unlock(&uevent_sock_mutex); 587 + retval = add_uevent_var(env, "SEQNUM=%llu", 588 + atomic64_inc_return(&uevent_seqnum)); 589 + if (retval) 592 590 goto exit; 593 - } 591 + 594 592 retval = kobject_uevent_net_broadcast(kobj, env, action_string, 595 593 devpath); 596 - mutex_unlock(&uevent_sock_mutex); 597 594 598 595 #ifdef CONFIG_UEVENT_HELPER 599 596 /* call uevent_helper, usually only enabled during early boot */ ··· 687 688 int ret; 688 689 689 690 /* bump and prepare sequence number */ 690 - ret = snprintf(buf, sizeof(buf), "SEQNUM=%llu", ++uevent_seqnum); 691 + ret = snprintf(buf, sizeof(buf), "SEQNUM=%llu", 692 + atomic64_inc_return(&uevent_seqnum)); 691 693 if (ret < 0 || (size_t)ret >= sizeof(buf)) 692 694 return -ENOMEM; 693 695 ret++; ··· 742 742 return -EPERM; 743 743 } 744 744 745 - mutex_lock(&uevent_sock_mutex); 746 745 ret = uevent_net_broadcast(net->uevent_sock->sk, skb, extack); 747 - mutex_unlock(&uevent_sock_mutex); 748 746 749 747 return ret; 750 748 }