mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings
@ 2022-09-05  9:55 Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 01/32] clk: define stub implementation for clk_get_parent Ahmad Fatoum
                   ` (32 more replies)
  0 siblings, 33 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox

I ran scan-build while building barebox for sandbox with clang and
patched some of the reported issues.

Ahmad Fatoum (32):
  clk: define stub implementation for clk_get_parent
  clk: have SCMI and SiFive clock controllers depend on COMMON_CLK
  meminfo: support SANDBOX build with DEBUG log level
  net: phy: micrel: drop useless assignment of dummy read
  mci: core: drop useless assignment
  nvmem: core: propagate read failure
  fs: remove never-read initializer in mount_all()
  usb: otg: always propagate failure to register parameters
  usb: dwc2: gracefully handle unknown hs_phy_type
  state: propagate failure to fixup enum32 into DT
  of: silence warning about never-read error assignment
  commands: trigger: drop unused variable
  commands: tutorial: fix memory leak
  bthread: fix null pointer dereference in error path
  common: env: drop never-read initialization
  of: refactor for of_fixup_reserved_memory() for clarity
  password: avoid static analyzer false positive
  regmap-mmio: regmap_mmio_get_min_stride: unify branches for
    readability
  crypto: caam - delete unused variable
  misc: ubootvar: always initialize struct ubootvar_data::flag
  nvmem: core: drop always true condition
  of: fdt: gracefully handle out-of-place properties
  of: overlay: drop unused variable of_overlay_apply_dir()
  of: partition: drop unused variable
  serial: ns16550_pci: drop useless assignment
  phy: core: drop useless else clause
  fs: ext4: ext_barebox: handle ext_get_inode() errors
  fs: fat: propagate f_lseek failure
  fs: drop duplicate follow_managed() call
  lib: parse_area_spec: guard against NULL pointer dereference
  net: ping: propagate failure
  net: fastboot: keep error message initialized at all times

 commands/trigger.c                  |  5 +----
 commands/tutorial.c                 |  7 ++----
 common/bthread.c                    |  2 ++
 common/env.c                        |  2 +-
 common/meminfo.c                    |  6 ++++--
 common/oftree.c                     |  6 ++++--
 common/password.c                   |  4 ++--
 common/state/state_variables.c      |  2 ++
 drivers/base/regmap/regmap-mmio.c   |  2 +-
 drivers/clk/Kconfig                 |  5 ++++-
 drivers/crypto/caam/jr.c            |  2 --
 drivers/mci/mci-core.c              |  2 +-
 drivers/misc/ubootvar.c             |  2 +-
 drivers/net/phy/micrel.c            |  2 +-
 drivers/nvmem/core.c                |  8 ++++++-
 drivers/of/fdt.c                    |  2 +-
 drivers/of/overlay.c                |  3 ---
 drivers/of/partition.c              |  3 ---
 drivers/of/resolver.c               |  1 +
 drivers/phy/phy-core.c              |  2 --
 drivers/serial/serial_ns16550_pci.c |  2 +-
 drivers/usb/dwc2/core.c             |  3 +++
 drivers/usb/otg/otgdev.c            | 33 ++++++++++++++++-------------
 fs/ext4/ext_barebox.c               | 18 ++++++++++------
 fs/fat/fat.c                        |  5 +++++
 fs/fs.c                             | 15 ++++---------
 include/linux/clk.h                 | 20 ++++++++++-------
 lib/misc.c                          |  2 ++
 net/fastboot.c                      |  2 ++
 net/net.c                           |  2 +-
 30 files changed, 95 insertions(+), 75 deletions(-)

-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 01/32] clk: define stub implementation for clk_get_parent
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-12  9:23   ` Sascha Hauer
  2022-09-05  9:55 ` [PATCH 02/32] clk: have SCMI and SiFive clock controllers depend on COMMON_CLK Ahmad Fatoum
                   ` (31 subsequent siblings)
  32 siblings, 1 reply; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

To make it easier to build drivers utilizing clk_get_parent on sandbox
for static analysis, provide a stub implementation of the function.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/linux/clk.h | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/include/linux/clk.h b/include/linux/clk.h
index 42c64d650d1f..b18fc733843d 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -128,14 +128,6 @@ int clk_hw_set_rate(struct clk_hw *hw, unsigned long rate);
 int clk_set_parent(struct clk *clk, struct clk *parent);
 int clk_hw_set_parent(struct clk_hw *hw, struct clk_hw *hwp);
 
-/**
- * clk_get_parent - get the parent clock source for this clock
- * @clk: clock source
- *
- * Returns struct clk corresponding to parent clock source, or
- * valid IS_ERR() condition containing errno.
- */
-struct clk *clk_get_parent(struct clk *clk);
 struct clk_hw *clk_hw_get_parent(struct clk_hw *hw);
 
 int clk_set_phase(struct clk *clk, int degrees);
@@ -658,6 +650,14 @@ struct clk_hw *of_clk_hw_simple_get(struct of_phandle_args *clkspec, void *data)
 struct clk *of_clk_get(struct device_node *np, int index);
 struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
 struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
+/**
+ * clk_get_parent - get the parent clock source for this clock
+ * @clk: clock source
+ *
+ * Returns struct clk corresponding to parent clock source, or
+ * valid IS_ERR() condition containing errno.
+ */
+struct clk *clk_get_parent(struct clk *clk);
 unsigned int of_clk_get_parent_count(struct device_node *np);
 int of_clk_parent_fill(struct device_node *np, const char **parents,
 		       unsigned int size);
@@ -717,6 +717,10 @@ static inline unsigned int of_clk_get_parent_count(struct device_node *np)
 {
 	return 0;
 }
+static inline struct clk *clk_get_parent(struct clk *clk)
+{
+	return ERR_PTR(-ENOENT);
+}
 static inline int of_clk_init(struct device_node *root,
 			      const struct of_device_id *matches)
 {
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 02/32] clk: have SCMI and SiFive clock controllers depend on COMMON_CLK
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 01/32] clk: define stub implementation for clk_get_parent Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 03/32] meminfo: support SANDBOX build with DEBUG log level Ahmad Fatoum
                   ` (30 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Both drivers require CCF support, so move these into a new if
COMMON_CLK. As we already have COMMON_CLK_STM32 with the same
requirement, move it in there as well.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/clk/Kconfig | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 5b5acf4e0656..0faea6488e59 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -20,10 +20,11 @@ config CLK_SOCFPGA
 	select COMMON_CLK_OF_PROVIDER
 	default y if ARCH_SOCFPGA && OFDEVICE
 
+if COMMON_CLK
 
 config COMMON_CLK_STM32F
 	bool "STM32F4 and STM32F7 clock driver" if COMPILE_TEST
-	depends on COMMON_CLK && ARCH_STM32
+	depends on ARCH_STM32
 	help
 	  Support for stm32f4 and stm32f7 SoC families clocks
 
@@ -38,3 +39,5 @@ config COMMON_CLK_SCMI
 	  firmware providing all the clock controls.
 
 source "drivers/clk/sifive/Kconfig"
+
+endif
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 03/32] meminfo: support SANDBOX build with DEBUG log level
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 01/32] clk: define stub implementation for clk_get_parent Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 02/32] clk: have SCMI and SiFive clock controllers depend on COMMON_CLK Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 04/32] net: phy: micrel: drop useless assignment of dummy read Ahmad Fatoum
                   ` (29 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We don't necessarily have _[se]text, __bss_(start|stop) symbols on
sandbox, so we shouldn't reference these there in the debug prints.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/meminfo.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/common/meminfo.c b/common/meminfo.c
index e6b251e5bfee..f4994959b6ae 100644
--- a/common/meminfo.c
+++ b/common/meminfo.c
@@ -12,8 +12,10 @@ static int display_meminfo(void)
 	ulong mend   = mem_malloc_end();
 	ulong msize  = mend - mstart + 1;
 
-	pr_debug("barebox code: 0x%p -> 0x%p\n", _stext, _etext - 1);
-	pr_debug("bss segment:  0x%p -> 0x%p\n", __bss_start, __bss_stop - 1);
+	if (!IS_ENABLED(CONFIG_SANDBOX)) {
+		pr_debug("barebox code: 0x%p -> 0x%p\n", _stext, _etext - 1);
+		pr_debug("bss segment:  0x%p -> 0x%p\n", __bss_start, __bss_stop - 1);
+	}
 	pr_info("malloc space: 0x%08lx -> 0x%08lx (size %s)\n",
 		mstart, mend, size_human_readable(msize));
 	return 0;
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 04/32] net: phy: micrel: drop useless assignment of dummy read
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 03/32] meminfo: support SANDBOX build with DEBUG log level Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 05/32] mci: core: drop useless assignment Ahmad Fatoum
                   ` (28 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The result of the PHY read is never used and the comment suggests this
is intentional. Still static analysis warns about this, so remove the
variable assignment and leave the read. We cast it to (void) to avoid
possible future __must_check warnings.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/net/phy/micrel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index cf593ee6a6e6..8a30faa92b8a 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -554,7 +554,7 @@ static int ksz8873mll_read_status(struct phy_device *phydev)
 	int regval;
 
 	/* dummy read */
-	regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4);
+	(void)phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4);
 
 	regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4);
 
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 05/32] mci: core: drop useless assignment
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (3 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 04/32] net: phy: micrel: drop useless assignment of dummy read Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 06/32] nvmem: core: propagate read failure Ahmad Fatoum
                   ` (27 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

rc is never read afterwards anyway, so no point in setting it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mci/mci-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 8c08a4f61f63..a1e27b954375 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1722,8 +1722,8 @@ static int mci_register_partition(struct mci_part *part)
 
 	rc = parse_partition_table(&part->blk);
 	if (rc != 0) {
+		/* Lack of partition table is unusual, but not a failure */
 		dev_warn(&mci->dev, "No partition table found\n");
-		rc = 0; /* it's not a failure */
 	}
 
 	if (np) {
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 06/32] nvmem: core: propagate read failure
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (4 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 05/32] mci: core: drop useless assignment Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 07/32] fs: remove never-read initializer in mount_all() Ahmad Fatoum
                   ` (26 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The read may fail and we may not depend on v's value then. Propagate the
error correctly to fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/nvmem/core.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index c5fe5f6b767a..c344738abd51 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -591,6 +591,9 @@ static inline void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell,
 
 		/* setup the first byte with lsb bits from nvmem */
 		rc = nvmem->bus->read(nvmem->priv, cell->offset, &v, 1);
+		if (IS_ERR_VALUE(rc))
+			return ERR_PTR(rc);
+
 		*b++ |= GENMASK(bit_offset - 1, 0) & v;
 
 		/* setup rest of the byte if any */
@@ -609,6 +612,9 @@ static inline void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell,
 		/* setup the last byte with msb bits from nvmem */
 		rc = nvmem->bus->read(nvmem->priv, cell->offset + cell->bytes - 1,
 				      &v, 1);
+		if (IS_ERR_VALUE(rc))
+			return ERR_PTR(rc);
+
 		*p |= GENMASK(7, (nbits + bit_offset) % BITS_PER_BYTE) & v;
 
 	}
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 07/32] fs: remove never-read initializer in mount_all()
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (5 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 06/32] nvmem: core: propagate read failure Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 08/32] usb: otg: always propagate failure to register parameters Ahmad Fatoum
                   ` (25 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

list_for_each_entry will initialize cdev for each iteration, so the
initial assignment is never used, thus drop it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/fs.c b/fs/fs.c
index 620cd6597a63..14d5f7330457 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1014,7 +1014,7 @@ void mount_all(void)
 		device_detect(dev);
 
 	for_each_block_device(bdev) {
-		struct cdev *cdev = &bdev->cdev;
+		struct cdev *cdev;
 
 		list_for_each_entry(cdev, &bdev->dev->cdevs, devices_list)
 			cdev_mount_default(cdev, NULL);
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 08/32] usb: otg: always propagate failure to register parameters
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (6 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 07/32] fs: remove never-read initializer in mount_all() Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 09/32] usb: dwc2: gracefully handle unknown hs_phy_type Ahmad Fatoum
                   ` (24 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We assign the result of the first dev_add_param_enum() to a variable,
but don't use the variable for anything. Refactor device registration
and parameter addition to a new helper function and do error checking
right.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/usb/otg/otgdev.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/otg/otgdev.c b/drivers/usb/otg/otgdev.c
index 129b1cf5e14b..29cb0d362b9b 100644
--- a/drivers/usb/otg/otgdev.c
+++ b/drivers/usb/otg/otgdev.c
@@ -42,6 +42,22 @@ static const char *otg_mode_names[] = {
 	[USB_DR_MODE_OTG] = "otg",
 };
 
+static int register_otg_device(struct device_d *dev, struct otg_mode *otg)
+{
+	struct param_d *param_mode;
+	int ret;
+
+	ret = register_device(dev);
+	if (ret)
+		return ret;
+
+	param_mode = dev_add_param_enum(dev, "mode",
+			otg_set_mode, NULL, &otg->var_mode,
+			otg_mode_names, ARRAY_SIZE(otg_mode_names), otg);
+
+	return PTR_ERR_OR_ZERO(param_mode);
+}
+
 static struct device_d otg_device = {
 	.name = "otg",
 	.id = DEVICE_ID_SINGLE,
@@ -51,7 +67,6 @@ int usb_register_otg_device(struct device_d *parent,
 			    int (*set_mode)(void *ctx, enum usb_dr_mode mode), void *ctx)
 {
 	int ret;
-	struct param_d *param_mode;
 	struct otg_mode *otg;
 
 	otg = xzalloc(sizeof(*otg));
@@ -68,22 +83,10 @@ int usb_register_otg_device(struct device_d *parent,
 	/* register otg.mode as an alias of otg0.mode */
 	if (otg_device.parent == NULL) {
 		otg_device.parent = parent;
-		ret = register_device(&otg_device);
+		ret = register_otg_device(&otg_device, otg);
 		if (ret)
 			return ret;
-
-		param_mode = dev_add_param_enum(&otg_device, "mode",
-				otg_set_mode, NULL, &otg->var_mode,
-				otg_mode_names, ARRAY_SIZE(otg_mode_names), otg);
 	}
 
-	ret = register_device(&otg->dev);
-	if (ret)
-		return ret;
-
-	param_mode = dev_add_param_enum(&otg->dev, "mode",
-			otg_set_mode, NULL, &otg->var_mode,
-			otg_mode_names, ARRAY_SIZE(otg_mode_names), otg);
-
-	return PTR_ERR_OR_ZERO(param_mode);
+	return register_otg_device(&otg->dev, otg);
 }
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 09/32] usb: dwc2: gracefully handle unknown hs_phy_type
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (7 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 08/32] usb: otg: always propagate failure to register parameters Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 10/32] state: propagate failure to fixup enum32 into DT Ahmad Fatoum
                   ` (23 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Static analysis shows that, we may not enter the switch and thus write
an uninitialized value. Warn if we indeed reach this case and handle it
as if the register read GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED for now.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/usb/dwc2/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 8be5c91f98a1..459ebc65372c 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -61,6 +61,9 @@ static void dwc2_set_param_phy_type(struct dwc2 *dwc2)
 	case GHWCFG2_HS_PHY_TYPE_ULPI:
 		val = DWC2_PHY_TYPE_PARAM_ULPI;
 		break;
+	default:
+		dwc2_warn(dwc2, "Unhandled HS PHY type\n");
+		fallthrough;
 	case GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED:
 		val = DWC2_PHY_TYPE_PARAM_FS;
 		break;
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 10/32] state: propagate failure to fixup enum32 into DT
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (8 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 09/32] usb: dwc2: gracefully handle unknown hs_phy_type Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 11/32] of: silence warning about never-read error assignment Ahmad Fatoum
                   ` (22 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We assign to ret, but don't use the value anywhere laments the static
analyzer. Remedy that.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/state/state_variables.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index f112c60bf602..cb85f3a92602 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -180,6 +180,8 @@ static int state_enum32_export(struct state_variable *var,
 		str += sprintf(str, "%s", enum32->names[i]) + 1;
 
 	ret = of_set_property(node, "names", prop, len, 1);
+	if (ret)
+		return ret;
 
 	free(prop);
 
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 11/32] of: silence warning about never-read error assignment
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (9 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 10/32] state: propagate failure to fixup enum32 into DT Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-12  9:41   ` Sascha Hauer
  2022-09-05  9:55 ` [PATCH 12/32] commands: trigger: drop unused variable Ahmad Fatoum
                   ` (21 subsequent siblings)
  32 siblings, 1 reply; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

err is assigned specific error codes, but they are not propagated and
instead NULL is returned for error. Make it explicit that we handle all
errors the same by typecasting to (void).

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/of/resolver.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c
index 2457ae96a412..510d36f95192 100644
--- a/drivers/of/resolver.c
+++ b/drivers/of/resolver.c
@@ -272,6 +272,7 @@ out:
 err:
 	of_delete_node(result);
 
+	(void)err;
 	return NULL;
 
 }
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 12/32] commands: trigger: drop unused variable
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (10 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 11/32] of: silence warning about never-read error assignment Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 13/32] commands: tutorial: fix memory leak Ahmad Fatoum
                   ` (20 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Static analyzer correctly identifies led as being set, but always
overwritten later on. As the later assignments all have their own
argument count check, so we can just drop the first assignment.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/trigger.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/commands/trigger.c b/commands/trigger.c
index c1402b66f049..d2802080b96f 100644
--- a/commands/trigger.c
+++ b/commands/trigger.c
@@ -16,7 +16,7 @@
 
 static int do_trigger(int argc, char *argv[])
 {
-	struct led *led = NULL;
+	struct led *led;
 	int opt, ret = 0;
 	int cmd = LED_COMMAND_SHOW_INFO;
 	enum led_trigger trigger;
@@ -35,9 +35,6 @@ static int do_trigger(int argc, char *argv[])
 		}
 	}
 
-	if (optind < argc)
-		led = led_by_name_or_number(argv[optind]);
-
 	switch (cmd) {
 	case LED_COMMAND_SHOW_INFO:
 		led_triggers_show_info();
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 13/32] commands: tutorial: fix memory leak
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (11 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 12/32] commands: trigger: drop unused variable Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-12  9:44   ` Sascha Hauer
  2022-09-05  9:55 ` [PATCH 14/32] bthread: fix null pointer dereference in error path Ahmad Fatoum
                   ` (19 subsequent siblings)
  32 siblings, 1 reply; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We don't need to duplicate argv[i], because it persists for the lieftime
of print_tutorial_step. We can thus drop the strdup and while at it,
just drop the redundant step variable altogether.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/tutorial.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/commands/tutorial.c b/commands/tutorial.c
index 444177764311..afe5b66f0b0a 100644
--- a/commands/tutorial.c
+++ b/commands/tutorial.c
@@ -84,7 +84,6 @@ out:
 static int do_tutorial_next(int argc, char *argv[])
 {
 	int opt, i;
-	char *step = NULL;
 	char *oldcwd;
 	ssize_t ret = 0;
 	bool is_prev = *argv[0] == 'p';
@@ -121,14 +120,12 @@ static int do_tutorial_next(int argc, char *argv[])
 		next_step = next_step > 0 ? next_step - 1 : 0;
 
 	if (optind == argc) {
-		step = steps.gl_pathv[next_step];
-		ret = print_tutorial_step(step);
+		ret = print_tutorial_step(steps.gl_pathv[next_step]);
 		if (ret == 0 && !is_prev)
 			next_step = (next_step + 1) % steps.gl_pathc;
 	} else {
 		for (i = optind; i < argc; i++) {
-			step = strdup(argv[i]);
-			ret = print_tutorial_step(step);
+			ret = print_tutorial_step(argv[i]);
 			if (ret)
 				break;
 		}
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 14/32] bthread: fix null pointer dereference in error path
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (12 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 13/32] commands: tutorial: fix memory leak Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 15/32] common: env: drop never-read initialization Ahmad Fatoum
                   ` (18 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

When borting bthread creation early, we would end up calling
bthread_free on a NULL bthread, causing a NULL pointer dereference.

As it's customary for free functions to gracefully handle a NULL
argument, have bthread_free follow suit.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/bthread.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/common/bthread.c b/common/bthread.c
index 46e6987149bb..d40c0b0f9e3a 100644
--- a/common/bthread.c
+++ b/common/bthread.c
@@ -70,6 +70,8 @@ bool bthread_is_main(struct bthread *bthread)
 
 static void bthread_free(struct bthread *bthread)
 {
+	if (!bthread)
+		return;
 	free(bthread->stack);
 	free(bthread->name);
 	free(bthread);
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 15/32] common: env: drop never-read initialization
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (13 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 14/32] bthread: fix null pointer dereference in error path Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 16/32] of: refactor for of_fixup_reserved_memory() for clarity Ahmad Fatoum
                   ` (17 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

c is used a temporary variable later on for context pushing and its
initializer is never read, so drop it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/env.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/env.c b/common/env.c
index 5ac1e62b8c79..9e9988e415cf 100644
--- a/common/env.c
+++ b/common/env.c
@@ -80,7 +80,7 @@ int env_push_context(void)
  */
 int env_pop_context(void)
 {
-	struct env_context *c = context;
+	struct env_context *c;
 
 	if (context->parent) {
 		c = context->parent;
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 16/32] of: refactor for of_fixup_reserved_memory() for clarity
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (14 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 15/32] common: env: drop never-read initialization Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 17/32] password: avoid static analyzer false positive Ahmad Fatoum
                   ` (16 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

pp was never used and the ?: construct made the code needlessly terse.
Use it and make the code a bit clearer.

No functional change.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/oftree.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/common/oftree.c b/common/oftree.c
index e459f84601a3..38752e2c191d 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -292,8 +292,10 @@ int of_fixup_reserved_memory(struct device_node *root, void *_res)
 	if (ret)
 		of_property_write_u32(node, "#size-cells", size_n_cells);
 
-	pp = of_find_property(node, "ranges", &rangelen) ?: of_new_property(node, "ranges", NULL, 0);
-	if (rangelen) {
+	pp = of_find_property(node, "ranges", &rangelen);
+	if (!pp) {
+		of_new_property(node, "ranges", NULL, 0);
+	} else if (rangelen) {
 		pr_warn("reserved-memory ranges not 1:1 mapped. Aborting fixup\n");
 		return -EINVAL;
 	}
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 17/32] password: avoid static analyzer false positive
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (15 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 16/32] of: refactor for of_fixup_reserved_memory() for clarity Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 18/32] regmap-mmio: regmap_mmio_get_min_stride: unify branches for readability Ahmad Fatoum
                   ` (15 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

default_passwd is a compile-time constant. In case, where it's unset,
the function will early-return and the static analyzer will warn about
len being initialized, but never used, move the length calculation later
to avoid this false positive.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/password.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/password.c b/common/password.c
index aea7c7ff5d21..55b2d1093ab9 100644
--- a/common/password.c
+++ b/common/password.c
@@ -148,8 +148,7 @@ static unsigned char to_hexa(unsigned char c)
 
 static int read_default_passwd(unsigned char *sum, size_t length)
 {
-	int i = 0;
-	int len = strlen(default_passwd);
+	int len, i = 0;
 	unsigned char *buf = (unsigned char *)default_passwd;
 	unsigned char c;
 
@@ -159,6 +158,7 @@ static int read_default_passwd(unsigned char *sum, size_t length)
 	if (!sum || length < 1)
 		return -EINVAL;
 
+	len = strlen(default_passwd);
 	for (i = 0; i < len && length > 0; i++) {
 		c = buf[i];
 		i++;
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 18/32] regmap-mmio: regmap_mmio_get_min_stride: unify branches for readability
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (16 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 17/32] password: avoid static analyzer false positive Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 19/32] crypto: caam - delete unused variable Ahmad Fatoum
                   ` (14 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We just return min_stride after the switch statement, so instead of
returning 0 directly for 8 bits, just have all code reach the same return
at the end.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/base/regmap/regmap-mmio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c
index c8422ca46f3c..7b1501df933b 100644
--- a/drivers/base/regmap/regmap-mmio.c
+++ b/drivers/base/regmap/regmap-mmio.c
@@ -46,7 +46,7 @@ static int regmap_mmio_get_min_stride(size_t val_bits)
 	case 8:
 		/* The core treats 0 as 1 */
 		min_stride = 0;
-		return 0;
+		break;
 	case 16:
 		min_stride = 2;
 		break;
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 19/32] crypto: caam - delete unused variable
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (17 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 18/32] regmap-mmio: regmap_mmio_get_min_stride: unify branches for readability Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 20/32] misc: ubootvar: always initialize struct ubootvar_data::flag Ahmad Fatoum
                   ` (13 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We don't use nprop anywhere, so drop it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/crypto/caam/jr.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index 70e016486a7e..6c4867914753 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -289,7 +289,6 @@ static int caam_jr_init(struct device_d *dev)
  */
 int caam_jr_probe(struct device_d *dev)
 {
-	struct device_node *nprop;
 	struct caam_job_ring __iomem *ctrl;
 	struct caam_drv_private_jr *jrpriv;
 	static int total_jobrs;
@@ -303,7 +302,6 @@ int caam_jr_probe(struct device_d *dev)
 	/* save ring identity relative to detection */
 	jrpriv->ridx = total_jobrs++;
 
-	nprop = dev->device_node;
 	/* Get configuration properties from device tree */
 	/* First, get register page */
 	ctrl = dev_get_mem_region(dev, 0);
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 20/32] misc: ubootvar: always initialize struct ubootvar_data::flag
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (18 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 19/32] crypto: caam - delete unused variable Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 21/32] nvmem: core: drop always true condition Ahmad Fatoum
                   ` (12 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The flag member is only relevant to redundant environments, still we
shouldn't store garbage there for the non-redundant case. Thus
initialize it to an acceptable default: FLAG_NONE.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/misc/ubootvar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/ubootvar.c b/drivers/misc/ubootvar.c
index d98a6ed9a742..723e9e2b547a 100644
--- a/drivers/misc/ubootvar.c
+++ b/drivers/misc/ubootvar.c
@@ -181,7 +181,7 @@ static int ubootenv_probe(struct device_d *dev)
 	unsigned int crc_ok = 0;
 	int ret, i, current, count = 0;
 	uint32_t crc[2];
-	uint8_t flag[2];
+	uint8_t flag[2] = { FLAG_NONE, FLAG_NONE };
 	size_t size[2];
 	void *blob[2] = { NULL, NULL };
 	uint8_t *data[2];
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 21/32] nvmem: core: drop always true condition
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (19 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 20/32] misc: ubootvar: always initialize struct ubootvar_data::flag Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 22/32] of: fdt: gracefully handle out-of-place properties Ahmad Fatoum
                   ` (11 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The iterator in a list_for_each_entry's body can never be NULL, so drop
the needless NULL check.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/nvmem/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index c344738abd51..c89ad08f81d8 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -136,7 +136,7 @@ static struct nvmem_cell *nvmem_find_cell(const char *cell_id)
 	struct nvmem_cell *p;
 
 	list_for_each_entry(p, &nvmem_cells, node)
-		if (p && !strcmp(p->name, cell_id))
+		if (!strcmp(p->name, cell_id))
 			return p;
 
 	return NULL;
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 22/32] of: fdt: gracefully handle out-of-place properties
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (20 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 21/32] nvmem: core: drop always true condition Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 23/32] of: overlay: drop unused variable of_overlay_apply_dir() Ahmad Fatoum
                   ` (10 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

node is initialized by FDT_BEGIN_NODE. In case where a FDT_PROP is
encountered before the first FDT_BEGIN_NODE, we would end up
dereferencing a NULL pointer. Handle such malformed device trees
gracefully by returning with an -ESPIPE error instead.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/of/fdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 42f45bbd4fb5..01d7dc37439f 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -212,7 +212,7 @@ static struct device_node *__of_unflatten_dtb(const void *infdt, int size,
 			nodep = fdt_prop->data;
 
 			name = dt_string(&f, dt_strings, fdt32_to_cpu(fdt_prop->nameoff));
-			if (!name) {
+			if (!name || !node) {
 				ret = -ESPIPE;
 				goto err;
 			}
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 23/32] of: overlay: drop unused variable of_overlay_apply_dir()
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (21 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 22/32] of: fdt: gracefully handle out-of-place properties Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 24/32] of: partition: drop unused variable Ahmad Fatoum
                   ` (9 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

This seems to be a copy-paste left-over from of_overlay_filter_filename,
which has some actual use for both p and path. We don't though and just
end up leaking the buffer, so drop these variables.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/of/overlay.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 20a43f5170c8..fff1d6ea028e 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -418,7 +418,6 @@ void of_overlay_set_basedir(const char *path)
 static int of_overlay_apply_dir(struct device_node *root, const char *dirname,
 				bool filter)
 {
-	char *p, *path;
 	int ret = 0;
 	DIR *dir;
 
@@ -431,8 +430,6 @@ static int of_overlay_apply_dir(struct device_node *root, const char *dirname,
 	if (!dir)
 		return -errno;
 
-	p = path = strdup(of_overlay_filepattern);
-
 	while (1) {
 		struct dirent *ent;
 		char *filename;
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 24/32] of: partition: drop unused variable
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (22 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 23/32] of: overlay: drop unused variable of_overlay_apply_dir() Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 25/32] serial: ns16550_pci: drop useless assignment Ahmad Fatoum
                   ` (8 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The name variable is unused anywhere, so just drop it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/of/partition.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index 6c05e28ea9a8..abbda674d6cb 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -31,7 +31,6 @@ struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node)
 	struct cdev *new;
 	const __be32 *reg;
 	u64 offset, size;
-	const char *name;
 	int len;
 	unsigned long flags = 0;
 	int na, ns;
@@ -60,8 +59,6 @@ struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node)
 	if (!partname)
 		return NULL;
 
-	name = (char *)partname;
-
 	debug("add partition: %s.%s 0x%08llx 0x%08llx\n", cdev->name, partname, offset, size);
 
 	if (of_get_property(node, "read-only", NULL))
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 25/32] serial: ns16550_pci: drop useless assignment
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (23 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 24/32] of: partition: drop unused variable Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 26/32] phy: core: drop useless else clause Ahmad Fatoum
                   ` (7 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Code was imported from the kernel and the kernel had this fixed in the
meantime, so follow suit here.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/serial/serial_ns16550_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/serial/serial_ns16550_pci.c b/drivers/serial/serial_ns16550_pci.c
index fde8f718dd51..0d7b686fef0a 100644
--- a/drivers/serial/serial_ns16550_pci.c
+++ b/drivers/serial/serial_ns16550_pci.c
@@ -1203,7 +1203,7 @@ static int pci_quatech_init(struct pci_dev *dev)
 			outl(inl(base + 0x38) | 0x00002000, base + 0x38);
 			tmp = inl(base + 0x3c);
 			outl(tmp | 0x01000000, base + 0x3c);
-			outl(tmp &= ~0x01000000, base + 0x3c);
+			outl(tmp & ~0x01000000, base + 0x3c);
 		}
 	}
 	return 0;
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 26/32] phy: core: drop useless else clause
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (24 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 25/32] serial: ns16550_pci: drop useless assignment Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 27/32] fs: ext4: ext_barebox: handle ext_get_inode() errors Ahmad Fatoum
                   ` (6 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

ret is not read below, so we don't need this override.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/phy/phy-core.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 8a57bd1aa9d4..3a36f0a1b26d 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -169,8 +169,6 @@ int phy_power_on(struct phy *phy)
 			dev_err(&phy->dev, "phy poweron failed --> %d\n", ret);
 			goto out;
 		}
-	} else {
-		ret = 0; /* Override possible ret == -ENOTSUPP */
 	}
 	++phy->power_count;
 
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 27/32] fs: ext4: ext_barebox: handle ext_get_inode() errors
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (25 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 26/32] phy: core: drop useless else clause Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 28/32] fs: fat: propagate f_lseek failure Ahmad Fatoum
                   ` (5 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Static analyzer laments ext_get_inode, which can fail not having its
failure condition checked. Fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/ext4/ext_barebox.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/fs/ext4/ext_barebox.c b/fs/ext4/ext_barebox.c
index 8f318a49c008..6c7c9885c48f 100644
--- a/fs/ext4/ext_barebox.c
+++ b/fs/ext4/ext_barebox.c
@@ -127,8 +127,8 @@ static struct dentry *ext_lookup(struct inode *dir, struct dentry *dentry,
 
 	if (ino) {
 		inode = ext_get_inode(dir->i_sb, ino);
-
-		d_add(dentry, inode);
+		if (inode)
+			d_add(dentry, inode);
 	}
 
 	return NULL;
@@ -218,6 +218,8 @@ struct inode *ext_get_inode(struct super_block *sb, int ino)
 	node = container_of(inode, struct ext2fs_node, i);
 
 	ret = ext4fs_read_inode(fs->data, ino, &node->inode);
+	if (ret)
+		return NULL;
 
 	inode->i_ino = ino;
 	inode->i_mode = le16_to_cpu(node->inode.mode);
@@ -262,23 +264,27 @@ static int ext_probe(struct device_d *dev)
 
 	ret = fsdev_open_cdev(fsdev);
 	if (ret)
-		goto err_open;
+		goto err;
 
 	fs->cdev = fsdev->cdev;
 
 	ret = ext4fs_mount(fs);
 	if (ret)
-		goto err_mount;
+		goto err;
 
 	sb->s_op = &ext_ops;
 
 	inode = ext_get_inode(sb, 2);
+	if (!inode) {
+		ret = -EINVAL;
+		goto err;
+	}
+
 	sb->s_root = d_make_root(inode);
 
 	return 0;
 
-err_mount:
-err_open:
+err:
 	free(fs);
 
 	return ret;
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 28/32] fs: fat: propagate f_lseek failure
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (26 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 27/32] fs: ext4: ext_barebox: handle ext_get_inode() errors Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 29/32] fs: drop duplicate follow_managed() call Ahmad Fatoum
                   ` (4 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We store an error code to ret, but don't act on it. Fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/fat/fat.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 84bfe69089e5..7d888817c145 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -196,6 +196,11 @@ static int fat_open(struct device_d *dev, FILE *file, const char *filename)
 
 	if (file->flags & O_APPEND) {
 		ret = f_lseek(f_file, f_file->fsize);
+		if (ret) {
+			f_close(f_file);
+			free(f_file);
+			return -EINVAL;
+		}
 	}
 
 	file->priv = f_file;
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 29/32] fs: drop duplicate follow_managed() call
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (27 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 28/32] fs: fat: propagate f_lseek failure Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 30/32] lib: parse_area_spec: guard against NULL pointer dereference Ahmad Fatoum
                   ` (3 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

lookup_fast called above already calls follow_managed with the same
argument, so no need to duplicate the call here.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/fs.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 14d5f7330457..78878e7112d5 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1838,16 +1838,9 @@ static int walk_component(struct nameidata *nd, int flags)
 	if (err < 0)
 		return err;
 
-	if (err == 0) {
-		path.mnt = nd->path.mnt;
-		err = follow_managed(&path, nd);
-		if (err < 0)
-			return err;
-
-		if (d_is_negative(path.dentry)) {
-			path_to_nameidata(&path, nd);
-			return -ENOENT;
-		}
+	if (err == 0 && d_is_negative(path.dentry)) {
+		path_to_nameidata(&path, nd);
+		return -ENOENT;
 	}
 
 	return step_into(nd, &path, flags, d_inode(path.dentry));
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 30/32] lib: parse_area_spec: guard against NULL pointer dereference
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (28 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 29/32] fs: drop duplicate follow_managed() call Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 31/32] net: ping: propagate failure Ahmad Fatoum
                   ` (2 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

If mem_parse_options is called with an optstr containing x, but with
swab == NULL, we will end up doing a NULL pointer dereference. Add a
check that avoids this from happening.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 lib/misc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/misc.c b/lib/misc.c
index 532f0bfc1eb5..2d5f7c198586 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -159,6 +159,8 @@ int mem_parse_options(int argc, char *argv[], char *optstr, int *mode,
 			*destfile = optarg;
 			break;
 		case 'x':
+			if (!swab)
+				return -EINVAL;
 			*swab = 1;
 			break;
 		default:
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 31/32] net: ping: propagate failure
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (29 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 30/32] lib: parse_area_spec: guard against NULL pointer dereference Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-05  9:55 ` [PATCH 32/32] net: fastboot: keep error message initialized at all times Ahmad Fatoum
  2022-09-12 10:06 ` [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Sascha Hauer
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We populate ret, but don't do anything with it. Pass it along instead.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 net/net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/net.c b/net/net.c
index eae45e184359..22931509d0d9 100644
--- a/net/net.c
+++ b/net/net.c
@@ -634,7 +634,7 @@ static int ping_reply(struct eth_device *edev, unsigned char *pkt, int len)
 
 	free(packet);
 
-	return 0;
+	return ret;
 }
 
 static int net_handle_icmp(struct eth_device *edev, unsigned char *pkt, int len)
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 32/32] net: fastboot: keep error message initialized at all times
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (30 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 31/32] net: ping: propagate failure Ahmad Fatoum
@ 2022-09-05  9:55 ` Ahmad Fatoum
  2022-09-12 10:06 ` [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Sascha Hauer
  32 siblings, 0 replies; 37+ messages in thread
From: Ahmad Fatoum @ 2022-09-05  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Static analyzer points out that an unfortunate sequence of fastboot
commands can have us end up with an uninitialized error_msg, so
initialize it in that case, so we have something in there at all times.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 net/fastboot.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/fastboot.c b/net/fastboot.c
index aa483f57a74e..932eb05c4341 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -126,6 +126,8 @@ static void fastboot_send(struct fastboot_net *fbn,
 
 	if (error_msg)
 		header.id = FASTBOOT_ERROR;
+	else
+		error_msg = "no error";
 
 	/* send header */
 	memcpy(packet, &header, sizeof(header));
-- 
2.30.2




^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 01/32] clk: define stub implementation for clk_get_parent
  2022-09-05  9:55 ` [PATCH 01/32] clk: define stub implementation for clk_get_parent Ahmad Fatoum
@ 2022-09-12  9:23   ` Sascha Hauer
  0 siblings, 0 replies; 37+ messages in thread
From: Sascha Hauer @ 2022-09-12  9:23 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Sep 05, 2022 at 11:55:26AM +0200, Ahmad Fatoum wrote:
> To make it easier to build drivers utilizing clk_get_parent on sandbox
> for static analysis, provide a stub implementation of the function.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  include/linux/clk.h | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)

This will break architectures which do not use the common clk framework
and implement clk_get_parent themselves.

Fortunately there's only one architecture left doing this: AT91

Sascha

> 
> diff --git a/include/linux/clk.h b/include/linux/clk.h
> index 42c64d650d1f..b18fc733843d 100644
> --- a/include/linux/clk.h
> +++ b/include/linux/clk.h
> @@ -128,14 +128,6 @@ int clk_hw_set_rate(struct clk_hw *hw, unsigned long rate);
>  int clk_set_parent(struct clk *clk, struct clk *parent);
>  int clk_hw_set_parent(struct clk_hw *hw, struct clk_hw *hwp);
>  
> -/**
> - * clk_get_parent - get the parent clock source for this clock
> - * @clk: clock source
> - *
> - * Returns struct clk corresponding to parent clock source, or
> - * valid IS_ERR() condition containing errno.
> - */
> -struct clk *clk_get_parent(struct clk *clk);
>  struct clk_hw *clk_hw_get_parent(struct clk_hw *hw);
>  
>  int clk_set_phase(struct clk *clk, int degrees);
> @@ -658,6 +650,14 @@ struct clk_hw *of_clk_hw_simple_get(struct of_phandle_args *clkspec, void *data)
>  struct clk *of_clk_get(struct device_node *np, int index);
>  struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
>  struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
> +/**
> + * clk_get_parent - get the parent clock source for this clock
> + * @clk: clock source
> + *
> + * Returns struct clk corresponding to parent clock source, or
> + * valid IS_ERR() condition containing errno.
> + */
> +struct clk *clk_get_parent(struct clk *clk);
>  unsigned int of_clk_get_parent_count(struct device_node *np);
>  int of_clk_parent_fill(struct device_node *np, const char **parents,
>  		       unsigned int size);
> @@ -717,6 +717,10 @@ static inline unsigned int of_clk_get_parent_count(struct device_node *np)
>  {
>  	return 0;
>  }
> +static inline struct clk *clk_get_parent(struct clk *clk)
> +{
> +	return ERR_PTR(-ENOENT);
> +}
>  static inline int of_clk_init(struct device_node *root,
>  			      const struct of_device_id *matches)
>  {
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 11/32] of: silence warning about never-read error assignment
  2022-09-05  9:55 ` [PATCH 11/32] of: silence warning about never-read error assignment Ahmad Fatoum
@ 2022-09-12  9:41   ` Sascha Hauer
  0 siblings, 0 replies; 37+ messages in thread
From: Sascha Hauer @ 2022-09-12  9:41 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Sep 05, 2022 at 11:55:36AM +0200, Ahmad Fatoum wrote:
> err is assigned specific error codes, but they are not propagated and
> instead NULL is returned for error. Make it explicit that we handle all
> errors the same by typecasting to (void).

This warning likely goes back to assigning the variable 'err' right
before jumping to the label 'err':

	err = -EINVAL;
	goto err;

The assignment is indeed unused. We should remove this assignment
rather than suppressing the resulting warning.

Sascha

> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/of/resolver.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c
> index 2457ae96a412..510d36f95192 100644
> --- a/drivers/of/resolver.c
> +++ b/drivers/of/resolver.c
> @@ -272,6 +272,7 @@ out:
>  err:
>  	of_delete_node(result);
>  
> +	(void)err;
>  	return NULL;
>  
>  }
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 13/32] commands: tutorial: fix memory leak
  2022-09-05  9:55 ` [PATCH 13/32] commands: tutorial: fix memory leak Ahmad Fatoum
@ 2022-09-12  9:44   ` Sascha Hauer
  0 siblings, 0 replies; 37+ messages in thread
From: Sascha Hauer @ 2022-09-12  9:44 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Sep 05, 2022 at 11:55:38AM +0200, Ahmad Fatoum wrote:
> We don't need to duplicate argv[i], because it persists for the lieftime

s/lieftime/lifetime/

> of print_tutorial_step. We can thus drop the strdup and while at it,
> just drop the redundant step variable altogether.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  commands/tutorial.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/commands/tutorial.c b/commands/tutorial.c
> index 444177764311..afe5b66f0b0a 100644
> --- a/commands/tutorial.c
> +++ b/commands/tutorial.c
> @@ -84,7 +84,6 @@ out:
>  static int do_tutorial_next(int argc, char *argv[])
>  {
>  	int opt, i;
> -	char *step = NULL;
>  	char *oldcwd;
>  	ssize_t ret = 0;
>  	bool is_prev = *argv[0] == 'p';
> @@ -121,14 +120,12 @@ static int do_tutorial_next(int argc, char *argv[])
>  		next_step = next_step > 0 ? next_step - 1 : 0;
>  
>  	if (optind == argc) {
> -		step = steps.gl_pathv[next_step];
> -		ret = print_tutorial_step(step);
> +		ret = print_tutorial_step(steps.gl_pathv[next_step]);
>  		if (ret == 0 && !is_prev)
>  			next_step = (next_step + 1) % steps.gl_pathc;
>  	} else {
>  		for (i = optind; i < argc; i++) {
> -			step = strdup(argv[i]);
> -			ret = print_tutorial_step(step);
> +			ret = print_tutorial_step(argv[i]);
>  			if (ret)
>  				break;
>  		}
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings
  2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
                   ` (31 preceding siblings ...)
  2022-09-05  9:55 ` [PATCH 32/32] net: fastboot: keep error message initialized at all times Ahmad Fatoum
@ 2022-09-12 10:06 ` Sascha Hauer
  32 siblings, 0 replies; 37+ messages in thread
From: Sascha Hauer @ 2022-09-12 10:06 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Sep 05, 2022 at 11:55:25AM +0200, Ahmad Fatoum wrote:
> I ran scan-build while building barebox for sandbox with clang and
> patched some of the reported issues.
> 
> Ahmad Fatoum (32):
>   clk: define stub implementation for clk_get_parent
>   clk: have SCMI and SiFive clock controllers depend on COMMON_CLK
>   meminfo: support SANDBOX build with DEBUG log level
>   net: phy: micrel: drop useless assignment of dummy read
>   mci: core: drop useless assignment
>   nvmem: core: propagate read failure
>   fs: remove never-read initializer in mount_all()
>   usb: otg: always propagate failure to register parameters
>   usb: dwc2: gracefully handle unknown hs_phy_type
>   state: propagate failure to fixup enum32 into DT
>   of: silence warning about never-read error assignment
>   commands: trigger: drop unused variable
>   commands: tutorial: fix memory leak
>   bthread: fix null pointer dereference in error path
>   common: env: drop never-read initialization
>   of: refactor for of_fixup_reserved_memory() for clarity
>   password: avoid static analyzer false positive
>   regmap-mmio: regmap_mmio_get_min_stride: unify branches for
>     readability
>   crypto: caam - delete unused variable
>   misc: ubootvar: always initialize struct ubootvar_data::flag
>   nvmem: core: drop always true condition
>   of: fdt: gracefully handle out-of-place properties
>   of: overlay: drop unused variable of_overlay_apply_dir()
>   of: partition: drop unused variable
>   serial: ns16550_pci: drop useless assignment
>   phy: core: drop useless else clause
>   fs: ext4: ext_barebox: handle ext_get_inode() errors
>   fs: fat: propagate f_lseek failure
>   fs: drop duplicate follow_managed() call
>   lib: parse_area_spec: guard against NULL pointer dereference
>   net: ping: propagate failure
>   net: fastboot: keep error message initialized at all times

Applied 2-10 and 12-32, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2022-09-12 10:15 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 01/32] clk: define stub implementation for clk_get_parent Ahmad Fatoum
2022-09-12  9:23   ` Sascha Hauer
2022-09-05  9:55 ` [PATCH 02/32] clk: have SCMI and SiFive clock controllers depend on COMMON_CLK Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 03/32] meminfo: support SANDBOX build with DEBUG log level Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 04/32] net: phy: micrel: drop useless assignment of dummy read Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 05/32] mci: core: drop useless assignment Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 06/32] nvmem: core: propagate read failure Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 07/32] fs: remove never-read initializer in mount_all() Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 08/32] usb: otg: always propagate failure to register parameters Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 09/32] usb: dwc2: gracefully handle unknown hs_phy_type Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 10/32] state: propagate failure to fixup enum32 into DT Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 11/32] of: silence warning about never-read error assignment Ahmad Fatoum
2022-09-12  9:41   ` Sascha Hauer
2022-09-05  9:55 ` [PATCH 12/32] commands: trigger: drop unused variable Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 13/32] commands: tutorial: fix memory leak Ahmad Fatoum
2022-09-12  9:44   ` Sascha Hauer
2022-09-05  9:55 ` [PATCH 14/32] bthread: fix null pointer dereference in error path Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 15/32] common: env: drop never-read initialization Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 16/32] of: refactor for of_fixup_reserved_memory() for clarity Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 17/32] password: avoid static analyzer false positive Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 18/32] regmap-mmio: regmap_mmio_get_min_stride: unify branches for readability Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 19/32] crypto: caam - delete unused variable Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 20/32] misc: ubootvar: always initialize struct ubootvar_data::flag Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 21/32] nvmem: core: drop always true condition Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 22/32] of: fdt: gracefully handle out-of-place properties Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 23/32] of: overlay: drop unused variable of_overlay_apply_dir() Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 24/32] of: partition: drop unused variable Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 25/32] serial: ns16550_pci: drop useless assignment Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 26/32] phy: core: drop useless else clause Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 27/32] fs: ext4: ext_barebox: handle ext_get_inode() errors Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 28/32] fs: fat: propagate f_lseek failure Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 29/32] fs: drop duplicate follow_managed() call Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 30/32] lib: parse_area_spec: guard against NULL pointer dereference Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 31/32] net: ping: propagate failure Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 32/32] net: fastboot: keep error message initialized at all times Ahmad Fatoum
2022-09-12 10:06 ` [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox