diff options
-rw-r--r-- | Documentation/dell_rbu.txt | 5 | ||||
-rw-r--r-- | Documentation/driver-api/firmware/fallback-mechanisms.rst | 14 | ||||
-rw-r--r-- | Documentation/driver-api/firmware/firmware_cache.rst | 4 | ||||
-rw-r--r-- | Documentation/driver-api/firmware/request_firmware.rst | 5 | ||||
-rw-r--r-- | drivers/base/Kconfig | 90 | ||||
-rw-r--r-- | drivers/base/bus.c | 16 | ||||
-rw-r--r-- | drivers/base/core.c | 18 | ||||
-rw-r--r-- | drivers/base/dd.c | 8 | ||||
-rw-r--r-- | drivers/base/driver.c | 6 | ||||
-rw-r--r-- | drivers/base/firmware_loader/Kconfig | 154 | ||||
-rw-r--r-- | drivers/base/firmware_loader/fallback.c | 53 | ||||
-rw-r--r-- | drivers/base/firmware_loader/fallback.h | 18 | ||||
-rw-r--r-- | drivers/base/firmware_loader/firmware.h | 37 | ||||
-rw-r--r-- | drivers/base/firmware_loader/main.c | 57 | ||||
-rw-r--r-- | drivers/base/memory.c | 8 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath10k/core.c | 2 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath10k/testmode.c | 2 | ||||
-rw-r--r-- | drivers/usb/core/driver.c | 1 | ||||
-rw-r--r-- | fs/debugfs/file.c | 10 | ||||
-rw-r--r-- | fs/debugfs/inode.c | 4 | ||||
-rw-r--r-- | fs/kernfs/file.c | 8 | ||||
-rw-r--r-- | include/linux/device.h | 4 | ||||
-rw-r--r-- | include/linux/firmware.h | 10 |
23 files changed, 372 insertions, 162 deletions
diff --git a/Documentation/dell_rbu.txt b/Documentation/dell_rbu.txt index 0fdb6aa2704c..5d1ce7bcd04d 100644 --- a/Documentation/dell_rbu.txt +++ b/Documentation/dell_rbu.txt | |||
@@ -121,10 +121,7 @@ read back the image downloaded. | |||
121 | 121 | ||
122 | .. note:: | 122 | .. note:: |
123 | 123 | ||
124 | This driver requires a patch for firmware_class.c which has the modified | 124 | After updating the BIOS image a user mode application needs to execute |
125 | request_firmware_nowait function. | ||
126 | |||
127 | Also after updating the BIOS image a user mode application needs to execute | ||
128 | code which sends the BIOS update request to the BIOS. So on the next reboot | 125 | code which sends the BIOS update request to the BIOS. So on the next reboot |
129 | the BIOS knows about the new image downloaded and it updates itself. | 126 | the BIOS knows about the new image downloaded and it updates itself. |
130 | Also don't unload the rbu driver if the image has to be updated. | 127 | Also don't unload the rbu driver if the image has to be updated. |
diff --git a/Documentation/driver-api/firmware/fallback-mechanisms.rst b/Documentation/driver-api/firmware/fallback-mechanisms.rst index f353783ae0be..d35fed65eae9 100644 --- a/Documentation/driver-api/firmware/fallback-mechanisms.rst +++ b/Documentation/driver-api/firmware/fallback-mechanisms.rst | |||
@@ -72,9 +72,12 @@ the firmware requested, and establishes it in the device hierarchy by | |||
72 | associating the device used to make the request as the device's parent. | 72 | associating the device used to make the request as the device's parent. |
73 | The sysfs directory's file attributes are defined and controlled through | 73 | The sysfs directory's file attributes are defined and controlled through |
74 | the new device's class (firmware_class) and group (fw_dev_attr_groups). | 74 | the new device's class (firmware_class) and group (fw_dev_attr_groups). |
75 | This is actually where the original firmware_class.c file name comes from, | 75 | This is actually where the original firmware_class module name came from, |
76 | as originally the only firmware loading mechanism available was the | 76 | given that originally the only firmware loading mechanism available was the |
77 | mechanism we now use as a fallback mechanism. | 77 | mechanism we now use as a fallback mechanism, which registers a struct class |
78 | firmware_class. Because the attributes exposed are part of the module name, the | ||
79 | module name firmware_class cannot be renamed in the future, to ensure backward | ||
80 | compatibility with old userspace. | ||
78 | 81 | ||
79 | To load firmware using the sysfs interface we expose a loading indicator, | 82 | To load firmware using the sysfs interface we expose a loading indicator, |
80 | and a file upload firmware into: | 83 | and a file upload firmware into: |
@@ -83,7 +86,7 @@ and a file upload firmware into: | |||
83 | * /sys/$DEVPATH/data | 86 | * /sys/$DEVPATH/data |
84 | 87 | ||
85 | To upload firmware you will echo 1 onto the loading file to indicate | 88 | To upload firmware you will echo 1 onto the loading file to indicate |
86 | you are loading firmware. You then cat the firmware into the data file, | 89 | you are loading firmware. You then write the firmware into the data file, |
87 | and you notify the kernel the firmware is ready by echo'ing 0 onto | 90 | and you notify the kernel the firmware is ready by echo'ing 0 onto |
88 | the loading file. | 91 | the loading file. |
89 | 92 | ||
@@ -136,7 +139,8 @@ by kobject uevents. This is specially exacerbated due to the fact that most | |||
136 | distributions today disable CONFIG_FW_LOADER_USER_HELPER_FALLBACK. | 139 | distributions today disable CONFIG_FW_LOADER_USER_HELPER_FALLBACK. |
137 | 140 | ||
138 | Refer to do_firmware_uevent() for details of the kobject event variables | 141 | Refer to do_firmware_uevent() for details of the kobject event variables |
139 | setup. Variables passwdd with a kobject add event: | 142 | setup. The variables currently passed to userspace with a "kobject add" |
143 | event are: | ||
140 | 144 | ||
141 | * FIRMWARE=firmware name | 145 | * FIRMWARE=firmware name |
142 | * TIMEOUT=timeout value | 146 | * TIMEOUT=timeout value |
diff --git a/Documentation/driver-api/firmware/firmware_cache.rst b/Documentation/driver-api/firmware/firmware_cache.rst index 2210e5bfb332..c2e69d9c6bf1 100644 --- a/Documentation/driver-api/firmware/firmware_cache.rst +++ b/Documentation/driver-api/firmware/firmware_cache.rst | |||
@@ -29,8 +29,8 @@ Some implementation details about the firmware cache setup: | |||
29 | * If an asynchronous call is used the firmware cache is only set up for a | 29 | * If an asynchronous call is used the firmware cache is only set up for a |
30 | device if if the second argument (uevent) to request_firmware_nowait() is | 30 | device if if the second argument (uevent) to request_firmware_nowait() is |
31 | true. When uevent is true it requests that a kobject uevent be sent to | 31 | true. When uevent is true it requests that a kobject uevent be sent to |
32 | userspace for the firmware request. For details refer to the Fackback | 32 | userspace for the firmware request through the sysfs fallback mechanism |
33 | mechanism documented below. | 33 | if the firmware file is not found. |
34 | 34 | ||
35 | * If the firmware cache is determined to be needed as per the above two | 35 | * If the firmware cache is determined to be needed as per the above two |
36 | criteria the firmware cache is setup by adding a devres entry for the | 36 | criteria the firmware cache is setup by adding a devres entry for the |
diff --git a/Documentation/driver-api/firmware/request_firmware.rst b/Documentation/driver-api/firmware/request_firmware.rst index d5ec95a7195b..f62bdcbfed5b 100644 --- a/Documentation/driver-api/firmware/request_firmware.rst +++ b/Documentation/driver-api/firmware/request_firmware.rst | |||
@@ -20,6 +20,11 @@ request_firmware | |||
20 | .. kernel-doc:: drivers/base/firmware_loader/main.c | 20 | .. kernel-doc:: drivers/base/firmware_loader/main.c |
21 | :functions: request_firmware | 21 | :functions: request_firmware |
22 | 22 | ||
23 | firmware_request_nowarn | ||
24 | ----------------------- | ||
25 | .. kernel-doc:: drivers/base/firmware_loader/main.c | ||
26 | :functions: firmware_request_nowarn | ||
27 | |||
23 | request_firmware_direct | 28 | request_firmware_direct |
24 | ----------------------- | 29 | ----------------------- |
25 | .. kernel-doc:: drivers/base/firmware_loader/main.c | 30 | .. kernel-doc:: drivers/base/firmware_loader/main.c |
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index 29b0eb452b3a..3e63a900b330 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig | |||
@@ -70,81 +70,25 @@ config STANDALONE | |||
70 | If unsure, say Y. | 70 | If unsure, say Y. |
71 | 71 | ||
72 | config PREVENT_FIRMWARE_BUILD | 72 | config PREVENT_FIRMWARE_BUILD |
73 | bool "Prevent firmware from being built" | 73 | bool "Disable drivers features which enable custom firmware building" |
74 | default y | 74 | default y |
75 | help | 75 | help |
76 | Say yes to avoid building firmware. Firmware is usually shipped | 76 | Say yes to disable driver features which enable building a custom |
77 | with the driver and only when updating the firmware should a | 77 | driver firmware at kernel build time. These drivers do not use the |
78 | rebuild be made. | 78 | kernel firmware API to load firmware (CONFIG_FW_LOADER), instead they |
79 | If unsure, say Y here. | 79 | use their own custom loading mechanism. The required firmware is |
80 | 80 | usually shipped with the driver, building the driver firmware | |
81 | config FW_LOADER | 81 | should only be needed if you have an updated firmware source. |
82 | tristate "Userspace firmware loading support" if EXPERT | 82 | |
83 | default y | 83 | Firmware should not be being built as part of kernel, these days |
84 | ---help--- | 84 | you should always prevent this and say Y here. There are only two |
85 | This option is provided for the case where none of the in-tree modules | 85 | old drivers which enable building of its firmware at kernel build |
86 | require userspace firmware loading support, but a module built | 86 | time: |
87 | out-of-tree does. | 87 | |
88 | 88 | o CONFIG_WANXL through CONFIG_WANXL_BUILD_FIRMWARE | |
89 | config EXTRA_FIRMWARE | 89 | o CONFIG_SCSI_AIC79XX through CONFIG_AIC79XX_BUILD_FIRMWARE |
90 | string "External firmware blobs to build into the kernel binary" | 90 | |
91 | depends on FW_LOADER | 91 | source "drivers/base/firmware_loader/Kconfig" |
92 | help | ||
93 | Various drivers in the kernel source tree may require firmware, | ||
94 | which is generally available in your distribution's linux-firmware | ||
95 | package. | ||
96 | |||
97 | The linux-firmware package should install firmware into | ||
98 | /lib/firmware/ on your system, so they can be loaded by userspace | ||
99 | helpers on request. | ||
100 | |||
101 | This option allows firmware to be built into the kernel for the case | ||
102 | where the user either cannot or doesn't want to provide it from | ||
103 | userspace at runtime (for example, when the firmware in question is | ||
104 | required for accessing the boot device, and the user doesn't want to | ||
105 | use an initrd). | ||
106 | |||
107 | This option is a string and takes the (space-separated) names of the | ||
108 | firmware files -- the same names that appear in MODULE_FIRMWARE() | ||
109 | and request_firmware() in the source. These files should exist under | ||
110 | the directory specified by the EXTRA_FIRMWARE_DIR option, which is | ||
111 | /lib/firmware by default. | ||
112 | |||
113 | For example, you might set CONFIG_EXTRA_FIRMWARE="usb8388.bin", copy | ||
114 | the usb8388.bin file into /lib/firmware, and build the kernel. Then | ||
115 | any request_firmware("usb8388.bin") will be satisfied internally | ||
116 | without needing to call out to userspace. | ||
117 | |||
118 | WARNING: If you include additional firmware files into your binary | ||
119 | kernel image that are not available under the terms of the GPL, | ||
120 | then it may be a violation of the GPL to distribute the resulting | ||
121 | image since it combines both GPL and non-GPL work. You should | ||
122 | consult a lawyer of your own before distributing such an image. | ||
123 | |||
124 | config EXTRA_FIRMWARE_DIR | ||
125 | string "Firmware blobs root directory" | ||
126 | depends on EXTRA_FIRMWARE != "" | ||
127 | default "/lib/firmware" | ||
128 | help | ||
129 | This option controls the directory in which the kernel build system | ||
130 | looks for the firmware files listed in the EXTRA_FIRMWARE option. | ||
131 | |||
132 | config FW_LOADER_USER_HELPER | ||
133 | bool | ||
134 | |||
135 | config FW_LOADER_USER_HELPER_FALLBACK | ||
136 | bool "Fallback user-helper invocation for firmware loading" | ||
137 | depends on FW_LOADER | ||
138 | select FW_LOADER_USER_HELPER | ||
139 | help | ||
140 | This option enables / disables the invocation of user-helper | ||
141 | (e.g. udev) for loading firmware files as a fallback after the | ||
142 | direct file loading in kernel fails. The user-mode helper is | ||
143 | no longer required unless you have a special firmware file that | ||
144 | resides in a non-standard path. Moreover, the udev support has | ||
145 | been deprecated upstream. | ||
146 | |||
147 | If you are unsure about this, say N here. | ||
148 | 92 | ||
149 | config WANT_DEV_COREDUMP | 93 | config WANT_DEV_COREDUMP |
150 | bool | 94 | bool |
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index ef6183306b40..8bfd27ec73d6 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c | |||
@@ -184,10 +184,10 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf, | |||
184 | 184 | ||
185 | dev = bus_find_device_by_name(bus, NULL, buf); | 185 | dev = bus_find_device_by_name(bus, NULL, buf); |
186 | if (dev && dev->driver == drv) { | 186 | if (dev && dev->driver == drv) { |
187 | if (dev->parent) /* Needed for USB */ | 187 | if (dev->parent && dev->bus->need_parent_lock) |
188 | device_lock(dev->parent); | 188 | device_lock(dev->parent); |
189 | device_release_driver(dev); | 189 | device_release_driver(dev); |
190 | if (dev->parent) | 190 | if (dev->parent && dev->bus->need_parent_lock) |
191 | device_unlock(dev->parent); | 191 | device_unlock(dev->parent); |
192 | err = count; | 192 | err = count; |
193 | } | 193 | } |
@@ -211,12 +211,12 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf, | |||
211 | 211 | ||
212 | dev = bus_find_device_by_name(bus, NULL, buf); | 212 | dev = bus_find_device_by_name(bus, NULL, buf); |
213 | if (dev && dev->driver == NULL && driver_match_device(drv, dev)) { | 213 | if (dev && dev->driver == NULL && driver_match_device(drv, dev)) { |
214 | if (dev->parent) /* Needed for USB */ | 214 | if (dev->parent && bus->need_parent_lock) |
215 | device_lock(dev->parent); | 215 | device_lock(dev->parent); |
216 | device_lock(dev); | 216 | device_lock(dev); |
217 | err = driver_probe_device(drv, dev); | 217 | err = driver_probe_device(drv, dev); |
218 | device_unlock(dev); | 218 | device_unlock(dev); |
219 | if (dev->parent) | 219 | if (dev->parent && bus->need_parent_lock) |
220 | device_unlock(dev->parent); | 220 | device_unlock(dev->parent); |
221 | 221 | ||
222 | if (err > 0) { | 222 | if (err > 0) { |
@@ -735,10 +735,10 @@ static int __must_check bus_rescan_devices_helper(struct device *dev, | |||
735 | int ret = 0; | 735 | int ret = 0; |
736 | 736 | ||
737 | if (!dev->driver) { | 737 | if (!dev->driver) { |
738 | if (dev->parent) /* Needed for USB */ | 738 | if (dev->parent && dev->bus->need_parent_lock) |
739 | device_lock(dev->parent); | 739 | device_lock(dev->parent); |
740 | ret = device_attach(dev); | 740 | ret = device_attach(dev); |
741 | if (dev->parent) | 741 | if (dev->parent && dev->bus->need_parent_lock) |
742 | device_unlock(dev->parent); | 742 | device_unlock(dev->parent); |
743 | } | 743 | } |
744 | return ret < 0 ? ret : 0; | 744 | return ret < 0 ? ret : 0; |
@@ -770,10 +770,10 @@ EXPORT_SYMBOL_GPL(bus_rescan_devices); | |||
770 | int device_reprobe(struct device *dev) | 770 | int device_reprobe(struct device *dev) |
771 | { | 771 | { |
772 | if (dev->driver) { | 772 | if (dev->driver) { |
773 | if (dev->parent) /* Needed for USB */ | 773 | if (dev->parent && dev->bus->need_parent_lock) |
774 | device_lock(dev->parent); | 774 | device_lock(dev->parent); |
775 | device_release_driver(dev); | 775 | device_release_driver(dev); |
776 | if (dev->parent) | 776 | if (dev->parent && dev->bus->need_parent_lock) |
777 | device_unlock(dev->parent); | 777 | device_unlock(dev->parent); |
778 | } | 778 | } |
779 | return bus_rescan_devices_helper(dev, NULL); | 779 | return bus_rescan_devices_helper(dev, NULL); |
diff --git a/drivers/base/core.c b/drivers/base/core.c index ad7b50897bcc..36622b52e419 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -1487,7 +1487,7 @@ class_dir_create_and_add(struct class *class, struct kobject *parent_kobj) | |||
1487 | 1487 | ||
1488 | dir = kzalloc(sizeof(*dir), GFP_KERNEL); | 1488 | dir = kzalloc(sizeof(*dir), GFP_KERNEL); |
1489 | if (!dir) | 1489 | if (!dir) |
1490 | return NULL; | 1490 | return ERR_PTR(-ENOMEM); |
1491 | 1491 | ||
1492 | dir->class = class; | 1492 | dir->class = class; |
1493 | kobject_init(&dir->kobj, &class_dir_ktype); | 1493 | kobject_init(&dir->kobj, &class_dir_ktype); |
@@ -1497,7 +1497,7 @@ class_dir_create_and_add(struct class *class, struct kobject *parent_kobj) | |||
1497 | retval = kobject_add(&dir->kobj, parent_kobj, "%s", class->name); | 1497 | retval = kobject_add(&dir->kobj, parent_kobj, "%s", class->name); |
1498 | if (retval < 0) { | 1498 | if (retval < 0) { |
1499 | kobject_put(&dir->kobj); | 1499 | kobject_put(&dir->kobj); |
1500 | return NULL; | 1500 | return ERR_PTR(retval); |
1501 | } | 1501 | } |
1502 | return &dir->kobj; | 1502 | return &dir->kobj; |
1503 | } | 1503 | } |
@@ -1804,6 +1804,10 @@ int device_add(struct device *dev) | |||
1804 | 1804 | ||
1805 | parent = get_device(dev->parent); | 1805 | parent = get_device(dev->parent); |
1806 | kobj = get_device_parent(dev, parent); | 1806 | kobj = get_device_parent(dev, parent); |
1807 | if (IS_ERR(kobj)) { | ||
1808 | error = PTR_ERR(kobj); | ||
1809 | goto parent_error; | ||
1810 | } | ||
1807 | if (kobj) | 1811 | if (kobj) |
1808 | dev->kobj.parent = kobj; | 1812 | dev->kobj.parent = kobj; |
1809 | 1813 | ||
@@ -1902,6 +1906,7 @@ done: | |||
1902 | kobject_del(&dev->kobj); | 1906 | kobject_del(&dev->kobj); |
1903 | Error: | 1907 | Error: |
1904 | cleanup_glue_dir(dev, glue_dir); | 1908 | cleanup_glue_dir(dev, glue_dir); |
1909 | parent_error: | ||
1905 | put_device(parent); | 1910 | put_device(parent); |
1906 | name_error: | 1911 | name_error: |
1907 | kfree(dev->p); | 1912 | kfree(dev->p); |
@@ -2426,7 +2431,7 @@ static void device_create_release(struct device *dev) | |||
2426 | kfree(dev); | 2431 | kfree(dev); |
2427 | } | 2432 | } |
2428 | 2433 | ||
2429 | static struct device * | 2434 | static __printf(6, 0) struct device * |
2430 | device_create_groups_vargs(struct class *class, struct device *parent, | 2435 | device_create_groups_vargs(struct class *class, struct device *parent, |
2431 | dev_t devt, void *drvdata, | 2436 | dev_t devt, void *drvdata, |
2432 | const struct attribute_group **groups, | 2437 | const struct attribute_group **groups, |
@@ -2704,7 +2709,7 @@ static int device_move_class_links(struct device *dev, | |||
2704 | /** | 2709 | /** |
2705 | * device_move - moves a device to a new parent | 2710 | * device_move - moves a device to a new parent |
2706 | * @dev: the pointer to the struct device to be moved | 2711 | * @dev: the pointer to the struct device to be moved |
2707 | * @new_parent: the new parent of the device (can by NULL) | 2712 | * @new_parent: the new parent of the device (can be NULL) |
2708 | * @dpm_order: how to reorder the dpm_list | 2713 | * @dpm_order: how to reorder the dpm_list |
2709 | */ | 2714 | */ |
2710 | int device_move(struct device *dev, struct device *new_parent, | 2715 | int device_move(struct device *dev, struct device *new_parent, |
@@ -2721,6 +2726,11 @@ int device_move(struct device *dev, struct device *new_parent, | |||
2721 | device_pm_lock(); | 2726 | device_pm_lock(); |
2722 | new_parent = get_device(new_parent); | 2727 | new_parent = get_device(new_parent); |
2723 | new_parent_kobj = get_device_parent(dev, new_parent); | 2728 | new_parent_kobj = get_device_parent(dev, new_parent); |
2729 | if (IS_ERR(new_parent_kobj)) { | ||
2730 | error = PTR_ERR(new_parent_kobj); | ||
2731 | put_device(new_parent); | ||
2732 | goto out; | ||
2733 | } | ||
2724 | 2734 | ||
2725 | pr_debug("device: '%s': %s: moving to '%s'\n", dev_name(dev), | 2735 | pr_debug("device: '%s': %s: moving to '%s'\n", dev_name(dev), |
2726 | __func__, new_parent ? dev_name(new_parent) : "<NULL>"); | 2736 | __func__, new_parent ? dev_name(new_parent) : "<NULL>"); |
diff --git a/drivers/base/dd.c b/drivers/base/dd.c index a41c91bfac0e..fb4e2df68d95 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c | |||
@@ -814,13 +814,13 @@ static int __driver_attach(struct device *dev, void *data) | |||
814 | return ret; | 814 | return ret; |
815 | } /* ret > 0 means positive match */ | 815 | } /* ret > 0 means positive match */ |
816 | 816 | ||
817 | if (dev->parent) /* Needed for USB */ | 817 | if (dev->parent && dev->bus->need_parent_lock) |
818 | device_lock(dev->parent); | 818 | device_lock(dev->parent); |
819 | device_lock(dev); | 819 | device_lock(dev); |
820 | if (!dev->driver) | 820 | if (!dev->driver) |
821 | driver_probe_device(drv, dev); | 821 | driver_probe_device(drv, dev); |
822 | device_unlock(dev); | 822 | device_unlock(dev); |
823 | if (dev->parent) | 823 | if (dev->parent && dev->bus->need_parent_lock) |
824 | device_unlock(dev->parent); | 824 | device_unlock(dev->parent); |
825 | 825 | ||
826 | return 0; | 826 | return 0; |
@@ -916,7 +916,7 @@ void device_release_driver_internal(struct device *dev, | |||
916 | struct device_driver *drv, | 916 | struct device_driver *drv, |
917 | struct device *parent) | 917 | struct device *parent) |
918 | { | 918 | { |
919 | if (parent) | 919 | if (parent && dev->bus->need_parent_lock) |
920 | device_lock(parent); | 920 | device_lock(parent); |
921 | 921 | ||
922 | device_lock(dev); | 922 | device_lock(dev); |
@@ -924,7 +924,7 @@ void device_release_driver_internal(struct device *dev, | |||
924 | __device_release_driver(dev, parent); | 924 | __device_release_driver(dev, parent); |
925 | 925 | ||
926 | device_unlock(dev); | 926 | device_unlock(dev); |
927 | if (parent) | 927 | if (parent && dev->bus->need_parent_lock) |
928 | device_unlock(parent); | 928 | device_unlock(parent); |
929 | } | 929 | } |
930 | 930 | ||
diff --git a/drivers/base/driver.c b/drivers/base/driver.c index ba912558a510..857c8f1b876e 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c | |||
@@ -148,7 +148,11 @@ int driver_register(struct device_driver *drv) | |||
148 | int ret; | 148 | int ret; |
149 | struct device_driver *other; | 149 | struct device_driver *other; |
150 | 150 | ||
151 | BUG_ON(!drv->bus->p); | 151 | if (!drv->bus->p) { |
152 | pr_err("Driver '%s' was unable to register with bus_type '%s' because the bus was not initialized.\n", | ||
153 | drv->name, drv->bus->name); | ||
154 | return -EINVAL; | ||
155 | } | ||
152 | 156 | ||
153 | if ((drv->bus->probe && drv->probe) || | 157 | if ((drv->bus->probe && drv->probe) || |
154 | (drv->bus->remove && drv->remove) || | 158 | (drv->bus->remove && drv->remove) || |
diff --git a/drivers/base/firmware_loader/Kconfig b/drivers/base/firmware_loader/Kconfig new file mode 100644 index 000000000000..eb15d976a9ea --- /dev/null +++ b/drivers/base/firmware_loader/Kconfig | |||
@@ -0,0 +1,154 @@ | |||
1 | menu "Firmware loader" | ||
2 | |||
3 | config FW_LOADER | ||
4 | tristate "Firmware loading facility" if EXPERT | ||
5 | default y | ||
6 | help | ||
7 | This enables the firmware loading facility in the kernel. The kernel | ||
8 | will first look for built-in firmware, if it has any. Next, it will | ||
9 | look for the requested firmware in a series of filesystem paths: | ||
10 | |||
11 | o firmware_class path module parameter or kernel boot param | ||
12 | o /lib/firmware/updates/UTS_RELEASE | ||
13 | o /lib/firmware/updates | ||
14 | o /lib/firmware/UTS_RELEASE | ||
15 | o /lib/firmware | ||
16 | |||
17 | Enabling this feature only increases your kernel image by about | ||
18 | 828 bytes, enable this option unless you are certain you don't | ||
19 | need firmware. | ||
20 | |||
21 | You typically want this built-in (=y) but you can also enable this | ||
22 | as a module, in which case the firmware_class module will be built. | ||
23 | You also want to be sure to enable this built-in if you are going to | ||
24 | enable built-in firmware (CONFIG_EXTRA_FIRMWARE). | ||
25 | |||
26 | if FW_LOADER | ||
27 | |||
28 | config EXTRA_FIRMWARE | ||
29 | string "Build named firmware blobs into the kernel binary" | ||
30 | help | ||
31 | Device drivers which require firmware can typically deal with | ||
32 | having the kernel load firmware from the various supported | ||
33 | /lib/firmware/ paths. This option enables you to build into the | ||
34 | kernel firmware files. Built-in firmware searches are preceded | ||
35 | over firmware lookups using your filesystem over the supported | ||
36 | /lib/firmware paths documented on CONFIG_FW_LOADER. | ||
37 | |||
38 | This may be useful for testing or if the firmware is required early on | ||
39 | in boot and cannot rely on the firmware being placed in an initrd or | ||
40 | initramfs. | ||
41 | |||
42 | This option is a string and takes the (space-separated) names of the | ||
43 | firmware files -- the same names that appear in MODULE_FIRMWARE() | ||
44 | and request_firmware() in the source. These files should exist under | ||
45 | the directory specified by the EXTRA_FIRMWARE_DIR option, which is | ||
46 | /lib/firmware by default. | ||
47 | |||
48 | For example, you might set CONFIG_EXTRA_FIRMWARE="usb8388.bin", copy | ||
49 | the usb8388.bin file into /lib/firmware, and build the kernel. Then | ||
50 | any request_firmware("usb8388.bin") will be satisfied internally | ||
51 | inside the kernel without ever looking at your filesystem at runtime. | ||
52 | |||
53 | WARNING: If you include additional firmware files into your binary | ||
54 | kernel image that are not available under the terms of the GPL, | ||
55 | then it may be a violation of the GPL to distribute the resulting | ||
56 | image since it combines both GPL and non-GPL work. You should | ||
57 | consult a lawyer of your own before distributing such an image. | ||
58 | |||
59 | config EXTRA_FIRMWARE_DIR | ||
60 | string "Firmware blobs root directory" | ||
61 | depends on EXTRA_FIRMWARE != "" | ||
62 | default "/lib/firmware" | ||
63 | help | ||
64 | This option controls the directory in which the kernel build system | ||
65 | looks for the firmware files listed in the EXTRA_FIRMWARE option. | ||
66 | |||
67 | config FW_LOADER_USER_HELPER | ||
68 | bool "Enable the firmware sysfs fallback mechanism" | ||
69 | help | ||
70 | This option enables a sysfs loading facility to enable firmware | ||
71 | loading to the kernel through userspace as a fallback mechanism | ||
72 | if and only if the kernel's direct filesystem lookup for the | ||
73 | firmware failed using the different /lib/firmware/ paths, or the | ||
74 | path specified in the firmware_class path module parameter, or the | ||
75 | firmware_class path kernel boot parameter if the firmware_class is | ||
76 | built-in. For details on how to work with the sysfs fallback mechanism | ||
77 | refer to Documentation/driver-api/firmware/fallback-mechanisms.rst. | ||
78 | |||
79 | The direct filesystem lookup for firmware is always used first now. | ||
80 | |||
81 | If the kernel's direct filesystem lookup for firmware fails to find | ||
82 | the requested firmware a sysfs fallback loading facility is made | ||
83 | available and userspace is informed about this through uevents. | ||
84 | The uevent can be suppressed if the driver explicitly requested it, | ||
85 | this is known as the driver using the custom fallback mechanism. | ||
86 | If the custom fallback mechanism is used userspace must always | ||
87 | acknowledge failure to find firmware as the timeout for the fallback | ||
88 | mechanism is disabled, and failed requests will linger forever. | ||
89 | |||
90 | This used to be the default firmware loading facility, and udev used | ||
91 | to listen for uvents to load firmware for the kernel. The firmware | ||
92 | loading facility functionality in udev has been removed, as such it | ||
93 | can no longer be relied upon as a fallback mechanism. Linux no longer | ||
94 | relies on or uses a fallback mechanism in userspace. If you need to | ||
95 | rely on one refer to the permissively licensed firmwared: | ||
96 | |||
97 | https://github.com/teg/firmwared | ||
98 | |||
99 | Since this was the default firmware loading facility at one point, | ||
100 | old userspace may exist which relies upon it, and as such this | ||
101 | mechanism can never be removed from the kernel. | ||
102 | |||
103 | You should only enable this functionality if you are certain you | ||
104 | require a fallback mechanism and have a userspace mechanism ready to | ||
105 | load firmware in case it is not found. One main reason for this may | ||
106 | be if you have drivers which require firmware built-in and for | ||
107 | whatever reason cannot place the required firmware in initramfs. | ||
108 | Another reason kernels may have this feature enabled is to support a | ||
109 | driver which explicitly relies on this fallback mechanism. Only two | ||
110 | drivers need this today: | ||
111 | |||
112 | o CONFIG_LEDS_LP55XX_COMMON | ||
113 | o CONFIG_DELL_RBU | ||
114 | |||
115 | Outside of supporting the above drivers, another reason for needing | ||
116 | this may be that your firmware resides outside of the paths the kernel | ||
117 | looks for and cannot possibly be specified using the firmware_class | ||
118 | path module parameter or kernel firmware_class path boot parameter | ||
119 | if firmware_class is built-in. | ||
120 | |||
121 | A modern use case may be to temporarily mount a custom partition | ||
122 | during provisioning which is only accessible to userspace, and then | ||
123 | to use it to look for and fetch the required firmware. Such type of | ||
124 | driver functionality may not even ever be desirable upstream by | ||
125 | vendors, and as such is only required to be supported as an interface | ||
126 | for provisioning. Since udev's firmware loading facility has been | ||
127 | removed you can use firmwared or a fork of it to customize how you | ||
128 | want to load firmware based on uevents issued. | ||
129 | |||
130 | Enabling this option will increase your kernel image size by about | ||
131 | 13436 bytes. | ||
132 | |||
133 | If you are unsure about this, say N here, unless you are Linux | ||
134 | distribution and need to support the above two drivers, or you are | ||
135 | certain you need to support some really custom firmware loading | ||
136 | facility in userspace. | ||
137 | |||
138 | config FW_LOADER_USER_HELPER_FALLBACK | ||
139 | bool "Force the firmware sysfs fallback mechanism when possible" | ||
140 | depends on FW_LOADER_USER_HELPER | ||
141 | help | ||
142 | Enabling this option forces a sysfs userspace fallback mechanism | ||
143 | to be used for all firmware requests which explicitly do not disable a | ||
144 | a fallback mechanism. Firmware calls which do prohibit a fallback | ||
145 | mechanism is request_firmware_direct(). This option is kept for | ||
146 | backward compatibility purposes given this precise mechanism can also | ||
147 | be enabled by setting the proc sysctl value to true: | ||
148 | |||
149 | /proc/sys/kernel/firmware_config/force_sysfs_fallback | ||
150 | |||
151 | If you are unsure about this, say N here. | ||
152 | |||
153 | endif # FW_LOADER | ||
154 | endmenu | ||
diff --git a/drivers/base/firmware_loader/fallback.c b/drivers/base/firmware_loader/fallback.c index 358354148dec..b676a99c469c 100644 --- a/drivers/base/firmware_loader/fallback.c +++ b/drivers/base/firmware_loader/fallback.c | |||
@@ -125,7 +125,7 @@ static ssize_t timeout_show(struct class *class, struct class_attribute *attr, | |||
125 | } | 125 | } |
126 | 126 | ||
127 | /** | 127 | /** |
128 | * firmware_timeout_store - set number of seconds to wait for firmware | 128 | * firmware_timeout_store() - set number of seconds to wait for firmware |
129 | * @class: device class pointer | 129 | * @class: device class pointer |
130 | * @attr: device attribute pointer | 130 | * @attr: device attribute pointer |
131 | * @buf: buffer to scan for timeout value | 131 | * @buf: buffer to scan for timeout value |
@@ -239,7 +239,7 @@ static int map_fw_priv_pages(struct fw_priv *fw_priv) | |||
239 | } | 239 | } |
240 | 240 | ||
241 | /** | 241 | /** |
242 | * firmware_loading_store - set value in the 'loading' control file | 242 | * firmware_loading_store() - set value in the 'loading' control file |
243 | * @dev: device pointer | 243 | * @dev: device pointer |
244 | * @attr: device attribute pointer | 244 | * @attr: device attribute pointer |
245 | * @buf: buffer to scan for loading control value | 245 | * @buf: buffer to scan for loading control value |
@@ -431,7 +431,7 @@ static int fw_realloc_pages(struct fw_sysfs *fw_sysfs, int min_size) | |||
431 | } | 431 | } |
432 | 432 | ||
433 | /** | 433 | /** |
434 | * firmware_data_write - write method for firmware | 434 | * firmware_data_write() - write method for firmware |
435 | * @filp: open sysfs file | 435 | * @filp: open sysfs file |
436 | * @kobj: kobject for the device | 436 | * @kobj: kobject for the device |
437 | * @bin_attr: bin_attr structure | 437 | * @bin_attr: bin_attr structure |
@@ -512,7 +512,7 @@ static const struct attribute_group *fw_dev_attr_groups[] = { | |||
512 | 512 | ||
513 | static struct fw_sysfs * | 513 | static struct fw_sysfs * |
514 | fw_create_instance(struct firmware *firmware, const char *fw_name, | 514 | fw_create_instance(struct firmware *firmware, const char *fw_name, |
515 | struct device *device, unsigned int opt_flags) | 515 | struct device *device, enum fw_opt opt_flags) |
516 | { | 516 | { |
517 | struct fw_sysfs *fw_sysfs; | 517 | struct fw_sysfs *fw_sysfs; |
518 | struct device *f_dev; | 518 | struct device *f_dev; |
@@ -537,7 +537,7 @@ exit: | |||
537 | } | 537 | } |
538 | 538 | ||
539 | /** | 539 | /** |
540 | * fw_load_sysfs_fallback - load a firmware via the sysfs fallback mechanism | 540 | * fw_load_sysfs_fallback() - load a firmware via the sysfs fallback mechanism |
541 | * @fw_sysfs: firmware sysfs information for the firmware to load | 541 | * @fw_sysfs: firmware sysfs information for the firmware to load |
542 | * @opt_flags: flags of options, FW_OPT_* | 542 | * @opt_flags: flags of options, FW_OPT_* |
543 | * @timeout: timeout to wait for the load | 543 | * @timeout: timeout to wait for the load |
@@ -545,7 +545,7 @@ exit: | |||
545 | * In charge of constructing a sysfs fallback interface for firmware loading. | 545 | * In charge of constructing a sysfs fallback interface for firmware loading. |
546 | **/ | 546 | **/ |
547 | static int fw_load_sysfs_fallback(struct fw_sysfs *fw_sysfs, | 547 | static int fw_load_sysfs_fallback(struct fw_sysfs *fw_sysfs, |
548 | unsigned int opt_flags, long timeout) | 548 | enum fw_opt opt_flags, long timeout) |
549 | { | 549 | { |
550 | int retval = 0; | 550 | int retval = 0; |
551 | struct device *f_dev = &fw_sysfs->dev; | 551 | struct device *f_dev = &fw_sysfs->dev; |
@@ -599,7 +599,7 @@ err_put_dev: | |||
599 | 599 | ||
600 | static int fw_load_from_user_helper(struct firmware *firmware, | 600 | static int fw_load_from_user_helper(struct firmware *firmware, |
601 | const char *name, struct device *device, | 601 | const char *name, struct device *device, |
602 | unsigned int opt_flags) | 602 | enum fw_opt opt_flags) |
603 | { | 603 | { |
604 | struct fw_sysfs *fw_sysfs; | 604 | struct fw_sysfs *fw_sysfs; |
605 | long timeout; | 605 | long timeout; |
@@ -640,7 +640,7 @@ out_unlock: | |||
640 | return ret; | 640 | return ret; |
641 | } | 641 | } |
642 | 642 | ||
643 | static bool fw_force_sysfs_fallback(unsigned int opt_flags) | 643 | static bool fw_force_sysfs_fallback(enum fw_opt opt_flags) |
644 | { | 644 | { |
645 | if (fw_fallback_config.force_sysfs_fallback) | 645 | if (fw_fallback_config.force_sysfs_fallback) |
646 | return true; | 646 | return true; |
@@ -649,7 +649,7 @@ static bool fw_force_sysfs_fallback(unsigned int opt_flags) | |||
649 | return true; | 649 | return true; |
650 | } | 650 | } |
651 | 651 | ||
652 | static bool fw_run_sysfs_fallback(unsigned int opt_flags) | 652 | static bool fw_run_sysfs_fallback(enum fw_opt opt_flags) |
653 | { | 653 | { |
654 | if (fw_fallback_config.ignore_sysfs_fallback) { | 654 | if (fw_fallback_config.ignore_sysfs_fallback) { |
655 | pr_info_once("Ignoring firmware sysfs fallback due to sysctl knob\n"); | 655 | pr_info_once("Ignoring firmware sysfs fallback due to sysctl knob\n"); |
@@ -662,14 +662,39 @@ static bool fw_run_sysfs_fallback(unsigned int opt_flags) | |||
662 | return fw_force_sysfs_fallback(opt_flags); | 662 | return fw_force_sysfs_fallback(opt_flags); |
663 | } | 663 | } |
664 | 664 | ||
665 | int fw_sysfs_fallback(struct firmware *fw, const char *name, | 665 | /** |
666 | struct device *device, | 666 | * firmware_fallback_sysfs() - use the fallback mechanism to find firmware |
667 | unsigned int opt_flags, | 667 | * @fw: pointer to firmware image |
668 | int ret) | 668 | * @name: name of firmware file to look for |
669 | * @device: device for which firmware is being loaded | ||
670 | * @opt_flags: options to control firmware loading behaviour | ||
671 | * @ret: return value from direct lookup which triggered the fallback mechanism | ||
672 | * | ||
673 | * This function is called if direct lookup for the firmware failed, it enables | ||
674 | * a fallback mechanism through userspace by exposing a sysfs loading | ||
675 | * interface. Userspace is in charge of loading the firmware through the syfs | ||
676 | * loading interface. This syfs fallback mechanism may be disabled completely | ||
677 | * on a system by setting the proc sysctl value ignore_sysfs_fallback to true. | ||
678 | * If this false we check if the internal API caller set the @FW_OPT_NOFALLBACK | ||
679 | * flag, if so it would also disable the fallback mechanism. A system may want | ||
680 | * to enfoce the sysfs fallback mechanism at all times, it can do this by | ||
681 | * setting ignore_sysfs_fallback to false and force_sysfs_fallback to true. | ||
682 | * Enabling force_sysfs_fallback is functionally equivalent to build a kernel | ||
683 | * with CONFIG_FW_LOADER_USER_HELPER_FALLBACK. | ||
684 | **/ | ||
685 | int firmware_fallback_sysfs(struct firmware *fw, const char *name, | ||
686 | struct device *device, | ||
687 | enum fw_opt opt_flags, | ||
688 | int ret) | ||
669 | { | 689 | { |
670 | if (!fw_run_sysfs_fallback(opt_flags)) | 690 | if (!fw_run_sysfs_fallback(opt_flags)) |
671 | return ret; | 691 | return ret; |
672 | 692 | ||
673 | dev_warn(device, "Falling back to user helper\n"); | 693 | if (!(opt_flags & FW_OPT_NO_WARN)) |
694 | dev_warn(device, "Falling back to syfs fallback for: %s\n", | ||
695 | name); | ||
696 | else | ||
697 | dev_dbg(device, "Falling back to sysfs fallback for: %s\n", | ||
698 | name); | ||
674 | return fw_load_from_user_helper(fw, name, device, opt_flags); | 699 | return fw_load_from_user_helper(fw, name, device, opt_flags); |
675 | } | 700 | } |
diff --git a/drivers/base/firmware_loader/fallback.h b/drivers/base/firmware_loader/fallback.h index f8255670a663..21063503e4ea 100644 --- a/drivers/base/firmware_loader/fallback.h +++ b/drivers/base/firmware_loader/fallback.h | |||
@@ -5,6 +5,8 @@ | |||
5 | #include <linux/firmware.h> | 5 | #include <linux/firmware.h> |
6 | #include <linux/device.h> | 6 | #include <linux/device.h> |
7 | 7 | ||
8 | #include "firmware.h" | ||
9 | |||
8 | /** | 10 | /** |
9 | * struct firmware_fallback_config - firmware fallback configuration settings | 11 | * struct firmware_fallback_config - firmware fallback configuration settings |
10 | * | 12 | * |
@@ -29,10 +31,10 @@ struct firmware_fallback_config { | |||
29 | }; | 31 | }; |
30 | 32 | ||
31 | #ifdef CONFIG_FW_LOADER_USER_HELPER | 33 | #ifdef CONFIG_FW_LOADER_USER_HELPER |
32 | int fw_sysfs_fallback(struct firmware *fw, const char *name, | 34 | int firmware_fallback_sysfs(struct firmware *fw, const char *name, |
33 | struct device *device, | 35 | struct device *device, |
34 | unsigned int opt_flags, | 36 | enum fw_opt opt_flags, |
35 | int ret); | 37 | int ret); |
36 | void kill_pending_fw_fallback_reqs(bool only_kill_custom); | 38 | void kill_pending_fw_fallback_reqs(bool only_kill_custom); |
37 | 39 | ||
38 | void fw_fallback_set_cache_timeout(void); | 40 | void fw_fallback_set_cache_timeout(void); |
@@ -41,10 +43,10 @@ void fw_fallback_set_default_timeout(void); | |||
41 | int register_sysfs_loader(void); | 43 | int register_sysfs_loader(void); |
42 | void unregister_sysfs_loader(void); | 44 | void unregister_sysfs_loader(void); |
43 | #else /* CONFIG_FW_LOADER_USER_HELPER */ | 45 | #else /* CONFIG_FW_LOADER_USER_HELPER */ |
44 | static inline int fw_sysfs_fallback(struct firmware *fw, const char *name, | 46 | static inline int firmware_fallback_sysfs(struct firmware *fw, const char *name, |
45 | struct device *device, | 47 | struct device *device, |
46 | unsigned int opt_flags, | 48 | enum fw_opt opt_flags, |
47 | int ret) | 49 | int ret) |
48 | { | 50 | { |
49 | /* Keep carrying over the same error */ | 51 | /* Keep carrying over the same error */ |
50 | return ret; | 52 | return ret; |
diff --git a/drivers/base/firmware_loader/firmware.h b/drivers/base/firmware_loader/firmware.h index 64acbb1a392c..4c1395f8e7ed 100644 --- a/drivers/base/firmware_loader/firmware.h +++ b/drivers/base/firmware_loader/firmware.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #ifndef __FIRMWARE_LOADER_H | 2 | #ifndef __FIRMWARE_LOADER_H |
3 | #define __FIRMWARE_LOADER_H | 3 | #define __FIRMWARE_LOADER_H |
4 | 4 | ||
5 | #include <linux/bitops.h> | ||
5 | #include <linux/firmware.h> | 6 | #include <linux/firmware.h> |
6 | #include <linux/types.h> | 7 | #include <linux/types.h> |
7 | #include <linux/kref.h> | 8 | #include <linux/kref.h> |
@@ -10,13 +11,33 @@ | |||
10 | 11 | ||
11 | #include <generated/utsrelease.h> | 12 | #include <generated/utsrelease.h> |
12 | 13 | ||
13 | /* firmware behavior options */ | 14 | /** |
14 | #define FW_OPT_UEVENT (1U << 0) | 15 | * enum fw_opt - options to control firmware loading behaviour |
15 | #define FW_OPT_NOWAIT (1U << 1) | 16 | * |
16 | #define FW_OPT_USERHELPER (1U << 2) | 17 | * @FW_OPT_UEVENT: Enables the fallback mechanism to send a kobject uevent |
17 | #define FW_OPT_NO_WARN (1U << 3) | 18 | * when the firmware is not found. Userspace is in charge to load the |
18 | #define FW_OPT_NOCACHE (1U << 4) | 19 | * firmware using the sysfs loading facility. |
19 | #define FW_OPT_NOFALLBACK (1U << 5) | 20 | * @FW_OPT_NOWAIT: Used to describe the firmware request is asynchronous. |
21 | * @FW_OPT_USERHELPER: Enable the fallback mechanism, in case the direct | ||
22 | * filesystem lookup fails at finding the firmware. For details refer to | ||
23 | * firmware_fallback_sysfs(). | ||
24 | * @FW_OPT_NO_WARN: Quiet, avoid printing warning messages. | ||
25 | * @FW_OPT_NOCACHE: Disables firmware caching. Firmware caching is used to | ||
26 | * cache the firmware upon suspend, so that upon resume races against the | ||
27 | * firmware file lookup on storage is avoided. Used for calls where the | ||
28 | * file may be too big, or where the driver takes charge of its own | ||
29 | * firmware caching mechanism. | ||
30 | * @FW_OPT_NOFALLBACK: Disable the fallback mechanism. Takes precedence over | ||
31 | * &FW_OPT_UEVENT and &FW_OPT_USERHELPER. | ||
32 | */ | ||
33 | enum fw_opt { | ||
34 | FW_OPT_UEVENT = BIT(0), | ||
35 | FW_OPT_NOWAIT = BIT(1), | ||
36 | FW_OPT_USERHELPER = BIT(2), | ||
37 | FW_OPT_NO_WARN = BIT(3), | ||
38 | FW_OPT_NOCACHE = BIT(4), | ||
39 | FW_OPT_NOFALLBACK = BIT(5), | ||
40 | }; | ||
20 | 41 | ||
21 | enum fw_status { | 42 | enum fw_status { |
22 | FW_STATUS_UNKNOWN, | 43 | FW_STATUS_UNKNOWN, |
@@ -110,6 +131,6 @@ static inline void fw_state_done(struct fw_priv *fw_priv) | |||
110 | } | 131 | } |
111 | 132 | ||
112 | int assign_fw(struct firmware *fw, struct device *device, | 133 | int assign_fw(struct firmware *fw, struct device *device, |
113 | unsigned int opt_flags); | 134 | enum fw_opt opt_flags); |
114 | 135 | ||
115 | #endif /* __FIRMWARE_LOADER_H */ | 136 | #endif /* __FIRMWARE_LOADER_H */ |
diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c index eb34089e4299..0943e7065e0e 100644 --- a/drivers/base/firmware_loader/main.c +++ b/drivers/base/firmware_loader/main.c | |||
@@ -443,7 +443,7 @@ static int fw_add_devm_name(struct device *dev, const char *name) | |||
443 | #endif | 443 | #endif |
444 | 444 | ||
445 | int assign_fw(struct firmware *fw, struct device *device, | 445 | int assign_fw(struct firmware *fw, struct device *device, |
446 | unsigned int opt_flags) | 446 | enum fw_opt opt_flags) |
447 | { | 447 | { |
448 | struct fw_priv *fw_priv = fw->priv; | 448 | struct fw_priv *fw_priv = fw->priv; |
449 | int ret; | 449 | int ret; |
@@ -558,7 +558,7 @@ static void fw_abort_batch_reqs(struct firmware *fw) | |||
558 | static int | 558 | static int |
559 | _request_firmware(const struct firmware **firmware_p, const char *name, | 559 | _request_firmware(const struct firmware **firmware_p, const char *name, |
560 | struct device *device, void *buf, size_t size, | 560 | struct device *device, void *buf, size_t size, |
561 | unsigned int opt_flags) | 561 | enum fw_opt opt_flags) |
562 | { | 562 | { |
563 | struct firmware *fw = NULL; | 563 | struct firmware *fw = NULL; |
564 | int ret; | 564 | int ret; |
@@ -581,7 +581,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name, | |||
581 | dev_warn(device, | 581 | dev_warn(device, |
582 | "Direct firmware load for %s failed with error %d\n", | 582 | "Direct firmware load for %s failed with error %d\n", |
583 | name, ret); | 583 | name, ret); |
584 | ret = fw_sysfs_fallback(fw, name, device, opt_flags, ret); | 584 | ret = firmware_fallback_sysfs(fw, name, device, opt_flags, ret); |
585 | } else | 585 | } else |
586 | ret = assign_fw(fw, device, opt_flags); | 586 | ret = assign_fw(fw, device, opt_flags); |
587 | 587 | ||
@@ -597,7 +597,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name, | |||
597 | } | 597 | } |
598 | 598 | ||
599 | /** | 599 | /** |
600 | * request_firmware: - send firmware request and wait for it | 600 | * request_firmware() - send firmware request and wait for it |
601 | * @firmware_p: pointer to firmware image | 601 | * @firmware_p: pointer to firmware image |
602 | * @name: name of firmware file | 602 | * @name: name of firmware file |
603 | * @device: device for which firmware is being loaded | 603 | * @device: device for which firmware is being loaded |
@@ -632,7 +632,34 @@ request_firmware(const struct firmware **firmware_p, const char *name, | |||
632 | EXPORT_SYMBOL(request_firmware); | 632 | EXPORT_SYMBOL(request_firmware); |
633 | 633 | ||
634 | /** | 634 | /** |
635 | * request_firmware_direct: - load firmware directly without usermode helper | 635 | * firmware_request_nowarn() - request for an optional fw module |
636 | * @firmware: pointer to firmware image | ||
637 | * @name: name of firmware file | ||
638 | * @device: device for which firmware is being loaded | ||
639 | * | ||
640 | * This function is similar in behaviour to request_firmware(), except | ||
641 | * it doesn't produce warning messages when the file is not found. | ||
642 | * The sysfs fallback mechanism is enabled if direct filesystem lookup fails, | ||
643 | * however, however failures to find the firmware file with it are still | ||
644 | * suppressed. It is therefore up to the driver to check for the return value | ||
645 | * of this call and to decide when to inform the users of errors. | ||
646 | **/ | ||
647 | int firmware_request_nowarn(const struct firmware **firmware, const char *name, | ||
648 | struct device *device) | ||
649 | { | ||
650 | int ret; | ||
651 | |||
652 | /* Need to pin this module until return */ | ||
653 | __module_get(THIS_MODULE); | ||
654 | ret = _request_firmware(firmware, name, device, NULL, 0, | ||
655 | FW_OPT_UEVENT | FW_OPT_NO_WARN); | ||
656 | module_put(THIS_MODULE); | ||
657 | return ret; | ||
658 | } | ||
659 | EXPORT_SYMBOL_GPL(firmware_request_nowarn); | ||
660 | |||
661 | /** | ||
662 | * request_firmware_direct() - load firmware directly without usermode helper | ||
636 | * @firmware_p: pointer to firmware image | 663 | * @firmware_p: pointer to firmware image |
637 | * @name: name of firmware file | 664 | * @name: name of firmware file |
638 | * @device: device for which firmware is being loaded | 665 | * @device: device for which firmware is being loaded |
@@ -657,7 +684,7 @@ int request_firmware_direct(const struct firmware **firmware_p, | |||
657 | EXPORT_SYMBOL_GPL(request_firmware_direct); | 684 | EXPORT_SYMBOL_GPL(request_firmware_direct); |
658 | 685 | ||
659 | /** | 686 | /** |
660 | * firmware_request_cache: - cache firmware for suspend so resume can use it | 687 | * firmware_request_cache() - cache firmware for suspend so resume can use it |
661 | * @name: name of firmware file | 688 | * @name: name of firmware file |
662 | * @device: device for which firmware should be cached for | 689 | * @device: device for which firmware should be cached for |
663 | * | 690 | * |
@@ -681,7 +708,7 @@ int firmware_request_cache(struct device *device, const char *name) | |||
681 | EXPORT_SYMBOL_GPL(firmware_request_cache); | 708 | EXPORT_SYMBOL_GPL(firmware_request_cache); |
682 | 709 | ||
683 | /** | 710 | /** |
684 | * request_firmware_into_buf - load firmware into a previously allocated buffer | 711 | * request_firmware_into_buf() - load firmware into a previously allocated buffer |
685 | * @firmware_p: pointer to firmware image | 712 | * @firmware_p: pointer to firmware image |
686 | * @name: name of firmware file | 713 | * @name: name of firmware file |
687 | * @device: device for which firmware is being loaded and DMA region allocated | 714 | * @device: device for which firmware is being loaded and DMA region allocated |
@@ -713,7 +740,7 @@ request_firmware_into_buf(const struct firmware **firmware_p, const char *name, | |||
713 | EXPORT_SYMBOL(request_firmware_into_buf); | 740 | EXPORT_SYMBOL(request_firmware_into_buf); |
714 | 741 | ||
715 | /** | 742 | /** |
716 | * release_firmware: - release the resource associated with a firmware image | 743 | * release_firmware() - release the resource associated with a firmware image |
717 | * @fw: firmware resource to release | 744 | * @fw: firmware resource to release |
718 | **/ | 745 | **/ |
719 | void release_firmware(const struct firmware *fw) | 746 | void release_firmware(const struct firmware *fw) |
@@ -734,7 +761,7 @@ struct firmware_work { | |||
734 | struct device *device; | 761 | struct device *device; |
735 | void *context; | 762 | void *context; |
736 | void (*cont)(const struct firmware *fw, void *context); | 763 | void (*cont)(const struct firmware *fw, void *context); |
737 | unsigned int opt_flags; | 764 | enum fw_opt opt_flags; |
738 | }; | 765 | }; |
739 | 766 | ||
740 | static void request_firmware_work_func(struct work_struct *work) | 767 | static void request_firmware_work_func(struct work_struct *work) |
@@ -755,7 +782,7 @@ static void request_firmware_work_func(struct work_struct *work) | |||
755 | } | 782 | } |
756 | 783 | ||
757 | /** | 784 | /** |
758 | * request_firmware_nowait - asynchronous version of request_firmware | 785 | * request_firmware_nowait() - asynchronous version of request_firmware |
759 | * @module: module requesting the firmware | 786 | * @module: module requesting the firmware |
760 | * @uevent: sends uevent to copy the firmware image if this flag | 787 | * @uevent: sends uevent to copy the firmware image if this flag |
761 | * is non-zero else the firmware copy must be done manually. | 788 | * is non-zero else the firmware copy must be done manually. |
@@ -824,7 +851,7 @@ EXPORT_SYMBOL(request_firmware_nowait); | |||
824 | static ASYNC_DOMAIN_EXCLUSIVE(fw_cache_domain); | 851 | static ASYNC_DOMAIN_EXCLUSIVE(fw_cache_domain); |
825 | 852 | ||
826 | /** | 853 | /** |
827 | * cache_firmware - cache one firmware image in kernel memory space | 854 | * cache_firmware() - cache one firmware image in kernel memory space |
828 | * @fw_name: the firmware image name | 855 | * @fw_name: the firmware image name |
829 | * | 856 | * |
830 | * Cache firmware in kernel memory so that drivers can use it when | 857 | * Cache firmware in kernel memory so that drivers can use it when |
@@ -866,7 +893,7 @@ static struct fw_priv *lookup_fw_priv(const char *fw_name) | |||
866 | } | 893 | } |
867 | 894 | ||
868 | /** | 895 | /** |
869 | * uncache_firmware - remove one cached firmware image | 896 | * uncache_firmware() - remove one cached firmware image |
870 | * @fw_name: the firmware image name | 897 | * @fw_name: the firmware image name |
871 | * | 898 | * |
872 | * Uncache one firmware image which has been cached successfully | 899 | * Uncache one firmware image which has been cached successfully |
@@ -1042,7 +1069,7 @@ static void __device_uncache_fw_images(void) | |||
1042 | } | 1069 | } |
1043 | 1070 | ||
1044 | /** | 1071 | /** |
1045 | * device_cache_fw_images - cache devices' firmware | 1072 | * device_cache_fw_images() - cache devices' firmware |
1046 | * | 1073 | * |
1047 | * If one device called request_firmware or its nowait version | 1074 | * If one device called request_firmware or its nowait version |
1048 | * successfully before, the firmware names are recored into the | 1075 | * successfully before, the firmware names are recored into the |
@@ -1075,7 +1102,7 @@ static void device_cache_fw_images(void) | |||
1075 | } | 1102 | } |
1076 | 1103 | ||
1077 | /** | 1104 | /** |
1078 | * device_uncache_fw_images - uncache devices' firmware | 1105 | * device_uncache_fw_images() - uncache devices' firmware |
1079 | * | 1106 | * |
1080 | * uncache all firmwares which have been cached successfully | 1107 | * uncache all firmwares which have been cached successfully |
1081 | * by device_uncache_fw_images earlier | 1108 | * by device_uncache_fw_images earlier |
@@ -1092,7 +1119,7 @@ static void device_uncache_fw_images_work(struct work_struct *work) | |||
1092 | } | 1119 | } |
1093 | 1120 | ||
1094 | /** | 1121 | /** |
1095 | * device_uncache_fw_images_delay - uncache devices firmwares | 1122 | * device_uncache_fw_images_delay() - uncache devices firmwares |
1096 | * @delay: number of milliseconds to delay uncache device firmwares | 1123 | * @delay: number of milliseconds to delay uncache device firmwares |
1097 | * | 1124 | * |
1098 | * uncache all devices's firmwares which has been cached successfully | 1125 | * uncache all devices's firmwares which has been cached successfully |
diff --git a/drivers/base/memory.c b/drivers/base/memory.c index bffe8616bd55..f5e560188a18 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c | |||
@@ -649,13 +649,19 @@ static const struct attribute_group *memory_memblk_attr_groups[] = { | |||
649 | static | 649 | static |
650 | int register_memory(struct memory_block *memory) | 650 | int register_memory(struct memory_block *memory) |
651 | { | 651 | { |
652 | int ret; | ||
653 | |||
652 | memory->dev.bus = &memory_subsys; | 654 | memory->dev.bus = &memory_subsys; |
653 | memory->dev.id = memory->start_section_nr / sections_per_block; | 655 | memory->dev.id = memory->start_section_nr / sections_per_block; |
654 | memory->dev.release = memory_block_release; | 656 | memory->dev.release = memory_block_release; |
655 | memory->dev.groups = memory_memblk_attr_groups; | 657 | memory->dev.groups = memory_memblk_attr_groups; |
656 | memory->dev.offline = memory->state == MEM_OFFLINE; | 658 | memory->dev.offline = memory->state == MEM_OFFLINE; |
657 | 659 | ||
658 | return device_register(&memory->dev); | 660 | ret = device_register(&memory->dev); |
661 | if (ret) | ||
662 | put_device(&memory->dev); | ||
663 | |||
664 | return ret; | ||
659 | } | 665 | } |
660 | 666 | ||
661 | static int init_memory_block(struct memory_block **memory, | 667 | static int init_memory_block(struct memory_block **memory, |
diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c index 8a3020dbd4cf..936907227b9e 100644 --- a/drivers/net/wireless/ath/ath10k/core.c +++ b/drivers/net/wireless/ath/ath10k/core.c | |||
@@ -653,7 +653,7 @@ static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar, | |||
653 | dir = "."; | 653 | dir = "."; |
654 | 654 | ||
655 | snprintf(filename, sizeof(filename), "%s/%s", dir, file); | 655 | snprintf(filename, sizeof(filename), "%s/%s", dir, file); |
656 | ret = request_firmware(&fw, filename, ar->dev); | 656 | ret = firmware_request_nowarn(&fw, filename, ar->dev); |
657 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot fw request '%s': %d\n", | 657 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot fw request '%s': %d\n", |
658 | filename, ret); | 658 | filename, ret); |
659 | 659 | ||
diff --git a/drivers/net/wireless/ath/ath10k/testmode.c b/drivers/net/wireless/ath/ath10k/testmode.c index 568810b41657..c24ee616833c 100644 --- a/drivers/net/wireless/ath/ath10k/testmode.c +++ b/drivers/net/wireless/ath/ath10k/testmode.c | |||
@@ -157,7 +157,7 @@ static int ath10k_tm_fetch_utf_firmware_api_1(struct ath10k *ar, | |||
157 | ar->hw_params.fw.dir, ATH10K_FW_UTF_FILE); | 157 | ar->hw_params.fw.dir, ATH10K_FW_UTF_FILE); |
158 | 158 | ||
159 | /* load utf firmware image */ | 159 | /* load utf firmware image */ |
160 | ret = request_firmware_direct(&fw_file->firmware, filename, ar->dev); | 160 | ret = firmware_request_nowarn(&fw_file->firmware, filename, ar->dev); |
161 | ath10k_dbg(ar, ATH10K_DBG_TESTMODE, "testmode fw request '%s': %d\n", | 161 | ath10k_dbg(ar, ATH10K_DBG_TESTMODE, "testmode fw request '%s': %d\n", |
162 | filename, ret); | 162 | filename, ret); |
163 | 163 | ||
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 9792cedfc351..e76e95f62f76 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c | |||
@@ -1922,4 +1922,5 @@ struct bus_type usb_bus_type = { | |||
1922 | .name = "usb", | 1922 | .name = "usb", |
1923 | .match = usb_device_match, | 1923 | .match = usb_device_match, |
1924 | .uevent = usb_uevent, | 1924 | .uevent = usb_uevent, |
1925 | .need_parent_lock = true, | ||
1925 | }; | 1926 | }; |
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 1f99678ff5d3..4fce1da7db23 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c | |||
@@ -796,19 +796,13 @@ EXPORT_SYMBOL_GPL(debugfs_read_file_bool); | |||
796 | ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf, | 796 | ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf, |
797 | size_t count, loff_t *ppos) | 797 | size_t count, loff_t *ppos) |
798 | { | 798 | { |
799 | char buf[32]; | ||
800 | size_t buf_size; | ||
801 | bool bv; | 799 | bool bv; |
802 | int r; | 800 | int r; |
803 | bool *val = file->private_data; | 801 | bool *val = file->private_data; |
804 | struct dentry *dentry = F_DENTRY(file); | 802 | struct dentry *dentry = F_DENTRY(file); |
805 | 803 | ||
806 | buf_size = min(count, (sizeof(buf)-1)); | 804 | r = kstrtobool_from_user(user_buf, count, &bv); |
807 | if (copy_from_user(buf, user_buf, buf_size)) | 805 | if (!r) { |
808 | return -EFAULT; | ||
809 | |||
810 | buf[buf_size] = '\0'; | ||
811 | if (strtobool(buf, &bv) == 0) { | ||
812 | r = debugfs_file_get(dentry); | 806 | r = debugfs_file_get(dentry); |
813 | if (unlikely(r)) | 807 | if (unlikely(r)) |
814 | return r; | 808 | return r; |
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index 13b01351dd1c..a913b12fc7f8 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c | |||
@@ -512,7 +512,9 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent) | |||
512 | if (unlikely(!inode)) | 512 | if (unlikely(!inode)) |
513 | return failed_creating(dentry); | 513 | return failed_creating(dentry); |
514 | 514 | ||
515 | inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; | 515 | if (!parent) |
516 | parent = debugfs_mount->mnt_root; | ||
517 | inode->i_mode = S_IFDIR | ((d_inode(parent)->i_mode & 0770)); | ||
516 | inode->i_op = &simple_dir_inode_operations; | 518 | inode->i_op = &simple_dir_inode_operations; |
517 | inode->i_fop = &simple_dir_operations; | 519 | inode->i_fop = &simple_dir_operations; |
518 | 520 | ||
diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c index fd5ce883072e..2015d8c45e4a 100644 --- a/fs/kernfs/file.c +++ b/fs/kernfs/file.c | |||
@@ -348,11 +348,11 @@ static void kernfs_vma_open(struct vm_area_struct *vma) | |||
348 | kernfs_put_active(of->kn); | 348 | kernfs_put_active(of->kn); |
349 | } | 349 | } |
350 | 350 | ||
351 | static int kernfs_vma_fault(struct vm_fault *vmf) | 351 | static vm_fault_t kernfs_vma_fault(struct vm_fault *vmf) |
352 | { | 352 | { |
353 | struct file *file = vmf->vma->vm_file; | 353 | struct file *file = vmf->vma->vm_file; |
354 | struct kernfs_open_file *of = kernfs_of(file); | 354 | struct kernfs_open_file *of = kernfs_of(file); |
355 | int ret; | 355 | vm_fault_t ret; |
356 | 356 | ||
357 | if (!of->vm_ops) | 357 | if (!of->vm_ops) |
358 | return VM_FAULT_SIGBUS; | 358 | return VM_FAULT_SIGBUS; |
@@ -368,11 +368,11 @@ static int kernfs_vma_fault(struct vm_fault *vmf) | |||
368 | return ret; | 368 | return ret; |
369 | } | 369 | } |
370 | 370 | ||
371 | static int kernfs_vma_page_mkwrite(struct vm_fault *vmf) | 371 | static vm_fault_t kernfs_vma_page_mkwrite(struct vm_fault *vmf) |
372 | { | 372 | { |
373 | struct file *file = vmf->vma->vm_file; | 373 | struct file *file = vmf->vma->vm_file; |
374 | struct kernfs_open_file *of = kernfs_of(file); | 374 | struct kernfs_open_file *of = kernfs_of(file); |
375 | int ret; | 375 | vm_fault_t ret; |
376 | 376 | ||
377 | if (!of->vm_ops) | 377 | if (!of->vm_ops) |
378 | return VM_FAULT_SIGBUS; | 378 | return VM_FAULT_SIGBUS; |
diff --git a/include/linux/device.h b/include/linux/device.h index 00b6c3b42437..e9d4b43c4ead 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -98,6 +98,8 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); | |||
98 | * @p: The private data of the driver core, only the driver core can | 98 | * @p: The private data of the driver core, only the driver core can |
99 | * touch this. | 99 | * touch this. |
100 | * @lock_key: Lock class key for use by the lock validator | 100 | * @lock_key: Lock class key for use by the lock validator |
101 | * @need_parent_lock: When probing or removing a device on this bus, the | ||
102 | * device core should lock the device's parent. | ||
101 | * | 103 | * |
102 | * A bus is a channel between the processor and one or more devices. For the | 104 | * A bus is a channel between the processor and one or more devices. For the |
103 | * purposes of the device model, all devices are connected via a bus, even if | 105 | * purposes of the device model, all devices are connected via a bus, even if |
@@ -138,6 +140,8 @@ struct bus_type { | |||
138 | 140 | ||
139 | struct subsys_private *p; | 141 | struct subsys_private *p; |
140 | struct lock_class_key lock_key; | 142 | struct lock_class_key lock_key; |
143 | |||
144 | bool need_parent_lock; | ||
141 | }; | 145 | }; |
142 | 146 | ||
143 | extern int __must_check bus_register(struct bus_type *bus); | 147 | extern int __must_check bus_register(struct bus_type *bus); |
diff --git a/include/linux/firmware.h b/include/linux/firmware.h index 41050417cafb..2dd566c91d44 100644 --- a/include/linux/firmware.h +++ b/include/linux/firmware.h | |||
@@ -42,6 +42,8 @@ struct builtin_fw { | |||
42 | #if defined(CONFIG_FW_LOADER) || (defined(CONFIG_FW_LOADER_MODULE) && defined(MODULE)) | 42 | #if defined(CONFIG_FW_LOADER) || (defined(CONFIG_FW_LOADER_MODULE) && defined(MODULE)) |
43 | int request_firmware(const struct firmware **fw, const char *name, | 43 | int request_firmware(const struct firmware **fw, const char *name, |
44 | struct device *device); | 44 | struct device *device); |
45 | int firmware_request_nowarn(const struct firmware **fw, const char *name, | ||
46 | struct device *device); | ||
45 | int request_firmware_nowait( | 47 | int request_firmware_nowait( |
46 | struct module *module, bool uevent, | 48 | struct module *module, bool uevent, |
47 | const char *name, struct device *device, gfp_t gfp, void *context, | 49 | const char *name, struct device *device, gfp_t gfp, void *context, |
@@ -59,6 +61,14 @@ static inline int request_firmware(const struct firmware **fw, | |||
59 | { | 61 | { |
60 | return -EINVAL; | 62 | return -EINVAL; |
61 | } | 63 | } |
64 | |||
65 | static inline int firmware_request_nowarn(const struct firmware **fw, | ||
66 | const char *name, | ||
67 | struct device *device) | ||
68 | { | ||
69 | return -EINVAL; | ||
70 | } | ||
71 | |||
62 | static inline int request_firmware_nowait( | 72 | static inline int request_firmware_nowait( |
63 | struct module *module, bool uevent, | 73 | struct module *module, bool uevent, |
64 | const char *name, struct device *device, gfp_t gfp, void *context, | 74 | const char *name, struct device *device, gfp_t gfp, void *context, |