firmware_loader: builtin: ignore 0-size firmware
Subsystems (2)
PATCH 1/2 firmware_loader: builtin: ignore 0-size firmware
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.
--- drivers/base/firmware_loader/builtin/main.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/base/firmware_loader/builtin/main.c +2 -0
@@ -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;
Signature · 1 line
2.54.0.545.g6539524ca2-goog
PATCH 2/2 firmware_loader: builtin: fail build on empty firmware
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.
--- drivers/base/firmware_loader/builtin/Makefile | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-)
drivers/base/firmware_loader/builtin/Makefile +18 -14
@@ -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
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Danilo Krummrich
maintainerRe: [PATCH 2/2] firmware_loader: builtin: fail build on empty firmware
drivers/base/firmware_loader/builtin/Makefile ASM_ALIGN = $(if $(CONFIG_64BIT),3,2) · line 21
Quoted 3 lines · Dmitry Torokhov
drivers/base/firmware_loader/builtin/Makefile +3
-0+ if [ ! -s "$(fwdir)/$(FWNAME)" ]; then \ + echo "error: empty firmware: $(fwdir)/$(FWNAME)" >&2 ;\ + exit ;\
Shouldn't this be 'exit 1' to actually fail the build?
Quoted 1 line
drivers/base/firmware_loader/builtin/Makefile +1
-0+ fi ;\
Re: [PATCH 2/2] firmware_loader: builtin: fail build on empty firmware
Quoted 6 lines · Danilo Krummrich
drivers/base/firmware_loader/builtin/Makefile ASM_ALIGN = $(if $(CONFIG_64BIT),3,2) · line 21
Quoted 3 lines · Dmitry Torokhov
drivers/base/firmware_loader/builtin/Makefile +3
-0+ 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.
Signature · 1 line
Dmitry
Quoted 11 lines · Dmitry Torokhov
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 <[email protected]>---
Gentle ping on this and the next one...
Quoted 16 lines
drivers/base/firmware_loader/builtin/main.c | 2 ++ 1 file changed, 2 insertions(+)drivers/base/firmware_loader/builtin/main.c +2
-0@@ -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;
Signature · 1 line
Dmitry
Danilo Krummrich
maintainerQuoted 1 line · Dmitry Torokhov
Gentle ping on this and the next one...
Sorry for the delay, I picked this one up, but I have a question on the second one.
Re: (subset) [PATCH 1/2] firmware_loader: builtin: ignore 0-size firmware
In reply to Dmitry TorokhovQuoted 1 line · Dmitry Torokhov
[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.
Re: (subset) [PATCH 1/2] firmware_loader: builtin: ignore 0-size firmware
In reply to Dmitry TorokhovQuoted 1 line · Dmitry Torokhov
[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.