Skip to content

Commit ec064d3

Browse files
committed
Merge tag 'driver-core-4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
Pull driver core updates from Greg KH: "Here is the driver core patchset for 4.18-rc1. The large chunk of these are firmware core documentation and api updates. Nothing major there, just better descriptions for others to be able to understand the firmware code better. There's also a user for a new firmware api call. Other than that, there are some minor updates for debugfs, kernfs, and the driver core itself. All of these have been in linux-next for a while with no reported issues" * tag 'driver-core-4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (23 commits) driver core: hold dev's parent lock when needed driver-core: return EINVAL error instead of BUG_ON() driver core: add __printf verification to device_create_groups_vargs mm: memory_hotplug: use put_device() if device_register fail base: core: fix typo 'can by' to 'can be' debugfs: inode: debugfs_create_dir uses mode permission from parent debugfs: Re-use kstrtobool_from_user() Documentation: clarify firmware_class provenance and why we can't rename the module Documentation: remove stale firmware API reference Documentation: fix few typos and clarifications for the firmware loader ath10k: re-enable the firmware fallback mechanism for testmode ath10k: use firmware_request_nowarn() to load firmware firmware: add firmware_request_nowarn() - load firmware without warnings firmware_loader: make firmware_fallback_sysfs() print more useful firmware_loader: move kconfig FW_LOADER entries to its own file firmware_loader: replace ---help--- with help firmware_loader: enhance Kconfig documentation over FW_LOADER firmware_loader: document firmware_sysfs_fallback() firmware: rename fw_sysfs_fallback to firmware_fallback_sysfs() firmware: use () to terminate kernel-doc function names ...
2 parents abf7dba + 8c97a46 commit ec064d3

File tree

23 files changed

+372
-162
lines changed

23 files changed

+372
-162
lines changed

Documentation/dell_rbu.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,7 @@ read back the image downloaded.
121121

122122
.. note::
123123

124-
This driver requires a patch for firmware_class.c which has the modified
125-
request_firmware_nowait function.
126-
127-
Also after updating the BIOS image a user mode application needs to execute
124+
After updating the BIOS image a user mode application needs to execute
128125
code which sends the BIOS update request to the BIOS. So on the next reboot
129126
the BIOS knows about the new image downloaded and it updates itself.
130127
Also don't unload the rbu driver if the image has to be updated.

Documentation/driver-api/firmware/fallback-mechanisms.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ the firmware requested, and establishes it in the device hierarchy by
7272
associating the device used to make the request as the device's parent.
7373
The sysfs directory's file attributes are defined and controlled through
7474
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,
76-
as originally the only firmware loading mechanism available was the
77-
mechanism we now use as a fallback mechanism.
75+
This is actually where the original firmware_class module name came from,
76+
given that originally the only firmware loading mechanism available was the
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.
7881

7982
To load firmware using the sysfs interface we expose a loading indicator,
8083
and a file upload firmware into:
@@ -83,7 +86,7 @@ and a file upload firmware into:
8386
* /sys/$DEVPATH/data
8487

8588
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,
8790
and you notify the kernel the firmware is ready by echo'ing 0 onto
8891
the loading file.
8992

@@ -136,7 +139,8 @@ by kobject uevents. This is specially exacerbated due to the fact that most
136139
distributions today disable CONFIG_FW_LOADER_USER_HELPER_FALLBACK.
137140

138141
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:
140144

141145
* FIRMWARE=firmware name
142146
* TIMEOUT=timeout value

Documentation/driver-api/firmware/firmware_cache.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Some implementation details about the firmware cache setup:
2929
* If an asynchronous call is used the firmware cache is only set up for a
3030
device if if the second argument (uevent) to request_firmware_nowait() is
3131
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
33-
mechanism documented below.
32+
userspace for the firmware request through the sysfs fallback mechanism
33+
if the firmware file is not found.
3434

3535
* If the firmware cache is determined to be needed as per the above two
3636
criteria the firmware cache is setup by adding a devres entry for the

Documentation/driver-api/firmware/request_firmware.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ request_firmware
2020
.. kernel-doc:: drivers/base/firmware_loader/main.c
2121
:functions: request_firmware
2222

23+
firmware_request_nowarn
24+
-----------------------
25+
.. kernel-doc:: drivers/base/firmware_loader/main.c
26+
:functions: firmware_request_nowarn
27+
2328
request_firmware_direct
2429
-----------------------
2530
.. kernel-doc:: drivers/base/firmware_loader/main.c

drivers/base/Kconfig

Lines changed: 17 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -70,81 +70,25 @@ config STANDALONE
7070
If unsure, say Y.
7171

7272
config PREVENT_FIRMWARE_BUILD
73-
bool "Prevent firmware from being built"
73+
bool "Disable drivers features which enable custom firmware building"
7474
default y
7575
help
76-
Say yes to avoid building firmware. Firmware is usually shipped
77-
with the driver and only when updating the firmware should a
78-
rebuild be made.
79-
If unsure, say Y here.
80-
81-
config FW_LOADER
82-
tristate "Userspace firmware loading support" if EXPERT
83-
default y
84-
---help---
85-
This option is provided for the case where none of the in-tree modules
86-
require userspace firmware loading support, but a module built
87-
out-of-tree does.
88-
89-
config EXTRA_FIRMWARE
90-
string "External firmware blobs to build into the kernel binary"
91-
depends on FW_LOADER
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.
76+
Say yes to disable driver features which enable building a custom
77+
driver firmware at kernel build time. These drivers do not use the
78+
kernel firmware API to load firmware (CONFIG_FW_LOADER), instead they
79+
use their own custom loading mechanism. The required firmware is
80+
usually shipped with the driver, building the driver firmware
81+
should only be needed if you have an updated firmware source.
82+
83+
Firmware should not be being built as part of kernel, these days
84+
you should always prevent this and say Y here. There are only two
85+
old drivers which enable building of its firmware at kernel build
86+
time:
87+
88+
o CONFIG_WANXL through CONFIG_WANXL_BUILD_FIRMWARE
89+
o CONFIG_SCSI_AIC79XX through CONFIG_AIC79XX_BUILD_FIRMWARE
90+
91+
source "drivers/base/firmware_loader/Kconfig"
14892

14993
config WANT_DEV_COREDUMP
15094
bool

drivers/base/bus.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf,
184184

185185
dev = bus_find_device_by_name(bus, NULL, buf);
186186
if (dev && dev->driver == drv) {
187-
if (dev->parent) /* Needed for USB */
187+
if (dev->parent && dev->bus->need_parent_lock)
188188
device_lock(dev->parent);
189189
device_release_driver(dev);
190-
if (dev->parent)
190+
if (dev->parent && dev->bus->need_parent_lock)
191191
device_unlock(dev->parent);
192192
err = count;
193193
}
@@ -211,12 +211,12 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf,
211211

212212
dev = bus_find_device_by_name(bus, NULL, buf);
213213
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)
215215
device_lock(dev->parent);
216216
device_lock(dev);
217217
err = driver_probe_device(drv, dev);
218218
device_unlock(dev);
219-
if (dev->parent)
219+
if (dev->parent && bus->need_parent_lock)
220220
device_unlock(dev->parent);
221221

222222
if (err > 0) {
@@ -735,10 +735,10 @@ static int __must_check bus_rescan_devices_helper(struct device *dev,
735735
int ret = 0;
736736

737737
if (!dev->driver) {
738-
if (dev->parent) /* Needed for USB */
738+
if (dev->parent && dev->bus->need_parent_lock)
739739
device_lock(dev->parent);
740740
ret = device_attach(dev);
741-
if (dev->parent)
741+
if (dev->parent && dev->bus->need_parent_lock)
742742
device_unlock(dev->parent);
743743
}
744744
return ret < 0 ? ret : 0;
@@ -770,10 +770,10 @@ EXPORT_SYMBOL_GPL(bus_rescan_devices);
770770
int device_reprobe(struct device *dev)
771771
{
772772
if (dev->driver) {
773-
if (dev->parent) /* Needed for USB */
773+
if (dev->parent && dev->bus->need_parent_lock)
774774
device_lock(dev->parent);
775775
device_release_driver(dev);
776-
if (dev->parent)
776+
if (dev->parent && dev->bus->need_parent_lock)
777777
device_unlock(dev->parent);
778778
}
779779
return bus_rescan_devices_helper(dev, NULL);

drivers/base/core.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ class_dir_create_and_add(struct class *class, struct kobject *parent_kobj)
14871487

14881488
dir = kzalloc(sizeof(*dir), GFP_KERNEL);
14891489
if (!dir)
1490-
return NULL;
1490+
return ERR_PTR(-ENOMEM);
14911491

14921492
dir->class = class;
14931493
kobject_init(&dir->kobj, &class_dir_ktype);
@@ -1497,7 +1497,7 @@ class_dir_create_and_add(struct class *class, struct kobject *parent_kobj)
14971497
retval = kobject_add(&dir->kobj, parent_kobj, "%s", class->name);
14981498
if (retval < 0) {
14991499
kobject_put(&dir->kobj);
1500-
return NULL;
1500+
return ERR_PTR(retval);
15011501
}
15021502
return &dir->kobj;
15031503
}
@@ -1804,6 +1804,10 @@ int device_add(struct device *dev)
18041804

18051805
parent = get_device(dev->parent);
18061806
kobj = get_device_parent(dev, parent);
1807+
if (IS_ERR(kobj)) {
1808+
error = PTR_ERR(kobj);
1809+
goto parent_error;
1810+
}
18071811
if (kobj)
18081812
dev->kobj.parent = kobj;
18091813

@@ -1902,6 +1906,7 @@ int device_add(struct device *dev)
19021906
kobject_del(&dev->kobj);
19031907
Error:
19041908
cleanup_glue_dir(dev, glue_dir);
1909+
parent_error:
19051910
put_device(parent);
19061911
name_error:
19071912
kfree(dev->p);
@@ -2426,7 +2431,7 @@ static void device_create_release(struct device *dev)
24262431
kfree(dev);
24272432
}
24282433

2429-
static struct device *
2434+
static __printf(6, 0) struct device *
24302435
device_create_groups_vargs(struct class *class, struct device *parent,
24312436
dev_t devt, void *drvdata,
24322437
const struct attribute_group **groups,
@@ -2704,7 +2709,7 @@ static int device_move_class_links(struct device *dev,
27042709
/**
27052710
* device_move - moves a device to a new parent
27062711
* @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)
27082713
* @dpm_order: how to reorder the dpm_list
27092714
*/
27102715
int device_move(struct device *dev, struct device *new_parent,
@@ -2721,6 +2726,11 @@ int device_move(struct device *dev, struct device *new_parent,
27212726
device_pm_lock();
27222727
new_parent = get_device(new_parent);
27232728
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+
}
27242734

27252735
pr_debug("device: '%s': %s: moving to '%s'\n", dev_name(dev),
27262736
__func__, new_parent ? dev_name(new_parent) : "<NULL>");

drivers/base/dd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,13 +814,13 @@ static int __driver_attach(struct device *dev, void *data)
814814
return ret;
815815
} /* ret > 0 means positive match */
816816

817-
if (dev->parent) /* Needed for USB */
817+
if (dev->parent && dev->bus->need_parent_lock)
818818
device_lock(dev->parent);
819819
device_lock(dev);
820820
if (!dev->driver)
821821
driver_probe_device(drv, dev);
822822
device_unlock(dev);
823-
if (dev->parent)
823+
if (dev->parent && dev->bus->need_parent_lock)
824824
device_unlock(dev->parent);
825825

826826
return 0;
@@ -916,15 +916,15 @@ void device_release_driver_internal(struct device *dev,
916916
struct device_driver *drv,
917917
struct device *parent)
918918
{
919-
if (parent)
919+
if (parent && dev->bus->need_parent_lock)
920920
device_lock(parent);
921921

922922
device_lock(dev);
923923
if (!drv || drv == dev->driver)
924924
__device_release_driver(dev, parent);
925925

926926
device_unlock(dev);
927-
if (parent)
927+
if (parent && dev->bus->need_parent_lock)
928928
device_unlock(parent);
929929
}
930930

drivers/base/driver.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ int driver_register(struct device_driver *drv)
148148
int ret;
149149
struct device_driver *other;
150150

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+
}
152156

153157
if ((drv->bus->probe && drv->probe) ||
154158
(drv->bus->remove && drv->remove) ||

0 commit comments

Comments
 (0)