From c2343695e309f2176817dfa836dd42fc6cecc7a3 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sat, 17 Apr 2021 09:34:37 -0500 Subject: arm: zimage: Use correct symbol to hide messages in SPL When zImage support was added to SPL, the messages were hidden to reduce code size. However, the wrong config symbol was used. Since this file is only built when CONFIG_SPL_FRAMEWORK=y, the messages were always hidden. Use the correct symbol so the messages are printed in U-Boot proper. Also use IS_ENABLED to drop the #ifdef. Fixes: 431889d6ad9a ("spl: zImage support in Falcon mode") Signed-off-by: Samuel Holland --- arch/arm/lib/zimage.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/arm/lib/zimage.c b/arch/arm/lib/zimage.c index 477ea94997..45e9c4506a 100644 --- a/arch/arm/lib/zimage.c +++ b/arch/arm/lib/zimage.c @@ -25,18 +25,16 @@ int bootz_setup(ulong image, ulong *start, ulong *end) if (zi->zi_magic != LINUX_ARM_ZIMAGE_MAGIC && zi->zi_magic != BAREBOX_IMAGE_MAGIC) { -#ifndef CONFIG_SPL_FRAMEWORK - puts("zimage: Bad magic!\n"); -#endif + if (!IS_ENABLED(CONFIG_SPL_BUILD)) + puts("zimage: Bad magic!\n"); return 1; } *start = zi->zi_start; *end = zi->zi_end; -#ifndef CONFIG_SPL_FRAMEWORK - printf("Kernel image @ %#08lx [ %#08lx - %#08lx ]\n", - image, *start, *end); -#endif + if (!IS_ENABLED(CONFIG_SPL_BUILD)) + printf("Kernel image @ %#08lx [ %#08lx - %#08lx ]\n", + image, *start, *end); return 0; } -- cgit From dae9aeda45277de24161d0f68f1a9468758f166e Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Sat, 17 Apr 2021 20:52:13 +0800 Subject: fs: btrfs: fix the false alert of decompression failure There are some cases where decompressed sectors can have padding zeros. In kernel code, we have lines to address such situation: /* * btrfs_getblock is doing a zero on the tail of the page too, * but this will cover anything missing from the decompressed * data. */ if (bytes < destlen) memset(kaddr+bytes, 0, destlen-bytes); kunmap_local(kaddr); But not in U-boot code, thus we have some reports of U-boot failed to read compressed files in btrfs. Fix it by doing the same thing of the kernel, for both inline and regular compressed extents. Reported-by: Matwey Kornilov Link: https://bugzilla.suse.com/show_bug.cgi?id=1183717 Fixes: a26a6bedafcf ("fs: btrfs: Introduce btrfs_read_extent_inline() and btrfs_read_extent_reg()") Signed-off-by: Qu Wenruo --- fs/btrfs/inode.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 019d532a1a..2c2379303d 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -390,10 +390,16 @@ int btrfs_read_extent_inline(struct btrfs_path *path, csize); ret = btrfs_decompress(btrfs_file_extent_compression(leaf, fi), cbuf, csize, dbuf, dsize); - if (ret < 0 || ret != dsize) { + if (ret == (u32)-1) { ret = -EIO; goto out; } + /* + * The compressed part ends before sector boundary, the remaining needs + * to be zeroed out. + */ + if (ret < dsize) + memset(dbuf + ret, 0, dsize - ret); memcpy(dest, dbuf, dsize); ret = dsize; out: @@ -494,10 +500,16 @@ int btrfs_read_extent_reg(struct btrfs_path *path, ret = btrfs_decompress(btrfs_file_extent_compression(leaf, fi), cbuf, csize, dbuf, dsize); - if (ret != dsize) { + if (ret == (u32)-1) { ret = -EIO; goto out; } + /* + * The compressed part ends before sector boundary, the remaining needs + * to be zeroed out. + */ + if (ret < dsize) + memset(dbuf + ret, 0, dsize - ret); /* Then copy the needed part */ memcpy(dest, dbuf + btrfs_file_extent_offset(leaf, fi), len); ret = len; -- cgit From 7ac7038ab36feff54e882422de0f3127db094565 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Thu, 22 Apr 2021 09:44:18 +0200 Subject: Makefile: fix generation of defaultenv.h from empty initial file When CONFIG_USE_DEFAULT_ENV_FILE=y and the file CONFIG_DEFAULT_ENV_FILE is empty (or at least doesn't contain any non-comment, non-empty lines), we end up feeding nothing into xxd, which in turn then outputs nothing. Then blindly appending ", 0x00" means that we end up trying to compile (roughly) const char defaultenv[] = { , 0x00 } which is of course broken. To fix that, change the frobbing of the text file so that we always end up printing an extra empty line (which gets turned into that extra nul byte we need) - that corresponds better to the binary format consisting of a series of key=val nul terminated strings, terminated by an empty string. Reported-by: Oleksandr Suvorov Signed-off-by: Rasmus Villemoes Reviewed-by: Oleksandr Suvorov --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index a0ab464ea9..404977efa5 100644 --- a/Makefile +++ b/Makefile @@ -1854,11 +1854,10 @@ define filechk_timestamp.h endef define filechk_defaultenv.h - (grep -v '^#' | \ - grep -v '^$$' | \ + ( { grep -v '^#' | grep -v '^$$' || true ; echo '' ; } | \ tr '\n' '\0' | \ sed -e 's/\\\x0\s*//g' | \ - xxd -i ; echo ", 0x00" ; ) + xxd -i ; ) endef define filechk_dt.h -- cgit From 69414d86ed57bf7b55ccd79d3d5ca5a01987a5b7 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Thu, 22 Apr 2021 18:35:58 +0200 Subject: pinctrl: single: check function mask to be non-zero Otherwise it can generate a division by zero, which has an undefined behavior. Signed-off-by: Dario Binacchi --- drivers/pinctrl/pinctrl-single.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c index 48bdd0f6f5..17f3818dd1 100644 --- a/drivers/pinctrl/pinctrl-single.c +++ b/drivers/pinctrl/pinctrl-single.c @@ -335,6 +335,10 @@ static int single_configure_bits(struct udevice *dev, phys_addr_t reg; u32 offset, val, mask, bit_pos, val_pos, mask_pos, submask; + /* If function mask is null, needn't enable it. */ + if (!pdata->mask) + return 0; + npins_in_reg = pdata->width / priv->bits_per_pin; func = single_allocate_function(dev, count * npins_in_reg); if (IS_ERR(func)) @@ -469,6 +473,11 @@ static int single_probe(struct udevice *dev) priv->npins = size / (pdata->width / BITS_PER_BYTE); if (pdata->bits_per_mux) { + if (!pdata->mask) { + dev_err(dev, "function mask needs to be non-zero\n"); + return -EINVAL; + } + priv->bits_per_pin = fls(pdata->mask); priv->npins *= (pdata->width / priv->bits_per_pin); } -- cgit From 230bc623a49a214bdf1a53971404ab762414ec71 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Thu, 22 Apr 2021 22:28:56 +0200 Subject: pinctrl: single: fix a never true comparison As reported by Coverity Scan for Das U-Boot, the 'less-than-zero' comparison of an unsigned value is never true. Signed-off-by: Dario Binacchi Reviewed-by: Pratyush Yadav --- drivers/pinctrl/pinctrl-single.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c index 17f3818dd1..ebb7602dde 100644 --- a/drivers/pinctrl/pinctrl-single.c +++ b/drivers/pinctrl/pinctrl-single.c @@ -295,7 +295,7 @@ static int single_configure_pins(struct udevice *dev, func->npins = 0; for (n = 0; n < count; n++, pins++) { offset = fdt32_to_cpu(pins->reg); - if (offset < 0 || offset > pdata->offset) { + if (offset > pdata->offset) { dev_err(dev, " invalid register offset 0x%x\n", offset); continue; @@ -348,7 +348,7 @@ static int single_configure_bits(struct udevice *dev, func->npins = 0; for (n = 0; n < count; n++, pins++) { offset = fdt32_to_cpu(pins->reg); - if (offset < 0 || offset > pdata->offset) { + if (offset > pdata->offset) { dev_dbg(dev, " invalid register offset 0x%x\n", offset); continue; -- cgit From 77ed7a2ac975e4b72a1bd87e5c475c08c23bb06a Mon Sep 17 00:00:00 2001 From: Yuichiro Goto Date: Mon, 26 Apr 2021 08:08:03 +0900 Subject: IOMUX: Fix buffer overflow in iomux_replace_device() Use of strcat() against an uninitialized buffer would lead to buffer overflow. This patch fixes it. Fixes: 694cd5618c ("IOMUX: Introduce iomux_replace_device()") Signed-off-by: Yuichiro Goto Cc: Peter Robinson Cc: Andy Shevchenko Cc: Nicolas Saenz Julienne Reviewed-by: Andy Shevchenko Tested-by: Peter Robinson --- common/iomux.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/common/iomux.c b/common/iomux.c index b9088aa3b5..c428f7110a 100644 --- a/common/iomux.c +++ b/common/iomux.c @@ -158,8 +158,12 @@ int iomux_replace_device(const int console, const char *old, const char *new) return -ENOMEM; } - strcat(tmp, ","); - strcat(tmp, name); + if (arg) { + strcat(tmp, ","); + strcat(tmp, name); + } + else + strcpy(tmp, name); arg = tmp; size = strlen(tmp) + 1; -- cgit From bdfe6907e54d6ead19aa07ac4049223e28d4d0a5 Mon Sep 17 00:00:00 2001 From: Neil Armstrong Date: Tue, 20 Apr 2021 10:42:25 +0200 Subject: test: reset: Extend base reset test to catch error With this extended test, we get the following failure : => ut dm reset_base Test: dm_test_reset_base: reset.c test/dm/reset.c:52, dm_test_reset_base(): reset_method3.id == reset_method3_1.id: Expected 0x14 (20), got 0x2 (2) Test: dm_test_reset_base: reset.c (flat tree) test/dm/reset.c:52, dm_test_reset_base(): reset_method3.id == reset_method3_1.id: Expected 0x14 (20), got 0x2 (2) Failures: 2 A fix is needed in reset_get_by_index_nodev() when introduced in [1]. [1] ea9dc35aab ("reset: Get the RESET by index without device") Signed-off-by: Neil Armstrong --- arch/sandbox/dts/test.dts | 4 ++-- test/dm/reset.c | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 48240aa26f..4fde923e9a 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -997,8 +997,8 @@ reset-ctl-test { compatible = "sandbox,reset-ctl-test"; - resets = <&resetc 100>, <&resetc 2>; - reset-names = "other", "test"; + resets = <&resetc 100>, <&resetc 2>, <&resetc 20>, <&resetc 40>; + reset-names = "other", "test", "test2", "test3"; }; rng { diff --git a/test/dm/reset.c b/test/dm/reset.c index fc8e9250b0..9c00452336 100644 --- a/test/dm/reset.c +++ b/test/dm/reset.c @@ -24,18 +24,47 @@ static int dm_test_reset_base(struct unit_test_state *uts) { struct udevice *dev; - struct reset_ctl reset_method1; - struct reset_ctl reset_method2; + struct reset_ctl reset_method1, reset_method1_1; + struct reset_ctl reset_method2, reset_method2_1; + struct reset_ctl reset_method3, reset_method3_1; + struct reset_ctl reset_method4, reset_method4_1; /* Get the device using the reset device */ ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test", &dev)); /* Get the same reset port in 2 different ways and compare */ - ut_assertok(reset_get_by_index(dev, 1, &reset_method1)); + ut_assertok(reset_get_by_index(dev, 0, &reset_method1)); + ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 0, + &reset_method1_1)); + ut_assertok(reset_get_by_index(dev, 1, &reset_method2)); ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 1, - &reset_method2)); - ut_asserteq(reset_method1.id, reset_method2.id); + &reset_method2_1)); + ut_assertok(reset_get_by_index(dev, 2, &reset_method3)); + ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 2, + &reset_method3_1)); + ut_assertok(reset_get_by_index(dev, 3, &reset_method4)); + ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 3, + &reset_method4_1)); + + ut_asserteq(reset_method1.id, reset_method1_1.id); + ut_asserteq(reset_method2.id, reset_method2_1.id); + ut_asserteq(reset_method3.id, reset_method3_1.id); + ut_asserteq(reset_method4.id, reset_method4_1.id); + + ut_asserteq(true, reset_method1.id != reset_method2.id); + ut_asserteq(true, reset_method1.id != reset_method3.id); + ut_asserteq(true, reset_method1.id != reset_method4.id); + ut_asserteq(true, reset_method2.id != reset_method3.id); + ut_asserteq(true, reset_method2.id != reset_method4.id); + ut_asserteq(true, reset_method3.id != reset_method4.id); + + ut_asserteq(true, reset_method1_1.id != reset_method2_1.id); + ut_asserteq(true, reset_method1_1.id != reset_method3_1.id); + ut_asserteq(true, reset_method1_1.id != reset_method4_1.id); + ut_asserteq(true, reset_method2_1.id != reset_method3_1.id); + ut_asserteq(true, reset_method2_1.id != reset_method4_1.id); + ut_asserteq(true, reset_method3_1.id != reset_method4_1.id); return 0; } -- cgit From 67e69660781dac57f4a2347e4ae30d97698f245b Mon Sep 17 00:00:00 2001 From: Neil Armstrong Date: Tue, 20 Apr 2021 10:42:26 +0200 Subject: reset: fix reset_get_by_index_nodev index handling This fixes an issue getting resets index 1 and 3+, the spurius "> 0" made it return the index 0 or 1, whatever index was passed. The dm_test_reset_base() did not catch it, but the dm_test_reset_base() extension catches it and this fixes the regression. This also fixes a reggression on Amlogic G12A/G12B SoCs, where HDMI output was disable even when Linux was booting. Fixes: ea9dc35aab ("reset: Get the RESET by index without device") Reported-by: B1oHazard Signed-off-by: Neil Armstrong --- drivers/reset/reset-uclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c index 071c389ca0..ac89eaf098 100644 --- a/drivers/reset/reset-uclass.c +++ b/drivers/reset/reset-uclass.c @@ -95,7 +95,7 @@ int reset_get_by_index_nodev(ofnode node, int index, int ret; ret = ofnode_parse_phandle_with_args(node, "resets", "#reset-cells", 0, - index > 0, &args); + index, &args); return reset_get_by_index_tail(ret, node, &args, "resets", index > 0, reset_ctl); -- cgit