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

Configure Feed

Select the types of activity you want to include in your feed.

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

Pull driver core fixes from Danilo Krummrich:

- Prevent a device from being probed before device_add() has finished
initializing it; gate probe with a "ready_to_probe" device flag to
avoid races with concurrent driver_register() calls

- Fix a kernel-doc warning for DEV_FLAG_COUNT introduced by the above

- Return -ENOTCONN from software_node_get_reference_args() when a
referenced software node is known but not yet registered, allowing
callers to defer probe

- In sysfs_group_attrs_change_owner(), also check is_visible_const();
missed when the const variant was introduced

* tag 'driver-core-7.1-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core:
driver core: Add kernel-doc for DEV_FLAG_COUNT enum value
sysfs: attribute_group: Respect is_visible_const() when changing owner
software node: return -ENOTCONN when referenced swnode is not registered yet
driver core: Don't let a device probe until it's ready

+88 -3
+15
drivers/base/core.c
··· 3688 3688 fw_devlink_link_device(dev); 3689 3689 } 3690 3690 3691 + /* 3692 + * The moment the device was linked into the bus's "klist_devices" in 3693 + * bus_add_device() then it's possible that probe could have been 3694 + * attempted in a different thread via userspace loading a driver 3695 + * matching the device. "ready_to_probe" being unset would have 3696 + * blocked those attempts. Now that all of the above initialization has 3697 + * happened, unblock probe. If probe happens through another thread 3698 + * after this point but before bus_probe_device() runs then it's fine. 3699 + * bus_probe_device() -> device_initial_probe() -> __device_attach() 3700 + * will notice (under device_lock) that the device is already bound. 3701 + */ 3702 + device_lock(dev); 3703 + dev_set_ready_to_probe(dev); 3704 + device_unlock(dev); 3705 + 3691 3706 bus_probe_device(dev); 3692 3707 3693 3708 /*
+20
drivers/base/dd.c
··· 836 836 if (dev->driver) 837 837 return -EBUSY; 838 838 839 + /* 840 + * In device_add(), the "struct device" gets linked into the subsystem's 841 + * list of devices and broadcast to userspace (via uevent) before we're 842 + * quite ready to probe. Those open pathways to driver probe before 843 + * we've finished enough of device_add() to reliably support probe. 844 + * Detect this and tell other pathways to try again later. device_add() 845 + * itself will also try to probe immediately after setting 846 + * "ready_to_probe". 847 + */ 848 + if (!dev_ready_to_probe(dev)) 849 + return dev_err_probe(dev, -EPROBE_DEFER, "Device not ready to probe\n"); 850 + 851 + /* 852 + * Set can_match = true after calling dev_ready_to_probe(), so 853 + * driver_deferred_probe_add() won't actually add the device to the 854 + * deferred probe list when dev_ready_to_probe() returns false. 855 + * 856 + * When dev_ready_to_probe() returns false, it means that device_add() 857 + * will do another probe() attempt for us. 858 + */ 839 859 dev->can_match = true; 840 860 dev_dbg(dev, "bus: '%s': %s: matched device with driver %s\n", 841 861 drv->bus->name, __func__, drv->name);
+2
drivers/base/property.c
··· 602 602 * %-ENOENT when the index is out of bounds, the index has an empty 603 603 * reference or the property was not found 604 604 * %-EINVAL on parse error 605 + * %-ENOTCONN when the remote firmware node exists but has not been 606 + * registered yet 605 607 */ 606 608 int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode, 607 609 const char *prop, const char *nargs_prop,
+1 -1
drivers/base/swnode.c
··· 554 554 return -EINVAL; 555 555 556 556 if (!refnode) 557 - return -ENOENT; 557 + return -ENOTCONN; 558 558 559 559 if (nargs_prop) { 560 560 error = fwnode_property_read_u32(refnode, nargs_prop, &nargs_prop_val);
+5 -2
fs/sysfs/group.c
··· 517 517 struct attribute *const *attr; 518 518 519 519 for (i = 0, attr = grp->attrs; *attr; i++, attr++) { 520 - if (grp->is_visible) { 521 - mode = grp->is_visible(kobj, *attr, i); 520 + if (grp->is_visible || grp->is_visible_const) { 521 + if (grp->is_visible) 522 + mode = grp->is_visible(kobj, *attr, i); 523 + else 524 + mode = grp->is_visible_const(kobj, *attr, i); 522 525 if (mode & SYSFS_GROUP_INVISIBLE) 523 526 break; 524 527 if (!mode)
+45
include/linux/device.h
··· 505 505 }; 506 506 507 507 /** 508 + * enum struct_device_flags - Flags in struct device 509 + * 510 + * Each flag should have a set of accessor functions created via 511 + * __create_dev_flag_accessors() for each access. 512 + * 513 + * @DEV_FLAG_READY_TO_PROBE: If set then device_add() has finished enough 514 + * initialization that probe could be called. 515 + * @DEV_FLAG_COUNT: Number of defined struct_device_flags. 516 + */ 517 + enum struct_device_flags { 518 + DEV_FLAG_READY_TO_PROBE = 0, 519 + 520 + DEV_FLAG_COUNT 521 + }; 522 + 523 + /** 508 524 * struct device - The basic device structure 509 525 * @parent: The device's "parent" device, the device to which it is attached. 510 526 * In most cases, a parent device is some sort of bus or host ··· 615 599 * @dma_skip_sync: DMA sync operations can be skipped for coherent buffers. 616 600 * @dma_iommu: Device is using default IOMMU implementation for DMA and 617 601 * doesn't rely on dma_ops structure. 602 + * @flags: DEV_FLAG_XXX flags. Use atomic bitfield operations to modify. 618 603 * 619 604 * At the lowest level, every device in a Linux system is represented by an 620 605 * instance of struct device. The device structure contains the information ··· 738 721 #ifdef CONFIG_IOMMU_DMA 739 722 bool dma_iommu:1; 740 723 #endif 724 + 725 + DECLARE_BITMAP(flags, DEV_FLAG_COUNT); 741 726 }; 727 + 728 + #define __create_dev_flag_accessors(accessor_name, flag_name) \ 729 + static inline bool dev_##accessor_name(const struct device *dev) \ 730 + { \ 731 + return test_bit(flag_name, dev->flags); \ 732 + } \ 733 + static inline void dev_set_##accessor_name(struct device *dev) \ 734 + { \ 735 + set_bit(flag_name, dev->flags); \ 736 + } \ 737 + static inline void dev_clear_##accessor_name(struct device *dev) \ 738 + { \ 739 + clear_bit(flag_name, dev->flags); \ 740 + } \ 741 + static inline void dev_assign_##accessor_name(struct device *dev, bool value) \ 742 + { \ 743 + assign_bit(flag_name, dev->flags, value); \ 744 + } \ 745 + static inline bool dev_test_and_set_##accessor_name(struct device *dev) \ 746 + { \ 747 + return test_and_set_bit(flag_name, dev->flags); \ 748 + } 749 + 750 + __create_dev_flag_accessors(ready_to_probe, DEV_FLAG_READY_TO_PROBE); 751 + 752 + #undef __create_dev_flag_accessors 742 753 743 754 /** 744 755 * struct device_link - Device link representation.