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

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

Pull driver core updates from Greg KH:
"Here are the set of driver core and kernfs changes for 6.8-rc1.
Nothing major in here this release cycle, just lots of small cleanups
and some tweaks on kernfs that in the very end, got reverted and will
come back in a safer way next release cycle.

Included in here are:

- more driver core 'const' cleanups and fixes

- fw_devlink=rpm is now the default behavior

- kernfs tiny changes to remove some string functions

- cpu handling in the driver core is updated to work better on many
systems that add topologies and cpus after booting

- other minor changes and cleanups

All of the cpu handling patches have been acked by the respective
maintainers and are coming in here in one series. Everything has been
in linux-next for a while with no reported issues"

* tag 'driver-core-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (51 commits)
Revert "kernfs: convert kernfs_idr_lock to an irq safe raw spinlock"
kernfs: convert kernfs_idr_lock to an irq safe raw spinlock
class: fix use-after-free in class_register()
PM: clk: make pm_clk_add_notifier() take a const pointer
EDAC: constantify the struct bus_type usage
kernfs: fix reference to renamed function
driver core: device.h: fix Excess kernel-doc description warning
driver core: class: fix Excess kernel-doc description warning
driver core: mark remaining local bus_type variables as const
driver core: container: make container_subsys const
driver core: bus: constantify subsys_register() calls
driver core: bus: make bus_sort_breadthfirst() take a const pointer
kernfs: d_obtain_alias(NULL) will do the right thing...
driver core: Better advertise dev_err_probe()
kernfs: Convert kernfs_path_from_node_locked() from strlcpy() to strscpy()
kernfs: Convert kernfs_name_locked() from strlcpy() to strscpy()
kernfs: Convert kernfs_walk_ns() from strlcpy() to strscpy()
initramfs: Expose retained initrd as sysfs file
fs/kernfs/dir: obey S_ISGID
kernel/cgroup: use kernfs_create_dir_ns()
...

+207 -253
+8
Documentation/ABI/testing/sysfs-firmware-initrd
··· 1 + What: /sys/firmware/initrd 2 + Date: December 2023 3 + Contact: Alexander Graf <graf@amazon.com> 4 + Description: 5 + When the kernel was booted with an initrd and the 6 + "retain_initrd" option is set on the kernel command 7 + line, /sys/firmware/initrd contains the contents of the 8 + initrd that the kernel was booted with.
+3 -2
Documentation/admin-guide/kernel-parameters.txt
··· 2449 2449 between unregistering the boot console and initializing 2450 2450 the real console. 2451 2451 2452 - keepinitrd [HW,ARM] 2452 + keepinitrd [HW,ARM] See retain_initrd. 2453 2453 2454 2454 kernelcore= [KNL,X86,IA-64,PPC] 2455 2455 Format: nn[KMGTPE] | nn% | "mirror" ··· 5604 5604 Useful for devices that are detected asynchronously 5605 5605 (e.g. USB and MMC devices). 5606 5606 5607 - retain_initrd [RAM] Keep initrd memory after extraction 5607 + retain_initrd [RAM] Keep initrd memory after extraction. After boot, it will 5608 + be accessible via /sys/firmware/initrd. 5608 5609 5609 5610 retbleed= [X86] Control mitigation of RETBleed (Arbitrary 5610 5611 Speculative Code Execution with Return Instructions)
+1
arch/arm64/Kconfig
··· 133 133 select GENERIC_ARCH_TOPOLOGY 134 134 select GENERIC_CLOCKEVENTS_BROADCAST 135 135 select GENERIC_CPU_AUTOPROBE 136 + select GENERIC_CPU_DEVICES 136 137 select GENERIC_CPU_VULNERABILITIES 137 138 select GENERIC_EARLY_IOREMAP 138 139 select GENERIC_IDLE_POLL_SETUP
-1
arch/arm64/include/asm/cpu.h
··· 38 38 }; 39 39 40 40 struct cpuinfo_arm64 { 41 - struct cpu cpu; 42 41 struct kobject kobj; 43 42 u64 reg_ctr; 44 43 u64 reg_cntfrq;
+2 -11
arch/arm64/kernel/setup.c
··· 402 402 return false; 403 403 } 404 404 405 - static int __init topology_init(void) 405 + bool arch_cpu_is_hotpluggable(int num) 406 406 { 407 - int i; 408 - 409 - for_each_possible_cpu(i) { 410 - struct cpu *cpu = &per_cpu(cpu_data.cpu, i); 411 - cpu->hotpluggable = cpu_can_disable(i); 412 - register_cpu(cpu, i); 413 - } 414 - 415 - return 0; 407 + return cpu_can_disable(num); 416 408 } 417 - subsys_initcall(topology_init); 418 409 419 410 static void dump_kernel_offset(void) 420 411 {
+2
arch/loongarch/Kconfig
··· 5 5 select ACPI 6 6 select ACPI_GENERIC_GSI if ACPI 7 7 select ACPI_MCFG if ACPI 8 + select ACPI_HOTPLUG_CPU if ACPI_PROCESSOR && HOTPLUG_CPU 8 9 select ACPI_PPTT if ACPI 9 10 select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI 10 11 select ARCH_BINFMT_ELF_STATE ··· 72 71 select GENERIC_CLOCKEVENTS 73 72 select GENERIC_CMOS_UPDATE 74 73 select GENERIC_CPU_AUTOPROBE 74 + select GENERIC_CPU_DEVICES 75 75 select GENERIC_ENTRY 76 76 select GENERIC_GETTIMEOFDAY 77 77 select GENERIC_IOREMAP if !ARCH_IOREMAP
+2 -40
arch/loongarch/kernel/topology.c
··· 10 10 11 11 #include <acpi/processor.h> 12 12 13 - static DEFINE_PER_CPU(struct cpu, cpu_devices); 14 - 15 13 #ifdef CONFIG_HOTPLUG_CPU 16 - int arch_register_cpu(int cpu) 14 + bool arch_cpu_is_hotpluggable(int cpu) 17 15 { 18 - int ret; 19 - struct cpu *c = &per_cpu(cpu_devices, cpu); 20 - 21 - c->hotpluggable = 1; 22 - ret = register_cpu(c, cpu); 23 - if (ret < 0) 24 - pr_warn("register_cpu %d failed (%d)\n", cpu, ret); 25 - 26 - return ret; 16 + return !io_master(cpu); 27 17 } 28 - EXPORT_SYMBOL(arch_register_cpu); 29 - 30 - void arch_unregister_cpu(int cpu) 31 - { 32 - struct cpu *c = &per_cpu(cpu_devices, cpu); 33 - 34 - c->hotpluggable = 0; 35 - unregister_cpu(c); 36 - } 37 - EXPORT_SYMBOL(arch_unregister_cpu); 38 18 #endif 39 - 40 - static int __init topology_init(void) 41 - { 42 - int i, ret; 43 - 44 - for_each_present_cpu(i) { 45 - struct cpu *c = &per_cpu(cpu_devices, i); 46 - 47 - c->hotpluggable = !io_master(i); 48 - ret = register_cpu(c, i); 49 - if (ret < 0) 50 - pr_warn("topology_init: register_cpu %d failed (%d)\n", i, ret); 51 - } 52 - 53 - return 0; 54 - } 55 - 56 - subsys_initcall(topology_init);
+1
arch/riscv/Kconfig
··· 72 72 select GENERIC_ARCH_TOPOLOGY 73 73 select GENERIC_ATOMIC64 if !64BIT 74 74 select GENERIC_CLOCKEVENTS_BROADCAST if SMP 75 + select GENERIC_CPU_DEVICES 75 76 select GENERIC_EARLY_IOREMAP 76 77 select GENERIC_ENTRY 77 78 select GENERIC_GETTIMEOFDAY if HAVE_GENERIC_VDSO
+2 -16
arch/riscv/kernel/setup.c
··· 50 50 #endif 51 51 ; 52 52 unsigned long boot_cpu_hartid; 53 - static DEFINE_PER_CPU(struct cpu, cpu_devices); 54 53 55 54 /* 56 55 * Place kernel memory regions on the resource tree so that ··· 297 298 riscv_user_isa_enable(); 298 299 } 299 300 300 - static int __init topology_init(void) 301 + bool arch_cpu_is_hotpluggable(int cpu) 301 302 { 302 - int i, ret; 303 - 304 - for_each_possible_cpu(i) { 305 - struct cpu *cpu = &per_cpu(cpu_devices, i); 306 - 307 - cpu->hotpluggable = cpu_has_hotplug(i); 308 - ret = register_cpu(cpu, i); 309 - if (unlikely(ret)) 310 - pr_warn("Warning: %s: register_cpu %d failed (%d)\n", 311 - __func__, i, ret); 312 - } 313 - 314 - return 0; 303 + return cpu_has_hotplug(cpu); 315 304 } 316 - subsys_initcall(topology_init); 317 305 318 306 void free_initmem(void) 319 307 {
+2
arch/x86/Kconfig
··· 59 59 # 60 60 select ACPI_LEGACY_TABLES_LOOKUP if ACPI 61 61 select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI 62 + select ACPI_HOTPLUG_CPU if ACPI_PROCESSOR && HOTPLUG_CPU 62 63 select ARCH_32BIT_OFF_T if X86_32 63 64 select ARCH_CLOCKSOURCE_INIT 64 65 select ARCH_CORRECT_STACKTRACE_ON_KRETPROBE ··· 149 148 select GENERIC_CLOCKEVENTS_MIN_ADJUST 150 149 select GENERIC_CMOS_UPDATE 151 150 select GENERIC_CPU_AUTOPROBE 151 + select GENERIC_CPU_DEVICES 152 152 select GENERIC_CPU_VULNERABILITIES 153 153 select GENERIC_EARLY_IOREMAP 154 154 select GENERIC_ENTRY
-4
arch/x86/include/asm/cpu.h
··· 23 23 24 24 #endif /* CONFIG_SMP */ 25 25 26 - struct x86_cpu { 27 - struct cpu cpu; 28 - }; 29 - 30 26 #ifdef CONFIG_HOTPLUG_CPU 31 27 extern void soft_restart_cpu(void); 32 28 #endif
+2 -31
arch/x86/kernel/topology.c
··· 35 35 #include <asm/io_apic.h> 36 36 #include <asm/cpu.h> 37 37 38 - static DEFINE_PER_CPU(struct x86_cpu, cpu_devices); 39 - 40 38 #ifdef CONFIG_HOTPLUG_CPU 41 - int arch_register_cpu(int cpu) 39 + bool arch_cpu_is_hotpluggable(int cpu) 42 40 { 43 - struct x86_cpu *xc = per_cpu_ptr(&cpu_devices, cpu); 44 - 45 - xc->cpu.hotpluggable = cpu > 0; 46 - return register_cpu(&xc->cpu, cpu); 47 - } 48 - EXPORT_SYMBOL(arch_register_cpu); 49 - 50 - void arch_unregister_cpu(int num) 51 - { 52 - unregister_cpu(&per_cpu(cpu_devices, num).cpu); 53 - } 54 - EXPORT_SYMBOL(arch_unregister_cpu); 55 - #else /* CONFIG_HOTPLUG_CPU */ 56 - 57 - int __init arch_register_cpu(int num) 58 - { 59 - return register_cpu(&per_cpu(cpu_devices, num).cpu, num); 41 + return cpu > 0; 60 42 } 61 43 #endif /* CONFIG_HOTPLUG_CPU */ 62 - 63 - static int __init topology_init(void) 64 - { 65 - int i; 66 - 67 - for_each_present_cpu(i) 68 - arch_register_cpu(i); 69 - 70 - return 0; 71 - } 72 - subsys_initcall(topology_init);
-1
drivers/acpi/Kconfig
··· 314 314 bool 315 315 depends on ACPI_PROCESSOR && HOTPLUG_CPU 316 316 select ACPI_CONTAINER 317 - default y 318 317 319 318 config ACPI_PROCESSOR_AGGREGATOR 320 319 tristate "Processor Aggregator"
-18
drivers/acpi/acpi_processor.c
··· 184 184 185 185 /* Initialization */ 186 186 #ifdef CONFIG_ACPI_HOTPLUG_CPU 187 - int __weak acpi_map_cpu(acpi_handle handle, 188 - phys_cpuid_t physid, u32 acpi_id, int *pcpu) 189 - { 190 - return -ENODEV; 191 - } 192 - 193 - int __weak acpi_unmap_cpu(int cpu) 194 - { 195 - return -ENODEV; 196 - } 197 - 198 - int __weak arch_register_cpu(int cpu) 199 - { 200 - return -ENODEV; 201 - } 202 - 203 - void __weak arch_unregister_cpu(int cpu) {} 204 - 205 187 static int acpi_processor_hotadd_init(struct acpi_processor *pr) 206 188 { 207 189 unsigned long long sta;
+4
drivers/acpi/property.c
··· 881 881 * @index: Index of the reference to return 882 882 * @num_args: Maximum number of arguments after each reference 883 883 * @args: Location to store the returned reference with optional arguments 884 + * (may be NULL) 884 885 * 885 886 * Find property with @name, verifify that it is a package containing at least 886 887 * one object reference and if so, store the ACPI device object pointer to the ··· 938 937 device = acpi_fetch_acpi_dev(obj->reference.handle); 939 938 if (!device) 940 939 return -EINVAL; 940 + 941 + if (!args) 942 + return 0; 941 943 942 944 args->fwnode = acpi_fwnode_handle(device); 943 945 args->nargs = 0;
+26 -12
drivers/base/arch_topology.c
··· 219 219 220 220 static DEVICE_ATTR_RO(cpu_capacity); 221 221 222 + static int cpu_capacity_sysctl_add(unsigned int cpu) 223 + { 224 + struct device *cpu_dev = get_cpu_device(cpu); 225 + 226 + if (!cpu_dev) 227 + return -ENOENT; 228 + 229 + device_create_file(cpu_dev, &dev_attr_cpu_capacity); 230 + 231 + return 0; 232 + } 233 + 234 + static int cpu_capacity_sysctl_remove(unsigned int cpu) 235 + { 236 + struct device *cpu_dev = get_cpu_device(cpu); 237 + 238 + if (!cpu_dev) 239 + return -ENOENT; 240 + 241 + device_remove_file(cpu_dev, &dev_attr_cpu_capacity); 242 + 243 + return 0; 244 + } 245 + 222 246 static int register_cpu_capacity_sysctl(void) 223 247 { 224 - int i; 225 - struct device *cpu; 226 - 227 - for_each_possible_cpu(i) { 228 - cpu = get_cpu_device(i); 229 - if (!cpu) { 230 - pr_err("%s: too early to get CPU%d device!\n", 231 - __func__, i); 232 - continue; 233 - } 234 - device_create_file(cpu, &dev_attr_cpu_capacity); 235 - } 248 + cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "topology/cpu-capacity", 249 + cpu_capacity_sysctl_add, cpu_capacity_sysctl_remove); 236 250 237 251 return 0; 238 252 }
+1 -1
drivers/base/auxiliary.c
··· 244 244 auxdrv->shutdown(auxdev); 245 245 } 246 246 247 - static struct bus_type auxiliary_bus_type = { 247 + static const struct bus_type auxiliary_bus_type = { 248 248 .name = "auxiliary", 249 249 .probe = auxiliary_bus_probe, 250 250 .remove = auxiliary_bus_remove,
+4 -4
drivers/base/bus.c
··· 1030 1030 list_move_tail(&a->p->knode_bus.n_node, list); 1031 1031 } 1032 1032 1033 - void bus_sort_breadthfirst(struct bus_type *bus, 1033 + void bus_sort_breadthfirst(const struct bus_type *bus, 1034 1034 int (*compare)(const struct device *a, 1035 1035 const struct device *b)) 1036 1036 { ··· 1194 1194 kfree(dev); 1195 1195 } 1196 1196 1197 - static int subsys_register(struct bus_type *subsys, 1197 + static int subsys_register(const struct bus_type *subsys, 1198 1198 const struct attribute_group **groups, 1199 1199 struct kobject *parent_of_root) 1200 1200 { ··· 1264 1264 * directory itself and not some create fake root-device placed in 1265 1265 * /sys/devices/system/<name>. 1266 1266 */ 1267 - int subsys_system_register(struct bus_type *subsys, 1267 + int subsys_system_register(const struct bus_type *subsys, 1268 1268 const struct attribute_group **groups) 1269 1269 { 1270 1270 return subsys_register(subsys, groups, &system_kset->kobj); ··· 1282 1282 * There's no restriction on device naming. This is for kernel software 1283 1283 * constructs which need sysfs interface. 1284 1284 */ 1285 - int subsys_virtual_register(struct bus_type *subsys, 1285 + int subsys_virtual_register(const struct bus_type *subsys, 1286 1286 const struct attribute_group **groups) 1287 1287 { 1288 1288 struct kobject *virtual_dir;
+1
drivers/base/class.c
··· 213 213 return 0; 214 214 215 215 err_out: 216 + lockdep_unregister_key(key); 216 217 kfree(cp); 217 218 return error; 218 219 }
+1 -1
drivers/base/container.c
··· 24 24 return cdev->offline ? cdev->offline(cdev) : 0; 25 25 } 26 26 27 - struct bus_type container_subsys = { 27 + const struct bus_type container_subsys = { 28 28 .name = CONTAINER_BUS_NAME, 29 29 .dev_name = CONTAINER_BUS_NAME, 30 30 .online = trivial_online,
+7 -6
drivers/base/core.c
··· 298 298 * Check if @target depends on @dev or any device dependent on it (its child or 299 299 * its consumer etc). Return 1 if that is the case or 0 otherwise. 300 300 */ 301 - int device_is_dependent(struct device *dev, void *target) 301 + static int device_is_dependent(struct device *dev, void *target) 302 302 { 303 303 struct device_link *link; 304 304 int ret; ··· 1641 1641 #define FW_DEVLINK_FLAGS_RPM (FW_DEVLINK_FLAGS_ON | \ 1642 1642 DL_FLAG_PM_RUNTIME) 1643 1643 1644 - static u32 fw_devlink_flags = FW_DEVLINK_FLAGS_ON; 1644 + static u32 fw_devlink_flags = FW_DEVLINK_FLAGS_RPM; 1645 1645 static int __init fw_devlink_setup(char *arg) 1646 1646 { 1647 1647 if (!arg) ··· 4944 4944 * 4945 4945 * return dev_err_probe(dev, err, ...); 4946 4946 * 4947 - * Note that it is deemed acceptable to use this function for error 4948 - * prints during probe even if the @err is known to never be -EPROBE_DEFER. 4947 + * Using this helper in your probe function is totally fine even if @err is 4948 + * known to never be -EPROBE_DEFER. 4949 4949 * The benefit compared to a normal dev_err() is the standardized format 4950 - * of the error code and the fact that the error code is returned. 4950 + * of the error code, it being emitted symbolically (i.e. you get "EAGAIN" 4951 + * instead of "-35") and the fact that the error code is returned which allows 4952 + * more compact error paths. 4951 4953 * 4952 4954 * Returns @err. 4953 - * 4954 4955 */ 4955 4956 int dev_err_probe(const struct device *dev, int err, const char *fmt, ...) 4956 4957 {
+31 -8
drivers/base/cpu.c
··· 525 525 EXPORT_SYMBOL_GPL(cpu_is_hotpluggable); 526 526 527 527 #ifdef CONFIG_GENERIC_CPU_DEVICES 528 - static DEFINE_PER_CPU(struct cpu, cpu_devices); 529 - #endif 528 + DEFINE_PER_CPU(struct cpu, cpu_devices); 529 + 530 + bool __weak arch_cpu_is_hotpluggable(int cpu) 531 + { 532 + return false; 533 + } 534 + 535 + int __weak arch_register_cpu(int cpu) 536 + { 537 + struct cpu *c = &per_cpu(cpu_devices, cpu); 538 + 539 + c->hotpluggable = arch_cpu_is_hotpluggable(cpu); 540 + 541 + return register_cpu(c, cpu); 542 + } 543 + 544 + #ifdef CONFIG_HOTPLUG_CPU 545 + void __weak arch_unregister_cpu(int num) 546 + { 547 + unregister_cpu(&per_cpu(cpu_devices, num)); 548 + } 549 + #endif /* CONFIG_HOTPLUG_CPU */ 550 + #endif /* CONFIG_GENERIC_CPU_DEVICES */ 530 551 531 552 static void __init cpu_dev_register_generic(void) 532 553 { 533 - #ifdef CONFIG_GENERIC_CPU_DEVICES 534 - int i; 554 + int i, ret; 535 555 536 - for_each_possible_cpu(i) { 537 - if (register_cpu(&per_cpu(cpu_devices, i), i)) 538 - panic("Failed to register CPU device"); 556 + if (!IS_ENABLED(CONFIG_GENERIC_CPU_DEVICES)) 557 + return; 558 + 559 + for_each_present_cpu(i) { 560 + ret = arch_register_cpu(i); 561 + if (ret) 562 + pr_warn("register_cpu %d failed (%d)\n", i, ret); 539 563 } 540 - #endif 541 564 } 542 565 543 566 #ifdef CONFIG_GENERIC_CPU_VULNERABILITIES
+1 -1
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\n"); 316 + dev_info(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();
+1 -1
drivers/base/init.c
··· 35 35 of_core_init(); 36 36 platform_bus_init(); 37 37 auxiliary_bus_init(); 38 - cpu_dev_init(); 39 38 memory_dev_init(); 40 39 node_dev_init(); 40 + cpu_dev_init(); 41 41 container_dev_init(); 42 42 }
+1 -1
drivers/base/isa.c
··· 82 82 return 0; 83 83 } 84 84 85 - static struct bus_type isa_bus_type = { 85 + static const struct bus_type isa_bus_type = { 86 86 .name = "isa", 87 87 .match = isa_bus_match, 88 88 .probe = isa_bus_probe,
+1 -1
drivers/base/memory.c
··· 68 68 static int memory_subsys_online(struct device *dev); 69 69 static int memory_subsys_offline(struct device *dev); 70 70 71 - static struct bus_type memory_subsys = { 71 + static const struct bus_type memory_subsys = { 72 72 .name = MEMORY_CLASS_NAME, 73 73 .dev_name = MEMORY_CLASS_NAME, 74 74 .online = memory_subsys_online,
+7 -4
drivers/base/node.c
··· 21 21 #include <linux/swap.h> 22 22 #include <linux/slab.h> 23 23 24 - static struct bus_type node_subsys = { 24 + static const struct bus_type node_subsys = { 25 25 .name = "node", 26 26 .dev_name = "node", 27 27 }; ··· 868 868 { 869 869 int error; 870 870 int cpu; 871 + struct node *node; 871 872 872 - node_devices[nid] = kzalloc(sizeof(struct node), GFP_KERNEL); 873 - if (!node_devices[nid]) 873 + node = kzalloc(sizeof(struct node), GFP_KERNEL); 874 + if (!node) 874 875 return -ENOMEM; 876 + 877 + INIT_LIST_HEAD(&node->access_list); 878 + node_devices[nid] = node; 875 879 876 880 error = register_node(node_devices[nid], nid); 877 881 ··· 885 881 register_cpu_under_node(cpu, nid); 886 882 } 887 883 888 - INIT_LIST_HEAD(&node_devices[nid]->access_list); 889 884 node_init_caches(nid); 890 885 891 886 return error;
+1 -1
drivers/base/power/clock_ops.c
··· 793 793 * the remaining members of @clknb should be populated prior to calling this 794 794 * routine. 795 795 */ 796 - void pm_clk_add_notifier(struct bus_type *bus, 796 + void pm_clk_add_notifier(const struct bus_type *bus, 797 797 struct pm_clk_notifier_block *clknb) 798 798 { 799 799 if (!bus || !clknb)
+1
drivers/base/property.c
··· 543 543 * @nargs: Number of arguments. Ignored if @nargs_prop is non-NULL. 544 544 * @index: Index of the reference, from zero onwards. 545 545 * @args: Result structure with reference and integer arguments. 546 + * May be NULL. 546 547 * 547 548 * Obtain a reference based on a named property in an fwnode, with 548 549 * integer arguments.
+3 -3
drivers/base/soc.c
··· 28 28 int soc_dev_num; 29 29 }; 30 30 31 - static struct bus_type soc_bus_type = { 31 + static const struct bus_type soc_bus_type = { 32 32 .name = "soc", 33 33 }; 34 34 static bool soc_bus_registered; ··· 106 106 { 107 107 struct soc_device *soc_dev = container_of(dev, struct soc_device, dev); 108 108 109 - ida_simple_remove(&soc_ida, soc_dev->soc_dev_num); 109 + ida_free(&soc_ida, soc_dev->soc_dev_num); 110 110 kfree(soc_dev->dev.groups); 111 111 kfree(soc_dev); 112 112 } ··· 155 155 soc_attr_groups[1] = soc_dev_attr->custom_attr_group; 156 156 157 157 /* Fetch a unique (reclaimable) SOC ID. */ 158 - ret = ida_simple_get(&soc_ida, 0, 0, GFP_KERNEL); 158 + ret = ida_alloc(&soc_ida, GFP_KERNEL); 159 159 if (ret < 0) 160 160 goto out3; 161 161 soc_dev->soc_dev_num = ret;
+7 -4
drivers/base/swnode.c
··· 541 541 if (nargs > NR_FWNODE_REFERENCE_ARGS) 542 542 return -EINVAL; 543 543 544 + if (!args) 545 + return 0; 546 + 544 547 args->fwnode = software_node_get(refnode); 545 548 args->nargs = nargs; 546 549 ··· 750 747 struct swnode *swnode = kobj_to_swnode(kobj); 751 748 752 749 if (swnode->parent) { 753 - ida_simple_remove(&swnode->parent->child_ids, swnode->id); 750 + ida_free(&swnode->parent->child_ids, swnode->id); 754 751 list_del(&swnode->entry); 755 752 } else { 756 - ida_simple_remove(&swnode_root_ids, swnode->id); 753 + ida_free(&swnode_root_ids, swnode->id); 757 754 } 758 755 759 756 if (swnode->allocated) ··· 779 776 if (!swnode) 780 777 return ERR_PTR(-ENOMEM); 781 778 782 - ret = ida_simple_get(parent ? &parent->child_ids : &swnode_root_ids, 783 - 0, 0, GFP_KERNEL); 779 + ret = ida_alloc(parent ? &parent->child_ids : &swnode_root_ids, 780 + GFP_KERNEL); 784 781 if (ret < 0) { 785 782 kfree(swnode); 786 783 return ERR_PTR(ret);
+1 -1
drivers/edac/edac_device.h
··· 176 176 struct edac_dev_sysfs_attribute *sysfs_attributes; 177 177 178 178 /* pointer to main 'edac' subsys in sysfs */ 179 - struct bus_type *edac_subsys; 179 + const struct bus_type *edac_subsys; 180 180 181 181 /* the internal state of this controller instance */ 182 182 int op_state;
+1 -1
drivers/edac/edac_device_sysfs.c
··· 229 229 int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev) 230 230 { 231 231 struct device *dev_root; 232 - struct bus_type *edac_subsys; 232 + const struct bus_type *edac_subsys; 233 233 int err = -ENODEV; 234 234 235 235 edac_dbg(1, "\n");
+2 -2
drivers/edac/edac_module.c
··· 67 67 * sysfs object: /sys/devices/system/edac 68 68 * need to export to other files 69 69 */ 70 - static struct bus_type edac_subsys = { 70 + static const struct bus_type edac_subsys = { 71 71 .name = "edac", 72 72 .dev_name = "edac", 73 73 }; ··· 90 90 } 91 91 92 92 /* return pointer to the 'edac' node in sysfs */ 93 - struct bus_type *edac_get_sysfs_subsys(void) 93 + const struct bus_type *edac_get_sysfs_subsys(void) 94 94 { 95 95 return &edac_subsys; 96 96 }
+1 -1
drivers/edac/edac_pci_sysfs.c
··· 338 338 static int edac_pci_main_kobj_setup(void) 339 339 { 340 340 int err = -ENODEV; 341 - struct bus_type *edac_subsys; 341 + const struct bus_type *edac_subsys; 342 342 struct device *dev_root; 343 343 344 344 edac_dbg(0, "\n");
+1 -1
drivers/pmdomain/core.c
··· 2668 2668 kfree(dev); 2669 2669 } 2670 2670 2671 - static struct bus_type genpd_bus_type = { 2671 + static const struct bus_type genpd_bus_type = { 2672 2672 .name = "genpd", 2673 2673 }; 2674 2674
+37 -25
fs/kernfs/dir.c
··· 54 54 static int kernfs_name_locked(struct kernfs_node *kn, char *buf, size_t buflen) 55 55 { 56 56 if (!kn) 57 - return strlcpy(buf, "(null)", buflen); 57 + return strscpy(buf, "(null)", buflen); 58 58 59 - return strlcpy(buf, kn->parent ? kn->name : "/", buflen); 59 + return strscpy(buf, kn->parent ? kn->name : "/", buflen); 60 60 } 61 61 62 62 /* kernfs_node_depth - compute depth from @from to @to */ ··· 127 127 * 128 128 * [3] when @kn_to is %NULL result will be "(null)" 129 129 * 130 - * Return: the length of the full path. If the full length is equal to or 130 + * Return: the length of the constructed path. If the path would have been 131 131 * greater than @buflen, @buf contains the truncated path with the trailing 132 132 * '\0'. On error, -errno is returned. 133 133 */ ··· 138 138 struct kernfs_node *kn, *common; 139 139 const char parent_str[] = "/.."; 140 140 size_t depth_from, depth_to, len = 0; 141 + ssize_t copied; 141 142 int i, j; 142 143 143 144 if (!kn_to) 144 - return strlcpy(buf, "(null)", buflen); 145 + return strscpy(buf, "(null)", buflen); 145 146 146 147 if (!kn_from) 147 148 kn_from = kernfs_root(kn_to)->kn; 148 149 149 150 if (kn_from == kn_to) 150 - return strlcpy(buf, "/", buflen); 151 + return strscpy(buf, "/", buflen); 151 152 152 153 common = kernfs_common_ancestor(kn_from, kn_to); 153 154 if (WARN_ON(!common)) ··· 159 158 160 159 buf[0] = '\0'; 161 160 162 - for (i = 0; i < depth_from; i++) 163 - len += strlcpy(buf + len, parent_str, 164 - len < buflen ? buflen - len : 0); 161 + for (i = 0; i < depth_from; i++) { 162 + copied = strscpy(buf + len, parent_str, buflen - len); 163 + if (copied < 0) 164 + return copied; 165 + len += copied; 166 + } 165 167 166 168 /* Calculate how many bytes we need for the rest */ 167 169 for (i = depth_to - 1; i >= 0; i--) { 168 170 for (kn = kn_to, j = 0; j < i; j++) 169 171 kn = kn->parent; 170 - len += strlcpy(buf + len, "/", 171 - len < buflen ? buflen - len : 0); 172 - len += strlcpy(buf + len, kn->name, 173 - len < buflen ? buflen - len : 0); 172 + 173 + len += scnprintf(buf + len, buflen - len, "/%s", kn->name); 174 174 } 175 175 176 176 return len; ··· 184 182 * @buflen: size of @buf 185 183 * 186 184 * Copies the name of @kn into @buf of @buflen bytes. The behavior is 187 - * similar to strlcpy(). 185 + * similar to strscpy(). 188 186 * 189 187 * Fills buffer with "(null)" if @kn is %NULL. 190 188 * 191 - * Return: the length of @kn's name and if @buf isn't long enough, 192 - * it's filled up to @buflen-1 and nul terminated. 189 + * Return: the resulting length of @buf. If @buf isn't long enough, 190 + * it's filled up to @buflen-1 and nul terminated, and returns -E2BIG. 193 191 * 194 192 * This function can be called from any context. 195 193 */ ··· 216 214 * path (which includes '..'s) as needed to reach from @from to @to is 217 215 * returned. 218 216 * 219 - * Return: the length of the full path. If the full length is equal to or 217 + * Return: the length of the constructed path. If the path would have been 220 218 * greater than @buflen, @buf contains the truncated path with the trailing 221 219 * '\0'. On error, -errno is returned. 222 220 */ ··· 267 265 sz = kernfs_path_from_node(kn, NULL, kernfs_pr_cont_buf, 268 266 sizeof(kernfs_pr_cont_buf)); 269 267 if (sz < 0) { 270 - pr_cont("(error)"); 271 - goto out; 272 - } 273 - 274 - if (sz >= sizeof(kernfs_pr_cont_buf)) { 275 - pr_cont("(name too long)"); 268 + if (sz == -E2BIG) 269 + pr_cont("(name too long)"); 270 + else 271 + pr_cont("(error)"); 276 272 goto out; 277 273 } 278 274 ··· 676 676 { 677 677 struct kernfs_node *kn; 678 678 679 + if (parent->mode & S_ISGID) { 680 + /* this code block imitates inode_init_owner() for 681 + * kernfs 682 + */ 683 + 684 + if (parent->iattr) 685 + gid = parent->iattr->ia_gid; 686 + 687 + if (flags & KERNFS_DIR) 688 + mode |= S_ISGID; 689 + } 690 + 679 691 kn = __kernfs_new_node(kernfs_root(parent), parent, 680 692 name, mode, uid, gid, flags); 681 693 if (kn) { ··· 862 850 const unsigned char *path, 863 851 const void *ns) 864 852 { 865 - size_t len; 853 + ssize_t len; 866 854 char *p, *name; 867 855 868 856 lockdep_assert_held_read(&kernfs_root(parent)->kernfs_rwsem); 869 857 870 858 spin_lock_irq(&kernfs_pr_cont_lock); 871 859 872 - len = strlcpy(kernfs_pr_cont_buf, path, sizeof(kernfs_pr_cont_buf)); 860 + len = strscpy(kernfs_pr_cont_buf, path, sizeof(kernfs_pr_cont_buf)); 873 861 874 - if (len >= sizeof(kernfs_pr_cont_buf)) { 862 + if (len < 0) { 875 863 spin_unlock_irq(&kernfs_pr_cont_lock); 876 864 return NULL; 877 865 }
+1 -1
fs/kernfs/file.c
··· 447 447 * warnings and we don't want to add spurious locking dependency 448 448 * between the two. Check whether mmap is actually implemented 449 449 * without grabbing @of->mutex by testing HAS_MMAP flag. See the 450 - * comment in kernfs_file_open() for more details. 450 + * comment in kernfs_fop_open() for more details. 451 451 */ 452 452 if (!(of->kn->flags & KERNFS_HAS_MMAP)) 453 453 return -ENODEV;
-3
fs/kernfs/mount.c
··· 125 125 126 126 inode = kernfs_get_inode(sb, kn); 127 127 kernfs_put(kn); 128 - if (!inode) 129 - return ERR_PTR(-ESTALE); 130 - 131 128 return d_obtain_alias(inode); 132 129 } 133 130
+1 -1
fs/sysfs/dir.c
··· 81 81 struct kernfs_node *kn = kobj->sd; 82 82 83 83 /* 84 - * In general, kboject owner is responsible for ensuring removal 84 + * In general, kobject owner is responsible for ensuring removal 85 85 * doesn't race with other operations and sysfs doesn't provide any 86 86 * protection; however, when @kobj is used as a symlink target, the 87 87 * symlinking entity usually doesn't own @kobj and thus has no
+1 -1
include/linux/container.h
··· 12 12 #include <linux/device.h> 13 13 14 14 /* drivers/base/power/container.c */ 15 - extern struct bus_type container_subsys; 15 + extern const struct bus_type container_subsys; 16 16 17 17 struct container_dev { 18 18 struct device dev;
+5
include/linux/cpu.h
··· 80 80 struct device *cpu_device_create(struct device *parent, void *drvdata, 81 81 const struct attribute_group **groups, 82 82 const char *fmt, ...); 83 + extern bool arch_cpu_is_hotpluggable(int cpu); 83 84 extern int arch_register_cpu(int cpu); 84 85 extern void arch_unregister_cpu(int cpu); 85 86 #ifdef CONFIG_HOTPLUG_CPU 86 87 extern void unregister_cpu(struct cpu *cpu); 87 88 extern ssize_t arch_cpu_probe(const char *, size_t); 88 89 extern ssize_t arch_cpu_release(const char *, size_t); 90 + #endif 91 + 92 + #ifdef CONFIG_GENERIC_CPU_DEVICES 93 + DECLARE_PER_CPU(struct cpu, cpu_devices); 89 94 #endif 90 95 91 96 /*
+3 -5
include/linux/device.h
··· 63 63 */ 64 64 struct subsys_interface { 65 65 const char *name; 66 - struct bus_type *subsys; 66 + const struct bus_type *subsys; 67 67 struct list_head node; 68 68 int (*add_dev)(struct device *dev, struct subsys_interface *sif); 69 69 void (*remove_dev)(struct device *dev, struct subsys_interface *sif); ··· 72 72 int subsys_interface_register(struct subsys_interface *sif); 73 73 void subsys_interface_unregister(struct subsys_interface *sif); 74 74 75 - int subsys_system_register(struct bus_type *subsys, 75 + int subsys_system_register(const struct bus_type *subsys, 76 76 const struct attribute_group **groups); 77 - int subsys_virtual_register(struct bus_type *subsys, 77 + int subsys_virtual_register(const struct bus_type *subsys, 78 78 const struct attribute_group **groups); 79 79 80 80 /* ··· 662 662 * @id: device instance 663 663 * @devres_lock: Spinlock to protect the resource of the device. 664 664 * @devres_head: The resources list of the device. 665 - * @knode_class: The node used to add the device to the class list. 666 665 * @class: The class of the device. 667 666 * @groups: Optional attribute groups. 668 667 * @release: Callback to free the device after all references have ··· 1072 1073 int device_move(struct device *dev, struct device *new_parent, 1073 1074 enum dpm_order dpm_order); 1074 1075 int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid); 1075 - int device_is_dependent(struct device *dev, void *target); 1076 1076 1077 1077 static inline bool device_supports_offline(struct device *dev) 1078 1078 {
+1 -1
include/linux/device/bus.h
··· 232 232 233 233 int bus_for_each_drv(const struct bus_type *bus, struct device_driver *start, 234 234 void *data, int (*fn)(struct device_driver *, void *)); 235 - void bus_sort_breadthfirst(struct bus_type *bus, 235 + void bus_sort_breadthfirst(const struct bus_type *bus, 236 236 int (*compare)(const struct device *a, 237 237 const struct device *b)); 238 238 /*
-2
include/linux/device/class.h
··· 40 40 * for the devices belonging to the class. Usually tied to 41 41 * device's namespace. 42 42 * @pm: The default device power management operations of this class. 43 - * @p: The private data of the driver core, no one other than the 44 - * driver core can touch this. 45 43 * 46 44 * A class is a higher-level view of a device that abstracts out low-level 47 45 * implementation details. Drivers may see a SCSI disk or an ATA disk, but,
+2 -2
include/linux/edac.h
··· 30 30 31 31 extern int edac_op_state; 32 32 33 - struct bus_type *edac_get_sysfs_subsys(void); 33 + const struct bus_type *edac_get_sysfs_subsys(void); 34 34 35 35 static inline void opstate_init(void) 36 36 { ··· 495 495 */ 496 496 struct mem_ctl_info { 497 497 struct device dev; 498 - struct bus_type *bus; 498 + const struct bus_type *bus; 499 499 500 500 struct list_head link; /* for global list of mem_ctl_info structs */ 501 501
+2 -2
include/linux/pm_clock.h
··· 91 91 #endif 92 92 93 93 #ifdef CONFIG_HAVE_CLK 94 - extern void pm_clk_add_notifier(struct bus_type *bus, 94 + extern void pm_clk_add_notifier(const struct bus_type *bus, 95 95 struct pm_clk_notifier_block *clknb); 96 96 #else 97 - static inline void pm_clk_add_notifier(struct bus_type *bus, 97 + static inline void pm_clk_add_notifier(const struct bus_type *bus, 98 98 struct pm_clk_notifier_block *clknb) 99 99 { 100 100 }
+17 -1
init/initramfs.c
··· 574 574 #include <linux/initrd.h> 575 575 #include <linux/kexec.h> 576 576 577 + static ssize_t raw_read(struct file *file, struct kobject *kobj, 578 + struct bin_attribute *attr, char *buf, 579 + loff_t pos, size_t count) 580 + { 581 + memcpy(buf, attr->private + pos, count); 582 + return count; 583 + } 584 + 585 + static BIN_ATTR(initrd, 0440, raw_read, NULL, 0); 586 + 577 587 void __init reserve_initrd_mem(void) 578 588 { 579 589 phys_addr_t start; ··· 725 715 * If the initrd region is overlapped with crashkernel reserved region, 726 716 * free only memory that is not part of crashkernel region. 727 717 */ 728 - if (!do_retain_initrd && initrd_start && !kexec_free_initrd()) 718 + if (!do_retain_initrd && initrd_start && !kexec_free_initrd()) { 729 719 free_initrd_mem(initrd_start, initrd_end); 720 + } else if (do_retain_initrd && initrd_start) { 721 + bin_attr_initrd.size = initrd_end - initrd_start; 722 + bin_attr_initrd.private = (void *)initrd_start; 723 + if (sysfs_create_bin_file(firmware_kobj, &bin_attr_initrd)) 724 + pr_err("Failed to create initrd sysfs file"); 725 + } 730 726 initrd_start = 0; 731 727 initrd_end = 0; 732 728
+1 -1
kernel/cgroup/cgroup-v1.c
··· 802 802 goto out_free; 803 803 804 804 ret = cgroup_path_ns(cgrp, pathbuf, PATH_MAX, &init_cgroup_ns); 805 - if (ret < 0 || ret >= PATH_MAX) 805 + if (ret < 0) 806 806 goto out_free; 807 807 808 808 argv[0] = agentbuf;
+6 -29
kernel/cgroup/cgroup.c
··· 1906 1906 len = kernfs_path_from_node(kf_node, ns_cgroup->kn, buf, PATH_MAX); 1907 1907 spin_unlock_irq(&css_set_lock); 1908 1908 1909 - if (len >= PATH_MAX) 1909 + if (len == -E2BIG) 1910 1910 len = -ERANGE; 1911 1911 else if (len > 0) { 1912 1912 seq_escape(sf, buf, " \t\n\\"); ··· 4182 4182 .seq_show = cgroup_seqfile_show, 4183 4183 }; 4184 4184 4185 - /* set uid and gid of cgroup dirs and files to that of the creator */ 4186 - static int cgroup_kn_set_ugid(struct kernfs_node *kn) 4187 - { 4188 - struct iattr iattr = { .ia_valid = ATTR_UID | ATTR_GID, 4189 - .ia_uid = current_fsuid(), 4190 - .ia_gid = current_fsgid(), }; 4191 - 4192 - if (uid_eq(iattr.ia_uid, GLOBAL_ROOT_UID) && 4193 - gid_eq(iattr.ia_gid, GLOBAL_ROOT_GID)) 4194 - return 0; 4195 - 4196 - return kernfs_setattr(kn, &iattr); 4197 - } 4198 - 4199 4185 static void cgroup_file_notify_timer(struct timer_list *timer) 4200 4186 { 4201 4187 cgroup_file_notify(container_of(timer, struct cgroup_file, ··· 4194 4208 char name[CGROUP_FILE_NAME_MAX]; 4195 4209 struct kernfs_node *kn; 4196 4210 struct lock_class_key *key = NULL; 4197 - int ret; 4198 4211 4199 4212 #ifdef CONFIG_DEBUG_LOCK_ALLOC 4200 4213 key = &cft->lockdep_key; 4201 4214 #endif 4202 4215 kn = __kernfs_create_file(cgrp->kn, cgroup_file_name(cgrp, cft, name), 4203 4216 cgroup_file_mode(cft), 4204 - GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, 4217 + current_fsuid(), current_fsgid(), 4205 4218 0, cft->kf_ops, cft, 4206 4219 NULL, key); 4207 4220 if (IS_ERR(kn)) 4208 4221 return PTR_ERR(kn); 4209 - 4210 - ret = cgroup_kn_set_ugid(kn); 4211 - if (ret) { 4212 - kernfs_remove(kn); 4213 - return ret; 4214 - } 4215 4222 4216 4223 if (cft->file_offset) { 4217 4224 struct cgroup_file *cfile = (void *)css + cft->file_offset; ··· 5608 5629 goto out_cancel_ref; 5609 5630 5610 5631 /* create the directory */ 5611 - kn = kernfs_create_dir(parent->kn, name, mode, cgrp); 5632 + kn = kernfs_create_dir_ns(parent->kn, name, mode, 5633 + current_fsuid(), current_fsgid(), 5634 + cgrp, NULL); 5612 5635 if (IS_ERR(kn)) { 5613 5636 ret = PTR_ERR(kn); 5614 5637 goto out_stat_exit; ··· 5754 5773 * that @cgrp->kn is always accessible. 5755 5774 */ 5756 5775 kernfs_get(cgrp->kn); 5757 - 5758 - ret = cgroup_kn_set_ugid(cgrp->kn); 5759 - if (ret) 5760 - goto out_destroy; 5761 5776 5762 5777 ret = css_populate_dir(&cgrp->self); 5763 5778 if (ret) ··· 6293 6316 if (cgroup_on_dfl(cgrp) || !(tsk->flags & PF_EXITING)) { 6294 6317 retval = cgroup_path_ns_locked(cgrp, buf, PATH_MAX, 6295 6318 current->nsproxy->cgroup_ns); 6296 - if (retval >= PATH_MAX) 6319 + if (retval == -E2BIG) 6297 6320 retval = -ENAMETOOLONG; 6298 6321 if (retval < 0) 6299 6322 goto out_unlock;
+1 -1
kernel/cgroup/cpuset.c
··· 5092 5092 retval = cgroup_path_ns(css->cgroup, buf, PATH_MAX, 5093 5093 current->nsproxy->cgroup_ns); 5094 5094 css_put(css); 5095 - if (retval >= PATH_MAX) 5095 + if (retval == -E2BIG) 5096 5096 retval = -ENAMETOOLONG; 5097 5097 if (retval < 0) 5098 5098 goto out_free;