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

Cc: Rafael J. Wysocki <rafael@kernel.org>
Acked-by: Mark Brown <broonie@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.9.I897d478b4a9361d79cd5073207c1062fd4d0d0e4@changeid
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
arch/arm64/kernel/cpufeature.c
arch/powerpc/platforms/pseries/hotplug-memory.c
drivers/acpi/scan.c
drivers/base/core.c
drivers/base/cpu.c
drivers/base/memory.c
include/linux/device.h
kernel/cpu.c

index 6d53bb15cf7bb48e926330c7ff0c93c0c14b14c2..e592520e13b713bc65b8b6dd6935a125e5d025d4 100644 (file)
@@ -4052,7 +4052,7 @@ static int enable_mismatched_32bit_el0(unsigned int cpu)
         */
        lucky_winner = cpu_32bit ? cpu : cpumask_any_and(cpu_32bit_el0_mask,
                                                         cpu_active_mask);
-       get_cpu_device(lucky_winner)->offline_disabled = true;
+       dev_set_offline_disabled(get_cpu_device(lucky_winner));
        setup_elf_hwcaps(compat_elf_hwcaps);
        elf_hwcap_fixup();
        pr_info("Asymmetric 32-bit EL0 support detected on CPU %u; CPU hot-unplug disabled on CPU %u\n",
index b2f14db59034cf666e6dcad129103d06cb1e8328..75f85a5da9810491e17b2d23379f84e2f0e40f94 100644 (file)
@@ -213,9 +213,9 @@ static int dlpar_change_lmb_state(struct drmem_lmb *lmb, bool online)
                return -EINVAL;
        }
 
-       if (online && mem_block->dev.offline)
+       if (online && dev_offline(&mem_block->dev))
                rc = device_online(&mem_block->dev);
-       else if (!online && !mem_block->dev.offline)
+       else if (!online && !dev_offline(&mem_block->dev))
                rc = device_offline(&mem_block->dev);
        else
                rc = 0;
index 530547cda8b2866ad1aa39dc3a26a66d8ffa3df1..a0c36bd968d30ebf5ae073d75f35b97c9fd0ca5e 100644 (file)
@@ -122,7 +122,7 @@ bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent)
        mutex_lock_nested(&adev->physical_node_lock, SINGLE_DEPTH_NESTING);
 
        list_for_each_entry(pn, &adev->physical_node_list, node)
-               if (device_supports_offline(pn->dev) && !pn->dev->offline) {
+               if (device_supports_offline(pn->dev) && !dev_offline(pn->dev)) {
                        if (uevent)
                                kobject_uevent_env(&pn->dev->kobj, KOBJ_CHANGE, envp);
 
index 62140ec6c49ef33f019894458bf1b4fc3da828e4..d49420e066de6409c705d668c7b154ee1d311119 100644 (file)
@@ -2787,7 +2787,7 @@ static ssize_t online_show(struct device *dev, struct device_attribute *attr,
        bool val;
 
        device_lock(dev);
-       val = !dev->offline;
+       val = !dev_offline(dev);
        device_unlock(dev);
        return sysfs_emit(buf, "%u\n", val);
 }
@@ -2913,7 +2913,7 @@ static int device_add_attrs(struct device *dev)
        if (error)
                goto err_remove_type_groups;
 
-       if (device_supports_offline(dev) && !dev->offline_disabled) {
+       if (device_supports_offline(dev) && !dev_offline_disabled(dev)) {
                error = device_create_file(dev, &dev_attr_online);
                if (error)
                        goto err_remove_dev_groups;
@@ -4176,7 +4176,7 @@ static int device_check_offline(struct device *dev, void *not_used)
        if (ret)
                return ret;
 
-       return device_supports_offline(dev) && !dev->offline ? -EBUSY : 0;
+       return device_supports_offline(dev) && !dev_offline(dev) ? -EBUSY : 0;
 }
 
 /**
@@ -4194,7 +4194,7 @@ int device_offline(struct device *dev)
 {
        int ret;
 
-       if (dev->offline_disabled)
+       if (dev_offline_disabled(dev))
                return -EPERM;
 
        ret = device_for_each_child(dev, NULL, device_check_offline);
@@ -4203,13 +4203,13 @@ int device_offline(struct device *dev)
 
        device_lock(dev);
        if (device_supports_offline(dev)) {
-               if (dev->offline) {
+               if (dev_offline(dev)) {
                        ret = 1;
                } else {
                        ret = dev->bus->offline(dev);
                        if (!ret) {
                                kobject_uevent(&dev->kobj, KOBJ_OFFLINE);
-                               dev->offline = true;
+                               dev_set_offline(dev);
                        }
                }
        }
@@ -4234,11 +4234,11 @@ int device_online(struct device *dev)
 
        device_lock(dev);
        if (device_supports_offline(dev)) {
-               if (dev->offline) {
+               if (dev_offline(dev)) {
                        ret = dev->bus->online(dev);
                        if (!ret) {
                                kobject_uevent(&dev->kobj, KOBJ_ONLINE);
-                               dev->offline = false;
+                               dev_clear_offline(dev);
                        }
                } else {
                        ret = 1;
@@ -4712,7 +4712,7 @@ static int device_attrs_change_owner(struct device *dev, kuid_t kuid,
        if (error)
                return error;
 
-       if (device_supports_offline(dev) && !dev->offline_disabled) {
+       if (device_supports_offline(dev) && !dev_offline_disabled(dev)) {
                /* Change online device attributes of @dev to @kuid/@kgid. */
                error = sysfs_file_change_owner(kobj, dev_attr_online.attr.name,
                                                kuid, kgid);
index 875abdc9942e13d3ce44a0b1ed426a1613529a5d..19d288a3c80cdb1f086efc076f2205216bc487f2 100644 (file)
@@ -422,8 +422,8 @@ int register_cpu(struct cpu *cpu, int num)
        cpu->dev.id = num;
        cpu->dev.bus = &cpu_subsys;
        cpu->dev.release = cpu_device_release;
-       cpu->dev.offline_disabled = !cpu->hotpluggable;
-       cpu->dev.offline = !cpu_online(num);
+       dev_assign_offline_disabled(&cpu->dev, !cpu->hotpluggable);
+       dev_assign_offline(&cpu->dev, !cpu_online(num));
        cpu->dev.of_node = of_get_cpu_node(num, NULL);
        cpu->dev.groups = common_cpu_attr_groups;
        if (cpu->hotpluggable)
index f806a683b7672221ce49b613131cac6d8d2dab27..37c7f773aa5a824857d1fc4b9356e4bf4dee6f15 100644 (file)
@@ -697,7 +697,7 @@ static int __add_memory_block(struct memory_block *memory)
        memory->dev.id = memory->start_section_nr / sections_per_block;
        memory->dev.release = memory_block_release;
        memory->dev.groups = memory_memblk_attr_groups;
-       memory->dev.offline = memory->state == MEM_OFFLINE;
+       dev_assign_offline(&memory->dev, memory->state == MEM_OFFLINE);
 
        ret = device_register(&memory->dev);
        if (ret) {
index cc6ef0ca0d2579a5f64c5ed6830799d9a5382e55..3bf86d2f95448524bf07daceac2c15bea29f98cc 100644 (file)
@@ -531,6 +531,8 @@ struct device_physical_location {
  *             architecture supports non-coherent devices.
  * @DEV_FLAG_OF_NODE_REUSED: Set if the device-tree node is shared with an
  *             ancestor device.
+ * @DEV_FLAG_OFFLINE_DISABLED: If set, the device is permanently online.
+ * @DEV_FLAG_OFFLINE: Set after successful invocation of bus type's .offline().
  * @DEV_FLAG_COUNT: Number of defined struct_device_flags.
  */
 enum struct_device_flags {
@@ -542,6 +544,8 @@ enum struct_device_flags {
        DEV_FLAG_STATE_SYNCED = 5,
        DEV_FLAG_DMA_COHERENT = 6,
        DEV_FLAG_OF_NODE_REUSED = 7,
+       DEV_FLAG_OFFLINE_DISABLED = 8,
+       DEV_FLAG_OFFLINE = 9,
 
        DEV_FLAG_COUNT
 };
@@ -620,9 +624,6 @@ enum struct_device_flags {
  * @removable:  Whether the device can be removed from the system. This
  *              should be set by the subsystem / bus driver that discovered
  *              the device.
- *
- * @offline_disabled: If set, the device is permanently online.
- * @offline:   Set after successful invocation of bus type's .offline().
  * @flags:     DEV_FLAG_XXX flags. Use atomic bitfield operations to modify.
  *
  * At the lowest level, every device in a Linux system is represented by an
@@ -727,9 +728,6 @@ struct device {
 
        enum device_removable   removable;
 
-       bool                    offline_disabled:1;
-       bool                    offline:1;
-
        DECLARE_BITMAP(flags, DEV_FLAG_COUNT);
 };
 
@@ -763,6 +761,8 @@ __create_dev_flag_accessors(dma_ops_bypass, DEV_FLAG_DMA_OPS_BYPASS);
 __create_dev_flag_accessors(state_synced, DEV_FLAG_STATE_SYNCED);
 __create_dev_flag_accessors(dma_coherent, DEV_FLAG_DMA_COHERENT);
 __create_dev_flag_accessors(of_node_reused, DEV_FLAG_OF_NODE_REUSED);
+__create_dev_flag_accessors(offline_disabled, DEV_FLAG_OFFLINE_DISABLED);
+__create_dev_flag_accessors(offline, DEV_FLAG_OFFLINE);
 
 #undef __create_dev_flag_accessors
 
index bc4f7a9ba64e62d76fbb2b362f243c918defe5bc..f975bb34915b038b83c98edff5f890f1fc3c4b3e 100644 (file)
@@ -2639,7 +2639,7 @@ static void cpuhp_offline_cpu_device(unsigned int cpu)
 {
        struct device *dev = get_cpu_device(cpu);
 
-       dev->offline = true;
+       dev_set_offline(dev);
        /* Tell user space about the state change */
        kobject_uevent(&dev->kobj, KOBJ_OFFLINE);
 }
@@ -2648,7 +2648,7 @@ static void cpuhp_online_cpu_device(unsigned int cpu)
 {
        struct device *dev = get_cpu_device(cpu);
 
-       dev->offline = false;
+       dev_clear_offline(dev);
        /* Tell user space about the state change */
        kobject_uevent(&dev->kobj, KOBJ_ONLINE);
 }