]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
driver core: Replace dev->can_match with dev_can_match()
authorDouglas Anderson <dianders@chromium.org>
Mon, 6 Apr 2026 23:22:55 +0000 (16:22 -0700)
committerDanilo Krummrich <dakr@kernel.org>
Sun, 26 Apr 2026 21:38:02 +0000 (23:38 +0200)
In C, bitfields are not necessarily safe to modify from multiple
threads without locking. Switch "can_match" over to the "flags" field
so modifications are safe.

Cc: Saravana Kannan <saravanak@kernel.org>
Reviewed-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Link: https://patch.msgid.link/20260406162231.v5.2.I54b3ae6311ff34ad30227659d91bb109911a4aea@changeid
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
drivers/base/core.c
drivers/base/dd.c
include/linux/device.h

index bd2ddf2aab505fe0479d91ebaf70d59ad7cc738a..43bbd1716f3702d396ec0f80a5ab40d924618efa 100644 (file)
@@ -1011,7 +1011,7 @@ static void device_links_missing_supplier(struct device *dev)
 
 static bool dev_is_best_effort(struct device *dev)
 {
-       return (fw_devlink_best_effort && dev->can_match) ||
+       return (fw_devlink_best_effort && dev_can_match(dev)) ||
                (dev->fwnode && fwnode_test_flag(dev->fwnode, FWNODE_FLAG_BEST_EFFORT));
 }
 
@@ -1079,7 +1079,7 @@ int device_links_check_suppliers(struct device *dev)
 
                        if (dev_is_best_effort(dev) &&
                            device_link_test(link, DL_FLAG_INFERRED) &&
-                           !link->supplier->can_match) {
+                           !dev_can_match(link->supplier)) {
                                ret = -EAGAIN;
                                continue;
                        }
@@ -1370,7 +1370,7 @@ void device_links_driver_bound(struct device *dev)
                } else if (dev_is_best_effort(dev) &&
                           device_link_test(link, DL_FLAG_INFERRED) &&
                           link->status != DL_STATE_CONSUMER_PROBE &&
-                          !link->supplier->can_match) {
+                          !dev_can_match(link->supplier)) {
                        /*
                         * When dev_is_best_effort() is true, we ignore device
                         * links to suppliers that don't have a driver.  If the
@@ -1758,7 +1758,7 @@ static int fw_devlink_no_driver(struct device *dev, void *data)
 {
        struct device_link *link = to_devlink(dev);
 
-       if (!link->supplier->can_match)
+       if (!dev_can_match(link->supplier))
                fw_devlink_relax_link(link);
 
        return 0;
@@ -3710,7 +3710,7 @@ int device_add(struct device *dev)
         * match with any driver, don't block its consumers from probing in
         * case the consumer device is able to operate without this supplier.
         */
-       if (dev->fwnode && fw_devlink_drv_reg_done && !dev->can_match)
+       if (dev->fwnode && fw_devlink_drv_reg_done && !dev_can_match(dev))
                fw_devlink_unblock_consumers(dev);
 
        if (parent)
index 1dc1e3528043c3f44985b36c3392a689a00873ee..bce1e63b42304d8e9b812c857a23afcc7701db4c 100644 (file)
@@ -132,7 +132,7 @@ static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func);
 
 void driver_deferred_probe_add(struct device *dev)
 {
-       if (!dev->can_match)
+       if (!dev_can_match(dev))
                return;
 
        mutex_lock(&deferred_probe_mutex);
@@ -849,14 +849,14 @@ static int __driver_probe_device(const struct device_driver *drv, struct device
                return dev_err_probe(dev, -EPROBE_DEFER, "Device not ready to probe\n");
 
        /*
-        * Set can_match = true after calling dev_ready_to_probe(), so
+        * Call dev_set_can_match() after calling dev_ready_to_probe(), so
         * driver_deferred_probe_add() won't actually add the device to the
         * deferred probe list when dev_ready_to_probe() returns false.
         *
         * When dev_ready_to_probe() returns false, it means that device_add()
         * will do another probe() attempt for us.
         */
-       dev->can_match = true;
+       dev_set_can_match(dev);
        dev_dbg(dev, "bus: '%s': %s: matched device with driver %s\n",
                drv->bus->name, __func__, drv->name);
 
@@ -1002,7 +1002,7 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
                return 0;
        } else if (ret == -EPROBE_DEFER) {
                dev_dbg(dev, "Device match requests probe deferral\n");
-               dev->can_match = true;
+               dev_set_can_match(dev);
                driver_deferred_probe_add(dev);
                /*
                 * Device can't match with a driver right now, so don't attempt
@@ -1254,7 +1254,7 @@ static int __driver_attach(struct device *dev, void *data)
                return 0;
        } else if (ret == -EPROBE_DEFER) {
                dev_dbg(dev, "Device match requests probe deferral\n");
-               dev->can_match = true;
+               dev_set_can_match(dev);
                driver_deferred_probe_add(dev);
                /*
                 * Driver could not match with device, but may match with
index 9c8fde6a3d866b96b606e7eab5cf6ee0dd40633e..00113821ebe9b114b18e01c69512324064d4d4c5 100644 (file)
@@ -512,10 +512,14 @@ struct device_physical_location {
  *
  * @DEV_FLAG_READY_TO_PROBE: If set then device_add() has finished enough
  *             initialization that probe could be called.
+ * @DEV_FLAG_CAN_MATCH: The device has matched with a driver at least once or it
+ *             is in a bus (like AMBA) which can't check for matching drivers
+ *             until other devices probe successfully.
  * @DEV_FLAG_COUNT: Number of defined struct_device_flags.
  */
 enum struct_device_flags {
        DEV_FLAG_READY_TO_PROBE = 0,
+       DEV_FLAG_CAN_MATCH = 1,
 
        DEV_FLAG_COUNT
 };
@@ -602,9 +606,6 @@ enum struct_device_flags {
  * @state_synced: The hardware state of this device has been synced to match
  *               the software state of this device by calling the driver/bus
  *               sync_state() callback.
- * @can_match: The device has matched with a driver at least once or it is in
- *             a bus (like AMBA) which can't check for matching drivers until
- *             other devices probe successfully.
  * @dma_coherent: this particular device is dma coherent, even if the
  *             architecture supports non-coherent devices.
  * @dma_ops_bypass: If set to %true then the dma_ops are bypassed for the
@@ -723,7 +724,6 @@ struct device {
        bool                    offline:1;
        bool                    of_node_reused:1;
        bool                    state_synced:1;
-       bool                    can_match:1;
 #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
     defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
     defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
@@ -765,6 +765,7 @@ static inline bool dev_test_and_set_##accessor_name(struct device *dev) \
 }
 
 __create_dev_flag_accessors(ready_to_probe, DEV_FLAG_READY_TO_PROBE);
+__create_dev_flag_accessors(can_match, DEV_FLAG_CAN_MATCH);
 
 #undef __create_dev_flag_accessors