2013-05-20 19:17:43

by Fabio Estevam

[permalink] [raw]
Subject: [PATCH] dma: of-dma: Fix "'nbcells' may be used uninitialized" warning

Rearrange the code a bit so that we can get rid of the following build warning:

drivers/dma/of-dma.c:83:15: warning: 'nbcells' may be used uninitialized in this function [-Wuninitialized]

Signed-off-by: Fabio Estevam <[email protected]>
---
drivers/dma/of-dma.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
index 7aa0864..107e820 100644
--- a/drivers/dma/of-dma.c
+++ b/drivers/dma/of-dma.c
@@ -77,15 +77,14 @@ int of_dma_controller_register(struct device_node *np,
return -ENOMEM;

prop = of_get_property(np, "#dma-cells", NULL);
- if (prop)
- nbcells = be32_to_cpup(prop);
+ if (!prop)
+ goto free;
+
+ nbcells = be32_to_cpup(prop);

- if (!prop || !nbcells) {
- pr_err("%s: #dma-cells property is missing or invalid\n",
- __func__);
- kfree(ofdma);
- return -EINVAL;
- }
+
+ if (!nbcells)
+ goto free;

ofdma->of_node = np;
ofdma->of_dma_nbcells = nbcells;
@@ -98,6 +97,11 @@ int of_dma_controller_register(struct device_node *np,
mutex_unlock(&of_dma_lock);

return 0;
+
+free:
+ pr_err("%s: #dma-cells property is missing or invalid\n", __func__);
+ kfree(ofdma);
+ return -EINVAL;
}
EXPORT_SYMBOL_GPL(of_dma_controller_register);

--
1.8.1.2


2013-05-20 19:21:45

by Lars-Peter Clausen

[permalink] [raw]
Subject: Re: [PATCH] dma: of-dma: Fix "'nbcells' may be used uninitialized" warning

On 05/20/2013 09:17 PM, Fabio Estevam wrote:
> Rearrange the code a bit so that we can get rid of the following build warning:
>
> drivers/dma/of-dma.c:83:15: warning: 'nbcells' may be used uninitialized in this function [-Wuninitialized]
>
> Signed-off-by: Fabio Estevam <[email protected]>

Hi,

I've submitted a patch a couple of weeks ago which removes nbcells
altogether. See: https://patchwork.kernel.org/patch/2470601/

- Lars

> ---
> drivers/dma/of-dma.c | 20 ++++++++++++--------
> 1 file changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
> index 7aa0864..107e820 100644
> --- a/drivers/dma/of-dma.c
> +++ b/drivers/dma/of-dma.c
> @@ -77,15 +77,14 @@ int of_dma_controller_register(struct device_node *np,
> return -ENOMEM;
>
> prop = of_get_property(np, "#dma-cells", NULL);
> - if (prop)
> - nbcells = be32_to_cpup(prop);
> + if (!prop)
> + goto free;
> +
> + nbcells = be32_to_cpup(prop);
>
> - if (!prop || !nbcells) {
> - pr_err("%s: #dma-cells property is missing or invalid\n",
> - __func__);
> - kfree(ofdma);
> - return -EINVAL;
> - }
> +
> + if (!nbcells)
> + goto free;
>
> ofdma->of_node = np;
> ofdma->of_dma_nbcells = nbcells;
> @@ -98,6 +97,11 @@ int of_dma_controller_register(struct device_node *np,
> mutex_unlock(&of_dma_lock);
>
> return 0;
> +
> +free:
> + pr_err("%s: #dma-cells property is missing or invalid\n", __func__);
> + kfree(ofdma);
> + return -EINVAL;
> }
> EXPORT_SYMBOL_GPL(of_dma_controller_register);
>