Paul Menzel has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/42798 )
Change subject: drivers/mrc_cache: Avoid unused variable assignment ......................................................................
drivers/mrc_cache: Avoid unused variable assignment
Fix the scan-build warning below:
CC romstage/drivers/mrc_cache/mrc_cache.o src/drivers/mrc_cache/mrc_cache.c:450:26: warning: Value stored to 'flash' during its initialization is never read const struct spi_flash *flash = boot_device_spi_flash(); ^~~~~ ~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated.
The function can return early before the value is read. Fix this, by getting rid of the variable, as the value is only read once.
Change-Id: I3c94b123f4994eed9d7568b63971fd5b1d94bc09 Found-by: scan-build (clang-tools-9 1:9.0.1-12) Signed-off-by: Paul Menzel pmenzel@molgen.mpg.de --- M src/drivers/mrc_cache/mrc_cache.c 1 file changed, 1 insertion(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/98/42798/1
diff --git a/src/drivers/mrc_cache/mrc_cache.c b/src/drivers/mrc_cache/mrc_cache.c index 3a005db..d567a20 100644 --- a/src/drivers/mrc_cache/mrc_cache.c +++ b/src/drivers/mrc_cache/mrc_cache.c @@ -447,15 +447,13 @@ /* Apply protection to a range of flash */ static int nvm_protect(const struct region *r) { - const struct spi_flash *flash = boot_device_spi_flash(); - if (!CONFIG(MRC_SETTINGS_PROTECT)) return 0;
if (!CONFIG(BOOT_DEVICE_SPI_FLASH)) return 0;
- return spi_flash_ctrlr_protect_region(flash, r, WRITE_PROTECT); + return spi_flash_ctrlr_protect_region(boot_device_spi_flash(), r, WRITE_PROTECT); }
/* Protect mrc region with a Protected Range Register */
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/42798 )
Change subject: drivers/mrc_cache: Avoid unused variable assignment ......................................................................
Patch Set 1:
(1 comment)
a
https://review.coreboot.org/c/coreboot/+/42798/1/src/drivers/mrc_cache/mrc_c... File src/drivers/mrc_cache/mrc_cache.c:
https://review.coreboot.org/c/coreboot/+/42798/1/src/drivers/mrc_cache/mrc_c... PS1, Line 456: boot_device_spi_flash Note that this function has side effects. Calling it here means that it won't run in some cases.
Paul Menzel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/42798 )
Change subject: drivers/mrc_cache: Avoid unused variable assignment ......................................................................
Patch Set 1:
(1 comment)
https://review.coreboot.org/c/coreboot/+/42798/1/src/drivers/mrc_cache/mrc_c... File src/drivers/mrc_cache/mrc_cache.c:
https://review.coreboot.org/c/coreboot/+/42798/1/src/drivers/mrc_cache/mrc_c... PS1, Line 456: boot_device_spi_flash
Note that this function has side effects. Calling it here means that it won't run in some cases.
You mean, in case the two if statements above are true?
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/42798 )
Change subject: drivers/mrc_cache: Avoid unused variable assignment ......................................................................
Patch Set 1:
(1 comment)
https://review.coreboot.org/c/coreboot/+/42798/1/src/drivers/mrc_cache/mrc_c... File src/drivers/mrc_cache/mrc_cache.c:
https://review.coreboot.org/c/coreboot/+/42798/1/src/drivers/mrc_cache/mrc_c... PS1, Line 456: boot_device_spi_flash
You mean, in case the two if statements above are true?
No. Previously, every call to "nvm_protect" would call `boot_device_spi_flash`. Now, calls to "nvm_protect" will only call "boot_device_spi_flash" if the two checks are false. Would be good to know if this makes any difference.
Paul Menzel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/42798 )
Change subject: drivers/mrc_cache: Avoid unused variable assignment ......................................................................
Patch Set 1:
(1 comment)
https://review.coreboot.org/c/coreboot/+/42798/1/src/drivers/mrc_cache/mrc_c... File src/drivers/mrc_cache/mrc_cache.c:
https://review.coreboot.org/c/coreboot/+/42798/1/src/drivers/mrc_cache/mrc_c... PS1, Line 456: boot_device_spi_flash
No. Previously, every call to "nvm_protect" would call `boot_device_spi_flash`. […]
Sorry, I meant *false* indeed.
`boot_device_init()` is called by that function. I believe the SPI flash API ensures, the device is initialized each time.
Paul Menzel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/42798 )
Change subject: drivers/mrc_cache: Avoid unused variable assignment ......................................................................
Patch Set 1:
Strangely, for comparing with `BUILD_TIMELESS=1`, building the Lenovo ThinkPad X201 with `CONFIG_MRC_SETTINGS_PROTECT` selected, the object `mrc_cache.o` differs, but it’s stripped by the linker for `coreboot.rom`.
``` $ more defconfig CONFIG_VENDOR_LENOVO=y CONFIG_BOARD_LENOVO_X201=y CONFIG_NO_GFX_INIT=y CONFIG_MRC_SETTINGS_PROTECT=y CONFIG_PAYLOAD_NONE=y ```
``` $ LANG=C diff -ur build-1 build-2 Binary files build-1/cbfs/fallback/ramstage.debug and build-2/cbfs/fallback/ramstage.debug differ Binary files build-1/cbfs/fallback/romstage.debug and build-2/cbfs/fallback/romstage.debug differ Binary files build-1/cbfs/fallback/romstage.elf and build-2/cbfs/fallback/romstage.elf differ diff -ur build-1/dsdt.dsl build-2/dsdt.dsl --- build-1/dsdt.dsl 2020-06-28 09:45:38.065799763 +0200 +++ build-2/dsdt.dsl 2020-06-28 09:36:09.835617515 +0200 @@ -5,7 +5,7 @@ * * Disassembling to symbolic ASL+ operators * - * Disassembly of build/dsdt.aml, Sun Jun 28 07:45:38 2020 + * Disassembly of build/dsdt.aml, Sun Jun 28 07:36:09 2020 * * Original Table Header: * Signature "DSDT" Binary files build-1/generated/ramstage.o and build-2/generated/ramstage.o differ Only in build-1/mainboard/lenovo/x201: cbfs-file.3v1XCM Only in build-1/mainboard/lenovo/x201: cbfs-file.3v1XCM.out Only in build-2/mainboard/lenovo/x201: cbfs-file.frB3XA Only in build-2/mainboard/lenovo/x201: cbfs-file.frB3XA.out Binary files build-1/ramstage/drivers/mrc_cache/mrc_cache.o and build-2/ramstage/drivers/mrc_cache/mrc_cache.o differ Binary files build-1/ramstage/drivers/mrc_cache/ramstage.a and build-2/ramstage/drivers/mrc_cache/ramstage.a differ Binary files build-1/romstage/drivers/mrc_cache/mrc_cache.o and build-2/romstage/drivers/mrc_cache/mrc_cache.o differ ```
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/42798 )
Change subject: drivers/mrc_cache: Avoid unused variable assignment ......................................................................
Patch Set 1:
Patch Set 1:
Strangely, for comparing with `BUILD_TIMELESS=1`, building the Lenovo ThinkPad X201 with `CONFIG_MRC_SETTINGS_PROTECT` selected, the object `mrc_cache.o` differs, but it’s stripped by the linker for `coreboot.rom`.
*snip*
Well, does moving the local variable declaration after the two conditional statements also change the binary?
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/42798 )
Change subject: drivers/mrc_cache: Avoid unused variable assignment ......................................................................
Patch Set 1: Code-Review+2
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/42798 )
Change subject: drivers/mrc_cache: Avoid unused variable assignment ......................................................................
Patch Set 2:
(1 comment)
https://review.coreboot.org/c/coreboot/+/42798/1/src/drivers/mrc_cache/mrc_c... File src/drivers/mrc_cache/mrc_cache.c:
https://review.coreboot.org/c/coreboot/+/42798/1/src/drivers/mrc_cache/mrc_c... PS1, Line 456: boot_device_spi_flash
Sorry, I meant *false* indeed. […]
We can discuss the purity of `boot_device_spi_flash` in another commit.
Patrick Georgi has submitted this change. ( https://review.coreboot.org/c/coreboot/+/42798 )
Change subject: drivers/mrc_cache: Avoid unused variable assignment ......................................................................
drivers/mrc_cache: Avoid unused variable assignment
Fix the scan-build warning below:
CC romstage/drivers/mrc_cache/mrc_cache.o src/drivers/mrc_cache/mrc_cache.c:450:26: warning: Value stored to 'flash' during its initialization is never read const struct spi_flash *flash = boot_device_spi_flash(); ^~~~~ ~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated.
The function can return early before the value is read. Fix this, by getting rid of the variable, as the value is only read once.
Change-Id: I3c94b123f4994eed9d7568b63971fd5b1d94bc09 Found-by: scan-build (clang-tools-9 1:9.0.1-12) Signed-off-by: Paul Menzel pmenzel@molgen.mpg.de Reviewed-on: https://review.coreboot.org/c/coreboot/+/42798 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Patrick Rudolph siro@das-labor.org --- M src/drivers/mrc_cache/mrc_cache.c 1 file changed, 1 insertion(+), 3 deletions(-)
Approvals: build bot (Jenkins): Verified Patrick Rudolph: Looks good to me, approved
diff --git a/src/drivers/mrc_cache/mrc_cache.c b/src/drivers/mrc_cache/mrc_cache.c index 3a005db..d567a20 100644 --- a/src/drivers/mrc_cache/mrc_cache.c +++ b/src/drivers/mrc_cache/mrc_cache.c @@ -447,15 +447,13 @@ /* Apply protection to a range of flash */ static int nvm_protect(const struct region *r) { - const struct spi_flash *flash = boot_device_spi_flash(); - if (!CONFIG(MRC_SETTINGS_PROTECT)) return 0;
if (!CONFIG(BOOT_DEVICE_SPI_FLASH)) return 0;
- return spi_flash_ctrlr_protect_region(flash, r, WRITE_PROTECT); + return spi_flash_ctrlr_protect_region(boot_device_spi_flash(), r, WRITE_PROTECT); }
/* Protect mrc region with a Protected Range Register */