2023-02-17 15:31:37

by Ivan Bornyakov

[permalink] [raw]
Subject: [PATCH] bus: imx-weim: fix branch condition evaluates to a garbage value

If bus type is other than imx50_weim_devtype and have no child devices,
variable 'ret' in function weim_parse_dt() will not be initialized, but
will be used as branch condition and return value. Fix this by
initializing 'ret' with 0.

This was discovered with help of clang-analyzer, but the situation is
quite possible in real life.

Signed-off-by: Ivan Bornyakov <[email protected]>
Cc: [email protected]
---
drivers/bus/imx-weim.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
index 828c66bbaa67..55d917bd1f3f 100644
--- a/drivers/bus/imx-weim.c
+++ b/drivers/bus/imx-weim.c
@@ -204,8 +204,8 @@ static int weim_parse_dt(struct platform_device *pdev)
const struct of_device_id *of_id = of_match_device(weim_id_table,
&pdev->dev);
const struct imx_weim_devtype *devtype = of_id->data;
+ int ret = 0, have_child = 0;
struct device_node *child;
- int ret, have_child = 0;
struct weim_priv *priv;
void __iomem *base;
u32 reg;
--
2.39.2




2023-02-24 06:06:09

by Ivan Bornyakov

[permalink] [raw]
Subject: Re: [PATCH] bus: imx-weim: fix branch condition evaluates to a garbage value

On Fri, Feb 17, 2023 at 04:59:50PM +0300, Ivan Bornyakov wrote:
> If bus type is other than imx50_weim_devtype and have no child devices,
> variable 'ret' in function weim_parse_dt() will not be initialized, but
> will be used as branch condition and return value. Fix this by
> initializing 'ret' with 0.
>
> This was discovered with help of clang-analyzer, but the situation is
> quite possible in real life.
>
> Signed-off-by: Ivan Bornyakov <[email protected]>
> Cc: [email protected]
> ---
> drivers/bus/imx-weim.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
> index 828c66bbaa67..55d917bd1f3f 100644
> --- a/drivers/bus/imx-weim.c
> +++ b/drivers/bus/imx-weim.c
> @@ -204,8 +204,8 @@ static int weim_parse_dt(struct platform_device *pdev)
> const struct of_device_id *of_id = of_match_device(weim_id_table,
> &pdev->dev);
> const struct imx_weim_devtype *devtype = of_id->data;
> + int ret = 0, have_child = 0;
> struct device_node *child;
> - int ret, have_child = 0;
> struct weim_priv *priv;
> void __iomem *base;
> u32 reg;
> --
> 2.39.2
>

Friendly ping.


2023-03-14 01:19:25

by Shawn Guo

[permalink] [raw]
Subject: Re: [PATCH] bus: imx-weim: fix branch condition evaluates to a garbage value

On Fri, Feb 17, 2023 at 04:59:50PM +0300, Ivan Bornyakov wrote:
> If bus type is other than imx50_weim_devtype and have no child devices,
> variable 'ret' in function weim_parse_dt() will not be initialized, but
> will be used as branch condition and return value. Fix this by
> initializing 'ret' with 0.
>
> This was discovered with help of clang-analyzer, but the situation is
> quite possible in real life.
>
> Signed-off-by: Ivan Bornyakov <[email protected]>
> Cc: [email protected]

Applied with Fixes tag below. Let me know if it's incorrect.

Fixes: 52c47b63412b ("bus: imx-weim: improve error handling upon child probe-failure")

Shawn