* [PATCH 2/2] firmware_loader: builtin: fail build on empty firmware
2026-04-26 4:30 [PATCH 1/2] firmware_loader: builtin: ignore 0-size firmware Dmitry Torokhov
@ 2026-04-26 4:30 ` Dmitry Torokhov
2026-07-11 23:58 ` Danilo Krummrich
2026-07-11 22:11 ` [PATCH 1/2] firmware_loader: builtin: ignore 0-size firmware Dmitry Torokhov
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Dmitry Torokhov @ 2026-04-26 4:30 UTC (permalink / raw)
To: Luis Chamberlain, Russ Weight, Danilo Krummrich; +Cc: driver-core, linux-kernel
If an empty firmware file is supplied via CONFIG_EXTRA_FIRMWARE, the
build currently succeeds but creates an empty section. While the
firmware loader will not return such sections it is better to avoid
adding them in the first place.
Add a compile-time size check to the filechk_fwbin macro to abort the
build early if a 0-size firmware is encountered.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/base/firmware_loader/builtin/Makefile | 32 +++++++++++--------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/drivers/base/firmware_loader/builtin/Makefile b/drivers/base/firmware_loader/builtin/Makefile
index 6c067dedc01e..af5b1bbb31e4 100644
--- a/drivers/base/firmware_loader/builtin/Makefile
+++ b/drivers/base/firmware_loader/builtin/Makefile
@@ -16,20 +16,24 @@ ASM_ALIGN = $(if $(CONFIG_64BIT),3,2)
PROGBITS = $(if $(CONFIG_ARM),%,@)progbits
filechk_fwbin = \
- echo "/* Generated by $(src)/Makefile */" ;\
- echo " .section .rodata" ;\
- echo " .p2align 4" ;\
- echo "_fw_$(FWSTR)_bin:" ;\
- echo " .incbin \"$(fwdir)/$(FWNAME)\"" ;\
- echo "_fw_end:" ;\
- echo " .section .rodata.str,\"aMS\",$(PROGBITS),1" ;\
- echo " .p2align $(ASM_ALIGN)" ;\
- echo "_fw_$(FWSTR)_name:" ;\
- echo " .string \"$(FWNAME)\"" ;\
- echo " .section .builtin_fw,\"a\",$(PROGBITS)" ;\
- echo " .p2align $(ASM_ALIGN)" ;\
- echo " $(ASM_WORD) _fw_$(FWSTR)_name" ;\
- echo " $(ASM_WORD) _fw_$(FWSTR)_bin" ;\
+ if [ ! -s "$(fwdir)/$(FWNAME)" ]; then \
+ echo "error: empty firmware: $(fwdir)/$(FWNAME)" >&2 ;\
+ exit ;\
+ fi ;\
+ echo "/* Generated by $(src)/Makefile */" ;\
+ echo " .section .rodata" ;\
+ echo " .p2align 4" ;\
+ echo "_fw_$(FWSTR)_bin:" ;\
+ echo " .incbin \"$(fwdir)/$(FWNAME)\"" ;\
+ echo "_fw_end:" ;\
+ echo " .section .rodata.str,\"aMS\",$(PROGBITS),1" ;\
+ echo " .p2align $(ASM_ALIGN)" ;\
+ echo "_fw_$(FWSTR)_name:" ;\
+ echo " .string \"$(FWNAME)\"" ;\
+ echo " .section .builtin_fw,\"a\",$(PROGBITS)" ;\
+ echo " .p2align $(ASM_ALIGN)" ;\
+ echo " $(ASM_WORD) _fw_$(FWSTR)_name" ;\
+ echo " $(ASM_WORD) _fw_$(FWSTR)_bin" ;\
echo " $(ASM_WORD) _fw_end - _fw_$(FWSTR)_bin"
$(obj)/%.gen.S: FORCE
--
2.54.0.545.g6539524ca2-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 2/2] firmware_loader: builtin: fail build on empty firmware
2026-04-26 4:30 ` [PATCH 2/2] firmware_loader: builtin: fail build on empty firmware Dmitry Torokhov
@ 2026-07-11 23:58 ` Danilo Krummrich
2026-07-12 0:23 ` Dmitry Torokhov
0 siblings, 1 reply; 8+ messages in thread
From: Danilo Krummrich @ 2026-07-11 23:58 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: Luis Chamberlain, Russ Weight, driver-core, linux-kernel
On Sun Apr 26, 2026 at 6:30 AM CEST, Dmitry Torokhov wrote:
> + if [ ! -s "$(fwdir)/$(FWNAME)" ]; then \
> + echo "error: empty firmware: $(fwdir)/$(FWNAME)" >&2 ;\
> + exit ;\
Shouldn't this be 'exit 1' to actually fail the build?
> + fi ;\
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] firmware_loader: builtin: fail build on empty firmware
2026-07-11 23:58 ` Danilo Krummrich
@ 2026-07-12 0:23 ` Dmitry Torokhov
0 siblings, 0 replies; 8+ messages in thread
From: Dmitry Torokhov @ 2026-07-12 0:23 UTC (permalink / raw)
To: Danilo Krummrich; +Cc: Luis Chamberlain, Russ Weight, driver-core, linux-kernel
On Sun, Jul 12, 2026 at 01:58:26AM +0200, Danilo Krummrich wrote:
> On Sun Apr 26, 2026 at 6:30 AM CEST, Dmitry Torokhov wrote:
> > + if [ ! -s "$(fwdir)/$(FWNAME)" ]; then \
> > + echo "error: empty firmware: $(fwdir)/$(FWNAME)" >&2 ;\
> > + exit ;\
>
> Shouldn't this be 'exit 1' to actually fail the build?
Yes, you are absolutely right. Do you want me to resend or you can fix
it up on your end?
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] firmware_loader: builtin: ignore 0-size firmware
2026-04-26 4:30 [PATCH 1/2] firmware_loader: builtin: ignore 0-size firmware Dmitry Torokhov
2026-04-26 4:30 ` [PATCH 2/2] firmware_loader: builtin: fail build on empty firmware Dmitry Torokhov
@ 2026-07-11 22:11 ` Dmitry Torokhov
2026-07-11 23:57 ` Danilo Krummrich
2026-07-11 23:57 ` (subset) " Danilo Krummrich
2026-07-12 0:29 ` Danilo Krummrich
3 siblings, 1 reply; 8+ messages in thread
From: Dmitry Torokhov @ 2026-07-11 22:11 UTC (permalink / raw)
To: Luis Chamberlain, Russ Weight, Danilo Krummrich; +Cc: driver-core, linux-kernel
On Sat, Apr 25, 2026 at 09:30:38PM -0700, Dmitry Torokhov wrote:
> Currently, the builtin firmware loader allows 0-size firmware to be
> returned successfully to drivers. This differs from all other loading
> mechanisms (filesystem, sysfs fallback) which reject 0-byte files, and
> forces drivers to add boilerplate size checks.
>
> Modify firmware_request_builtin() to reject 0-size firmware. This will
> also result in firmware loader falling back to other mechanisms if an
> empty built-in firmware is present.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
Gentle ping on this and the next one...
> drivers/base/firmware_loader/builtin/main.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/base/firmware_loader/builtin/main.c b/drivers/base/firmware_loader/builtin/main.c
> index d36befebb1b9..1dcebe8e7f8e 100644
> --- a/drivers/base/firmware_loader/builtin/main.c
> +++ b/drivers/base/firmware_loader/builtin/main.c
> @@ -53,6 +53,8 @@ bool firmware_request_builtin(struct firmware *fw, const char *name)
>
> for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) {
> if (strcmp(name, b_fw->name) == 0) {
> + if (b_fw->size == 0)
> + return false;
> fw->size = b_fw->size;
> fw->data = b_fw->data;
> return true;
--
Dmitry
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: (subset) [PATCH 1/2] firmware_loader: builtin: ignore 0-size firmware
2026-04-26 4:30 [PATCH 1/2] firmware_loader: builtin: ignore 0-size firmware Dmitry Torokhov
2026-04-26 4:30 ` [PATCH 2/2] firmware_loader: builtin: fail build on empty firmware Dmitry Torokhov
2026-07-11 22:11 ` [PATCH 1/2] firmware_loader: builtin: ignore 0-size firmware Dmitry Torokhov
@ 2026-07-11 23:57 ` Danilo Krummrich
2026-07-12 0:29 ` Danilo Krummrich
3 siblings, 0 replies; 8+ messages in thread
From: Danilo Krummrich @ 2026-07-11 23:57 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Luis Chamberlain, Russ Weight, Danilo Krummrich, driver-core,
linux-kernel
On Sat, 25 Apr 2026 21:30:38 -0700, Dmitry Torokhov wrote:
> [PATCH 1/2] firmware_loader: builtin: ignore 0-size firmware
Applied, thanks!
Branch: driver-core-testing
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git
[1/2] firmware_loader: builtin: ignore 0-size firmware
commit: d059966c0c7d
The patch will appear in the next linux-next integration (typically within 24
hours on weekdays).
The patch is in the driver-core-testing branch and will be promoted to
driver-core-next after validation.
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: (subset) [PATCH 1/2] firmware_loader: builtin: ignore 0-size firmware
2026-04-26 4:30 [PATCH 1/2] firmware_loader: builtin: ignore 0-size firmware Dmitry Torokhov
` (2 preceding siblings ...)
2026-07-11 23:57 ` (subset) " Danilo Krummrich
@ 2026-07-12 0:29 ` Danilo Krummrich
3 siblings, 0 replies; 8+ messages in thread
From: Danilo Krummrich @ 2026-07-12 0:29 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Luis Chamberlain, Russ Weight, Danilo Krummrich, driver-core,
linux-kernel
On Sat, 25 Apr 2026 21:30:38 -0700, Dmitry Torokhov wrote:
> [PATCH 1/2] firmware_loader: builtin: ignore 0-size firmware
Applied, thanks!
Branch: driver-core-testing
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git
[2/2] firmware_loader: builtin: fail build on empty firmware
commit: 1160c2208fab
[ Use 'exit 1' to properly fail the build. - Danilo ]
The patch will appear in the next linux-next integration (typically within 24
hours on weekdays).
The patch is in the driver-core-testing branch and will be promoted to
driver-core-next after validation.
^ permalink raw reply [flat|nested] 8+ messages in thread