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

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

Pull driver core updates from Greg KH:
"Here is a small set of patches for the driver core code for 6.12-rc1.

This set is the one that caused the most delay on my side, due to lots
of last-minute reports of problems in the async shutdown feature that
was added. In the end, I've reverted all of the patches in that series
so we are back to "normal" and the patch set is being reworked for the
next merge window.

Other than the async shutdown patches that were reverted, included in
here are:

- minor driver core cleanups

- minor driver core bus and class api cleanups and simplifications
for some callbacks

- some const markings of structures

- other even more minor cleanups

All of these, including the last minute reverts, have been in
linux-next, but all of the reports of problems in linux-next were
before the reverts happened. After the reverts, all is good"

* tag 'driver-core-6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (32 commits)
Revert "driver core: don't always lock parent in shutdown"
Revert "driver core: separate function to shutdown one device"
Revert "driver core: shut down devices asynchronously"
Revert "nvme-pci: Make driver prefer asynchronous shutdown"
Revert "driver core: fix async device shutdown hang"
driver core: fix async device shutdown hang
driver core: attribute_container: Remove unused functions
driver core: Trivially simplify ((struct device_private *)curr)->device->p to @curr
devres: Correclty strip percpu address space of devm_free_percpu() argument
driver core: Make parameter check consistent for API cluster device_(for_each|find)_child()
bus: fsl-mc: make fsl_mc_bus_type const
nvme-pci: Make driver prefer asynchronous shutdown
driver core: shut down devices asynchronously
driver core: separate function to shutdown one device
driver core: don't always lock parent in shutdown
platform: Make platform_bus_type constant
driver core: class: Check namespace relevant parameters in class_register()
driver:base:core: Adding a "Return:" line in comment for device_link_add()
drivers/base: Introduce device_match_t for device finding APIs
firmware_loader: Block path traversal
...

+165 -164
+1 -47
drivers/base/attribute_container.c
··· 346 346 * @fn: the function to execute for each classdev. 347 347 * 348 348 * This function is for executing a trigger when you need to know both 349 - * the container and the classdev. If you only care about the 350 - * container, then use attribute_container_trigger() instead. 349 + * the container and the classdev. 351 350 */ 352 351 void 353 352 attribute_container_device_trigger(struct device *dev, ··· 373 374 if (dev == ic->classdev.parent) 374 375 fn(cont, dev, &ic->classdev); 375 376 } 376 - } 377 - mutex_unlock(&attribute_container_mutex); 378 - } 379 - 380 - /** 381 - * attribute_container_trigger - trigger a function for each matching container 382 - * 383 - * @dev: The generic device to activate the trigger for 384 - * @fn: the function to trigger 385 - * 386 - * This routine triggers a function that only needs to know the 387 - * matching containers (not the classdev) associated with a device. 388 - * It is more lightweight than attribute_container_device_trigger, so 389 - * should be used in preference unless the triggering function 390 - * actually needs to know the classdev. 391 - */ 392 - void 393 - attribute_container_trigger(struct device *dev, 394 - int (*fn)(struct attribute_container *, 395 - struct device *)) 396 - { 397 - struct attribute_container *cont; 398 - 399 - mutex_lock(&attribute_container_mutex); 400 - list_for_each_entry(cont, &attribute_container_list, node) { 401 - if (cont->match(cont, dev)) 402 - fn(cont, dev); 403 377 } 404 378 mutex_unlock(&attribute_container_mutex); 405 379 } ··· 428 456 if (error) 429 457 return error; 430 458 return attribute_container_add_attrs(classdev); 431 - } 432 - 433 - /** 434 - * attribute_container_add_class_device_adapter - simple adapter for triggers 435 - * 436 - * @cont: the container to register. 437 - * @dev: the generic device to activate the trigger for 438 - * @classdev: the class device to add 439 - * 440 - * This function is identical to attribute_container_add_class_device except 441 - * that it is designed to be called from the triggers 442 - */ 443 - int 444 - attribute_container_add_class_device_adapter(struct attribute_container *cont, 445 - struct device *dev, 446 - struct device *classdev) 447 - { 448 - return attribute_container_add_class_device(classdev); 449 459 } 450 460 451 461 /**
+1 -1
drivers/base/auxiliary.c
··· 352 352 */ 353 353 struct auxiliary_device *auxiliary_find_device(struct device *start, 354 354 const void *data, 355 - int (*match)(struct device *dev, const void *data)) 355 + device_match_t match) 356 356 { 357 357 struct device *dev; 358 358
+1 -1
drivers/base/base.h
··· 145 145 static inline void auxiliary_bus_init(void) { } 146 146 #endif 147 147 148 - struct kobject *virtual_device_parent(struct device *dev); 148 + struct kobject *virtual_device_parent(void); 149 149 150 150 int bus_add_device(struct device *dev); 151 151 void bus_probe_device(struct device *dev);
+14 -5
drivers/base/bus.c
··· 152 152 { 153 153 struct bus_attribute *bus_attr = to_bus_attr(attr); 154 154 struct subsys_private *subsys_priv = to_subsys_private(kobj); 155 - ssize_t ret = 0; 155 + /* return -EIO for reading a bus attribute without show() */ 156 + ssize_t ret = -EIO; 156 157 157 158 if (bus_attr->show) 158 159 ret = bus_attr->show(subsys_priv->bus, buf); ··· 165 164 { 166 165 struct bus_attribute *bus_attr = to_bus_attr(attr); 167 166 struct subsys_private *subsys_priv = to_subsys_private(kobj); 168 - ssize_t ret = 0; 167 + /* return -EIO for writing a bus attribute without store() */ 168 + ssize_t ret = -EIO; 169 169 170 170 if (bus_attr->store) 171 171 ret = bus_attr->store(subsys_priv->bus, buf, count); ··· 391 389 */ 392 390 struct device *bus_find_device(const struct bus_type *bus, 393 391 struct device *start, const void *data, 394 - int (*match)(struct device *dev, const void *data)) 392 + device_match_t match) 395 393 { 396 394 struct subsys_private *sp = bus_to_subsys(bus); 397 395 struct klist_iter i; ··· 922 920 bus_remove_file(bus, &bus_attr_uevent); 923 921 bus_uevent_fail: 924 922 kset_unregister(&priv->subsys); 923 + /* Above kset_unregister() will kfree @priv */ 924 + priv = NULL; 925 925 out: 926 926 kfree(priv); 927 927 return retval; ··· 1298 1294 { 1299 1295 struct kobject *virtual_dir; 1300 1296 1301 - virtual_dir = virtual_device_parent(NULL); 1297 + virtual_dir = virtual_device_parent(); 1302 1298 if (!virtual_dir) 1303 1299 return -ENOMEM; 1304 1300 ··· 1389 1385 return -ENOMEM; 1390 1386 1391 1387 system_kset = kset_create_and_add("system", NULL, &devices_kset->kobj); 1392 - if (!system_kset) 1388 + if (!system_kset) { 1389 + /* Do error handling here as devices_init() do */ 1390 + kset_unregister(bus_kset); 1391 + bus_kset = NULL; 1392 + pr_err("%s: failed to create and add kset 'bus'\n", __func__); 1393 1393 return -ENOMEM; 1394 + } 1394 1395 1395 1396 return 0; 1396 1397 }
+12 -2
drivers/base/class.c
··· 183 183 184 184 pr_debug("device class '%s': registering\n", cls->name); 185 185 186 + if (cls->ns_type && !cls->namespace) { 187 + pr_err("%s: class '%s' does not have namespace\n", 188 + __func__, cls->name); 189 + return -EINVAL; 190 + } 191 + if (!cls->ns_type && cls->namespace) { 192 + pr_err("%s: class '%s' does not have ns_type\n", 193 + __func__, cls->name); 194 + return -EINVAL; 195 + } 196 + 186 197 cp = kzalloc(sizeof(*cp), GFP_KERNEL); 187 198 if (!cp) 188 199 return -ENOMEM; ··· 444 433 * code. There's no locking restriction. 445 434 */ 446 435 struct device *class_find_device(const struct class *class, const struct device *start, 447 - const void *data, 448 - int (*match)(struct device *, const void *)) 436 + const void *data, device_match_t match) 449 437 { 450 438 struct subsys_private *sp = class_to_subsys(class); 451 439 struct class_dev_iter iter;
+83 -85
drivers/base/core.c
··· 9 9 */ 10 10 11 11 #include <linux/acpi.h> 12 + #include <linux/blkdev.h> 13 + #include <linux/cleanup.h> 12 14 #include <linux/cpufreq.h> 13 15 #include <linux/device.h> 16 + #include <linux/dma-map-ops.h> /* for dma_default_coherent */ 14 17 #include <linux/err.h> 15 18 #include <linux/fwnode.h> 16 19 #include <linux/init.h> 20 + #include <linux/kdev_t.h> 17 21 #include <linux/kstrtox.h> 18 22 #include <linux/module.h> 19 - #include <linux/slab.h> 20 - #include <linux/kdev_t.h> 23 + #include <linux/mutex.h> 24 + #include <linux/netdevice.h> 21 25 #include <linux/notifier.h> 22 26 #include <linux/of.h> 23 27 #include <linux/of_device.h> 24 - #include <linux/blkdev.h> 25 - #include <linux/mutex.h> 26 28 #include <linux/pm_runtime.h> 27 - #include <linux/netdevice.h> 28 29 #include <linux/rcupdate.h> 29 - #include <linux/sched/signal.h> 30 30 #include <linux/sched/mm.h> 31 + #include <linux/sched/signal.h> 32 + #include <linux/slab.h> 31 33 #include <linux/string_helpers.h> 32 34 #include <linux/swiotlb.h> 33 35 #include <linux/sysfs.h> 34 - #include <linux/dma-map-ops.h> /* for dma_default_coherent */ 35 36 36 37 #include "base.h" 37 38 #include "physical_location.h" ··· 98 97 int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup, 99 98 u8 flags) 100 99 { 101 - int ret; 100 + guard(mutex)(&fwnode_link_lock); 102 101 103 - mutex_lock(&fwnode_link_lock); 104 - ret = __fwnode_link_add(con, sup, flags); 105 - mutex_unlock(&fwnode_link_lock); 106 - return ret; 102 + return __fwnode_link_add(con, sup, flags); 107 103 } 108 104 109 105 /** ··· 141 143 { 142 144 struct fwnode_link *link, *tmp; 143 145 144 - mutex_lock(&fwnode_link_lock); 146 + guard(mutex)(&fwnode_link_lock); 147 + 145 148 list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook) 146 149 __fwnode_link_del(link); 147 - mutex_unlock(&fwnode_link_lock); 148 150 } 149 151 150 152 /** ··· 157 159 { 158 160 struct fwnode_link *link, *tmp; 159 161 160 - mutex_lock(&fwnode_link_lock); 162 + guard(mutex)(&fwnode_link_lock); 163 + 161 164 list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook) 162 165 __fwnode_link_del(link); 163 - mutex_unlock(&fwnode_link_lock); 164 166 } 165 167 166 168 /** ··· 561 563 562 564 static int devlink_add_symlinks(struct device *dev) 563 565 { 566 + char *buf_con __free(kfree) = NULL, *buf_sup __free(kfree) = NULL; 564 567 int ret; 565 - size_t len; 566 568 struct device_link *link = to_devlink(dev); 567 569 struct device *sup = link->supplier; 568 570 struct device *con = link->consumer; 569 - char *buf; 570 - 571 - len = max(strlen(dev_bus_name(sup)) + strlen(dev_name(sup)), 572 - strlen(dev_bus_name(con)) + strlen(dev_name(con))); 573 - len += strlen(":"); 574 - len += strlen("supplier:") + 1; 575 - buf = kzalloc(len, GFP_KERNEL); 576 - if (!buf) 577 - return -ENOMEM; 578 571 579 572 ret = sysfs_create_link(&link->link_dev.kobj, &sup->kobj, "supplier"); 580 573 if (ret) ··· 575 586 if (ret) 576 587 goto err_con; 577 588 578 - snprintf(buf, len, "consumer:%s:%s", dev_bus_name(con), dev_name(con)); 579 - ret = sysfs_create_link(&sup->kobj, &link->link_dev.kobj, buf); 589 + buf_con = kasprintf(GFP_KERNEL, "consumer:%s:%s", dev_bus_name(con), dev_name(con)); 590 + if (!buf_con) { 591 + ret = -ENOMEM; 592 + goto err_con_dev; 593 + } 594 + 595 + ret = sysfs_create_link(&sup->kobj, &link->link_dev.kobj, buf_con); 580 596 if (ret) 581 597 goto err_con_dev; 582 598 583 - snprintf(buf, len, "supplier:%s:%s", dev_bus_name(sup), dev_name(sup)); 584 - ret = sysfs_create_link(&con->kobj, &link->link_dev.kobj, buf); 599 + buf_sup = kasprintf(GFP_KERNEL, "supplier:%s:%s", dev_bus_name(sup), dev_name(sup)); 600 + if (!buf_sup) { 601 + ret = -ENOMEM; 602 + goto err_sup_dev; 603 + } 604 + 605 + ret = sysfs_create_link(&con->kobj, &link->link_dev.kobj, buf_sup); 585 606 if (ret) 586 607 goto err_sup_dev; 587 608 588 609 goto out; 589 610 590 611 err_sup_dev: 591 - snprintf(buf, len, "consumer:%s:%s", dev_bus_name(con), dev_name(con)); 592 - sysfs_remove_link(&sup->kobj, buf); 612 + sysfs_remove_link(&sup->kobj, buf_con); 593 613 err_con_dev: 594 614 sysfs_remove_link(&link->link_dev.kobj, "consumer"); 595 615 err_con: 596 616 sysfs_remove_link(&link->link_dev.kobj, "supplier"); 597 617 out: 598 - kfree(buf); 599 618 return ret; 600 619 } 601 620 602 621 static void devlink_remove_symlinks(struct device *dev) 603 622 { 623 + char *buf_con __free(kfree) = NULL, *buf_sup __free(kfree) = NULL; 604 624 struct device_link *link = to_devlink(dev); 605 - size_t len; 606 625 struct device *sup = link->supplier; 607 626 struct device *con = link->consumer; 608 - char *buf; 609 627 610 628 sysfs_remove_link(&link->link_dev.kobj, "consumer"); 611 629 sysfs_remove_link(&link->link_dev.kobj, "supplier"); 612 630 613 - len = max(strlen(dev_bus_name(sup)) + strlen(dev_name(sup)), 614 - strlen(dev_bus_name(con)) + strlen(dev_name(con))); 615 - len += strlen(":"); 616 - len += strlen("supplier:") + 1; 617 - buf = kzalloc(len, GFP_KERNEL); 618 - if (!buf) { 619 - WARN(1, "Unable to properly free device link symlinks!\n"); 620 - return; 631 + if (device_is_registered(con)) { 632 + buf_sup = kasprintf(GFP_KERNEL, "supplier:%s:%s", dev_bus_name(sup), dev_name(sup)); 633 + if (!buf_sup) 634 + goto out; 635 + sysfs_remove_link(&con->kobj, buf_sup); 621 636 } 622 637 623 - if (device_is_registered(con)) { 624 - snprintf(buf, len, "supplier:%s:%s", dev_bus_name(sup), dev_name(sup)); 625 - sysfs_remove_link(&con->kobj, buf); 626 - } 627 - snprintf(buf, len, "consumer:%s:%s", dev_bus_name(con), dev_name(con)); 628 - sysfs_remove_link(&sup->kobj, buf); 629 - kfree(buf); 638 + buf_con = kasprintf(GFP_KERNEL, "consumer:%s:%s", dev_bus_name(con), dev_name(con)); 639 + if (!buf_con) 640 + goto out; 641 + sysfs_remove_link(&sup->kobj, buf_con); 642 + 643 + return; 644 + 645 + out: 646 + WARN(1, "Unable to properly free device link symlinks!\n"); 630 647 } 631 648 632 649 static struct class_interface devlink_class_intf = { ··· 672 677 * @consumer: Consumer end of the link. 673 678 * @supplier: Supplier end of the link. 674 679 * @flags: Link flags. 680 + * 681 + * Return: On success, a device_link struct will be returned. 682 + * On error or invalid flag settings, NULL will be returned. 675 683 * 676 684 * The caller is responsible for the proper synchronization of the link creation 677 685 * with runtime PM. First, setting the DL_FLAG_PM_RUNTIME flag will cause the ··· 1059 1061 * Device waiting for supplier to become available is not allowed to 1060 1062 * probe. 1061 1063 */ 1062 - mutex_lock(&fwnode_link_lock); 1063 - sup_fw = fwnode_links_check_suppliers(dev->fwnode); 1064 - if (sup_fw) { 1065 - if (!dev_is_best_effort(dev)) { 1066 - fwnode_ret = -EPROBE_DEFER; 1067 - dev_err_probe(dev, -EPROBE_DEFER, 1068 - "wait for supplier %pfwf\n", sup_fw); 1069 - } else { 1070 - fwnode_ret = -EAGAIN; 1064 + scoped_guard(mutex, &fwnode_link_lock) { 1065 + sup_fw = fwnode_links_check_suppliers(dev->fwnode); 1066 + if (sup_fw) { 1067 + if (dev_is_best_effort(dev)) 1068 + fwnode_ret = -EAGAIN; 1069 + else 1070 + return dev_err_probe(dev, -EPROBE_DEFER, 1071 + "wait for supplier %pfwf\n", sup_fw); 1071 1072 } 1072 1073 } 1073 - mutex_unlock(&fwnode_link_lock); 1074 - if (fwnode_ret == -EPROBE_DEFER) 1075 - return fwnode_ret; 1076 1074 1077 1075 device_links_write_lock(); 1078 1076 ··· 1087 1093 } 1088 1094 1089 1095 device_links_missing_supplier(dev); 1090 - dev_err_probe(dev, -EPROBE_DEFER, 1091 - "supplier %s not ready\n", 1092 - dev_name(link->supplier)); 1093 - ret = -EPROBE_DEFER; 1096 + ret = dev_err_probe(dev, -EPROBE_DEFER, 1097 + "supplier %s not ready\n", dev_name(link->supplier)); 1094 1098 break; 1095 1099 } 1096 1100 WRITE_ONCE(link->status, DL_STATE_CONSUMER_PROBE); ··· 1241 1249 bool val; 1242 1250 1243 1251 device_lock(dev); 1244 - mutex_lock(&fwnode_link_lock); 1245 - val = !!fwnode_links_check_suppliers(dev->fwnode); 1246 - mutex_unlock(&fwnode_link_lock); 1252 + scoped_guard(mutex, &fwnode_link_lock) 1253 + val = !!fwnode_links_check_suppliers(dev->fwnode); 1247 1254 device_unlock(dev); 1248 1255 return sysfs_emit(buf, "%u\n", val); 1249 1256 } ··· 1315 1324 */ 1316 1325 if (dev->fwnode && dev->fwnode->dev == dev) { 1317 1326 struct fwnode_handle *child; 1327 + 1318 1328 fwnode_links_purge_suppliers(dev->fwnode); 1319 - mutex_lock(&fwnode_link_lock); 1329 + 1330 + guard(mutex)(&fwnode_link_lock); 1331 + 1320 1332 fwnode_for_each_available_child_node(dev->fwnode, child) 1321 1333 __fw_devlink_pickup_dangling_consumers(child, 1322 1334 dev->fwnode); 1323 1335 __fw_devlink_link_to_consumers(dev); 1324 - mutex_unlock(&fwnode_link_lock); 1325 1336 } 1326 1337 device_remove_file(dev, &dev_attr_waiting_for_supplier); 1327 1338 ··· 2332 2339 2333 2340 fw_devlink_parse_fwtree(fwnode); 2334 2341 2335 - mutex_lock(&fwnode_link_lock); 2342 + guard(mutex)(&fwnode_link_lock); 2343 + 2336 2344 __fw_devlink_link_to_consumers(dev); 2337 2345 __fw_devlink_link_to_suppliers(dev, fwnode); 2338 - mutex_unlock(&fwnode_link_lock); 2339 2346 } 2340 2347 2341 2348 /* Device links support end. */ ··· 2584 2591 const struct device *dev = kobj_to_dev(kobj); 2585 2592 const void *ns = NULL; 2586 2593 2587 - if (dev->class && dev->class->ns_type) 2594 + if (dev->class && dev->class->namespace) 2588 2595 ns = dev->class->namespace(dev); 2589 2596 2590 2597 return ns; ··· 3163 3170 } 3164 3171 EXPORT_SYMBOL_GPL(device_initialize); 3165 3172 3166 - struct kobject *virtual_device_parent(struct device *dev) 3173 + struct kobject *virtual_device_parent(void) 3167 3174 { 3168 3175 static struct kobject *virtual_dir = NULL; 3169 3176 ··· 3241 3248 * in a "glue" directory to prevent namespace collisions. 3242 3249 */ 3243 3250 if (parent == NULL) 3244 - parent_kobj = virtual_device_parent(dev); 3251 + parent_kobj = virtual_device_parent(); 3245 3252 else if (parent->class && !dev->class->ns_type) { 3246 3253 subsys_put(sp); 3247 3254 return &parent->kobj; ··· 3996 4003 struct device *child; 3997 4004 int error = 0; 3998 4005 3999 - if (!parent->p) 4006 + if (!parent || !parent->p) 4000 4007 return 0; 4001 4008 4002 4009 klist_iter_init(&parent->p->klist_children, &i); ··· 4026 4033 struct device *child; 4027 4034 int error = 0; 4028 4035 4029 - if (!parent->p) 4036 + if (!parent || !parent->p) 4030 4037 return 0; 4031 4038 4032 4039 klist_iter_init(&parent->p->klist_children, &i); ··· 4060 4067 struct klist_iter i; 4061 4068 struct device *child; 4062 4069 4063 - if (!parent) 4070 + if (!parent || !parent->p) 4064 4071 return NULL; 4065 4072 4066 4073 klist_iter_init(&parent->p->klist_children, &i); ··· 4508 4515 */ 4509 4516 int device_rename(struct device *dev, const char *new_name) 4510 4517 { 4518 + struct subsys_private *sp = NULL; 4511 4519 struct kobject *kobj = &dev->kobj; 4512 4520 char *old_device_name = NULL; 4513 4521 int error; 4522 + bool is_link_renamed = false; 4514 4523 4515 4524 dev = get_device(dev); 4516 4525 if (!dev) ··· 4527 4532 } 4528 4533 4529 4534 if (dev->class) { 4530 - struct subsys_private *sp = class_to_subsys(dev->class); 4535 + sp = class_to_subsys(dev->class); 4531 4536 4532 4537 if (!sp) { 4533 4538 error = -EINVAL; ··· 4536 4541 4537 4542 error = sysfs_rename_link_ns(&sp->subsys.kobj, kobj, old_device_name, 4538 4543 new_name, kobject_namespace(kobj)); 4539 - subsys_put(sp); 4540 4544 if (error) 4541 4545 goto out; 4546 + 4547 + is_link_renamed = true; 4542 4548 } 4543 4549 4544 4550 error = kobject_rename(kobj, new_name); 4545 - if (error) 4546 - goto out; 4547 - 4548 4551 out: 4552 + if (error && is_link_renamed) 4553 + sysfs_rename_link_ns(&sp->subsys.kobj, kobj, new_name, 4554 + old_device_name, kobject_namespace(kobj)); 4555 + subsys_put(sp); 4556 + 4549 4557 put_device(dev); 4550 4558 4551 4559 kfree(old_device_name); ··· 4870 4872 else 4871 4873 return; 4872 4874 4873 - strscpy(dev_info->subsystem, subsys, sizeof(dev_info->subsystem)); 4875 + strscpy(dev_info->subsystem, subsys); 4874 4876 4875 4877 /* 4876 4878 * Add device identifier DEVICE=:
+1 -1
drivers/base/dd.c
··· 248 248 249 249 list_for_each_entry(curr, &deferred_probe_pending_list, deferred_probe) 250 250 seq_printf(s, "%s\t%s", dev_name(curr->device), 251 - curr->device->p->deferred_probe_reason ?: "\n"); 251 + curr->deferred_probe_reason ?: "\n"); 252 252 253 253 mutex_unlock(&deferred_probe_mutex); 254 254
+1 -1
drivers/base/devres.c
··· 1231 1231 * devm_free_pages() does. 1232 1232 */ 1233 1233 WARN_ON(devres_release(dev, devm_percpu_release, devm_percpu_match, 1234 - (__force void *)pdata)); 1234 + (void *)(__force unsigned long)pdata)); 1235 1235 } 1236 1236 EXPORT_SYMBOL_GPL(devm_free_percpu);
+1 -1
drivers/base/driver.c
··· 150 150 */ 151 151 struct device *driver_find_device(const struct device_driver *drv, 152 152 struct device *start, const void *data, 153 - int (*match)(struct device *dev, const void *data)) 153 + device_match_t match) 154 154 { 155 155 struct klist_iter i; 156 156 struct device *dev;
+30
drivers/base/firmware_loader/main.c
··· 849 849 {} 850 850 #endif 851 851 852 + /* 853 + * Reject firmware file names with ".." path components. 854 + * There are drivers that construct firmware file names from device-supplied 855 + * strings, and we don't want some device to be able to tell us "I would like to 856 + * be sent my firmware from ../../../etc/shadow, please". 857 + * 858 + * Search for ".." surrounded by either '/' or start/end of string. 859 + * 860 + * This intentionally only looks at the firmware name, not at the firmware base 861 + * directory or at symlink contents. 862 + */ 863 + static bool name_contains_dotdot(const char *name) 864 + { 865 + size_t name_len = strlen(name); 866 + 867 + return strcmp(name, "..") == 0 || strncmp(name, "../", 3) == 0 || 868 + strstr(name, "/../") != NULL || 869 + (name_len >= 3 && strcmp(name+name_len-3, "/..") == 0); 870 + } 871 + 852 872 /* called from request_firmware() and request_firmware_work_func() */ 853 873 static int 854 874 _request_firmware(const struct firmware **firmware_p, const char *name, ··· 885 865 return -EINVAL; 886 866 887 867 if (!name || name[0] == '\0') { 868 + ret = -EINVAL; 869 + goto out; 870 + } 871 + 872 + if (name_contains_dotdot(name)) { 873 + dev_warn(device, 874 + "Firmware load for '%s' refused, path contains '..' component\n", 875 + name); 888 876 ret = -EINVAL; 889 877 goto out; 890 878 } ··· 974 946 * @name will be used as $FIRMWARE in the uevent environment and 975 947 * should be distinctive enough not to be confused with any other 976 948 * firmware image for this or any other device. 949 + * It must not contain any ".." path components - "foo/bar..bin" is 950 + * allowed, but "foo/../bar.bin" is not. 977 951 * 978 952 * Caller must hold the reference count of @device. 979 953 *
+9 -5
drivers/base/module.c
··· 66 66 driver_name = make_driver_name(drv); 67 67 if (!driver_name) { 68 68 ret = -ENOMEM; 69 - goto out; 69 + goto out_remove_kobj; 70 70 } 71 71 72 72 module_create_drivers_dir(mk); 73 73 if (!mk->drivers_dir) { 74 74 ret = -EINVAL; 75 - goto out; 75 + goto out_free_driver_name; 76 76 } 77 77 78 78 ret = sysfs_create_link(mk->drivers_dir, &drv->p->kobj, driver_name); 79 79 if (ret) 80 - goto out; 80 + goto out_remove_drivers_dir; 81 81 82 82 kfree(driver_name); 83 83 84 84 return 0; 85 - out: 86 - sysfs_remove_link(&drv->p->kobj, "module"); 85 + 86 + out_remove_drivers_dir: 87 87 sysfs_remove_link(mk->drivers_dir, driver_name); 88 + 89 + out_free_driver_name: 88 90 kfree(driver_name); 89 91 92 + out_remove_kobj: 93 + sysfs_remove_link(&drv->p->kobj, "module"); 90 94 return ret; 91 95 } 92 96
+1 -1
drivers/base/platform.c
··· 1474 1474 USE_PLATFORM_PM_SLEEP_OPS 1475 1475 }; 1476 1476 1477 - struct bus_type platform_bus_type = { 1477 + const struct bus_type platform_bus_type = { 1478 1478 .name = "platform", 1479 1479 .dev_groups = platform_dev_groups, 1480 1480 .match = platform_match,
+1 -1
drivers/bus/fsl-mc/fsl-mc-bus.c
··· 309 309 310 310 ATTRIBUTE_GROUPS(fsl_mc_bus); 311 311 312 - struct bus_type fsl_mc_bus_type = { 312 + const struct bus_type fsl_mc_bus_type = { 313 313 .name = "fsl-mc", 314 314 .match = fsl_mc_bus_match, 315 315 .uevent = fsl_mc_bus_uevent,
-6
include/linux/attribute_container.h
··· 61 61 int (*undo)(struct attribute_container *, 62 62 struct device *, 63 63 struct device *)); 64 - void attribute_container_trigger(struct device *dev, 65 - int (*fn)(struct attribute_container *, 66 - struct device *)); 67 64 int attribute_container_add_attrs(struct device *classdev); 68 65 int attribute_container_add_class_device(struct device *classdev); 69 - int attribute_container_add_class_device_adapter(struct attribute_container *cont, 70 - struct device *dev, 71 - struct device *classdev); 72 66 void attribute_container_remove_attrs(struct device *classdev); 73 67 void attribute_container_class_device_del(struct device *classdev); 74 68 struct attribute_container *attribute_container_classdev_to_container(struct device *);
+1 -1
include/linux/auxiliary_bus.h
··· 271 271 272 272 struct auxiliary_device *auxiliary_find_device(struct device *start, 273 273 const void *data, 274 - int (*match)(struct device *dev, const void *data)); 274 + device_match_t match); 275 275 276 276 #endif /* _AUXILIARY_BUS_H_ */
+4 -2
include/linux/device/bus.h
··· 126 126 int __must_check bus_create_file(const struct bus_type *bus, struct bus_attribute *attr); 127 127 void bus_remove_file(const struct bus_type *bus, struct bus_attribute *attr); 128 128 129 + /* Matching function type for drivers/base APIs to find a specific device */ 130 + typedef int (*device_match_t)(struct device *dev, const void *data); 131 + 129 132 /* Generic device matching functions that all busses can use to match with */ 130 133 int device_match_name(struct device *dev, const void *name); 131 134 int device_match_of_node(struct device *dev, const void *np); ··· 142 139 int bus_for_each_dev(const struct bus_type *bus, struct device *start, void *data, 143 140 int (*fn)(struct device *dev, void *data)); 144 141 struct device *bus_find_device(const struct bus_type *bus, struct device *start, 145 - const void *data, 146 - int (*match)(struct device *dev, const void *data)); 142 + const void *data, device_match_t match); 147 143 /** 148 144 * bus_find_device_by_name - device iterator for locating a particular device 149 145 * of a specific name.
+1 -1
include/linux/device/class.h
··· 95 95 int class_for_each_device(const struct class *class, const struct device *start, void *data, 96 96 int (*fn)(struct device *dev, void *data)); 97 97 struct device *class_find_device(const struct class *class, const struct device *start, 98 - const void *data, int (*match)(struct device *, const void *)); 98 + const void *data, device_match_t match); 99 99 100 100 /** 101 101 * class_find_device_by_name - device iterator for locating a particular device
+1 -1
include/linux/device/driver.h
··· 157 157 void *data, int (*fn)(struct device *dev, void *)); 158 158 struct device *driver_find_device(const struct device_driver *drv, 159 159 struct device *start, const void *data, 160 - int (*match)(struct device *dev, const void *data)); 160 + device_match_t match); 161 161 162 162 /** 163 163 * driver_find_device_by_name - device iterator for locating a particular device
+1 -1
include/linux/fsl/mc.h
··· 436 436 struct fsl_mc_device *fsl_mc_get_endpoint(struct fsl_mc_device *mc_dev, 437 437 u16 if_id); 438 438 439 - extern struct bus_type fsl_mc_bus_type; 439 + extern const struct bus_type fsl_mc_bus_type; 440 440 441 441 extern struct device_type fsl_mc_bus_dprc_type; 442 442 extern struct device_type fsl_mc_bus_dpni_type;
+1 -1
include/linux/platform_device.h
··· 52 52 extern int platform_device_register(struct platform_device *); 53 53 extern void platform_device_unregister(struct platform_device *); 54 54 55 - extern struct bus_type platform_bus_type; 55 + extern const struct bus_type platform_bus_type; 56 56 extern struct device platform_bus; 57 57 58 58 extern struct resource *platform_get_resource(struct platform_device *,