[PATCH] dma: of-dma: check OF pointer property before dereferencing it

Lars-Peter Clausen lars at metafoo.de
Tue Apr 16 01:22:51 EST 2013


On 04/15/2013 10:39 AM, Paolo Pisati wrote:
> Signed-off-by: Paolo Pisati <paolo.pisati at canonical.com>

That should already be fixed in the DMA tree. See commit 7362f04c28 ("DMA:
OF: Check properties value before running be32_to_cpup() on it").

- Lars


> ---
>  drivers/dma/of-dma.c |    7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
> index 69d04d2..9628298 100644
> --- a/drivers/dma/of-dma.c
> +++ b/drivers/dma/of-dma.c
> @@ -91,6 +91,7 @@ int of_dma_controller_register(struct device_node *np,
>  				(struct of_phandle_args *, struct of_dma *),
>  				void *data)
>  {
> +	void 	*parent;
>  	struct of_dma	*ofdma;
>  	int		nbcells;
>  
> @@ -103,8 +104,10 @@ int of_dma_controller_register(struct device_node *np,
>  	if (!ofdma)
>  		return -ENOMEM;
>  
> -	nbcells = be32_to_cpup(of_get_property(np, "#dma-cells", NULL));
> -	if (!nbcells) {
> +	parent = of_get_property(np, "#dma-cells", NULL);
> +	if (parent)
> +		nbcells = be32_to_cpup(parent);
> +	if (!parent || !nbcells) {
>  		pr_err("%s: #dma-cells property is missing or invalid\n",
>  		       __func__);
>  		kfree(ofdma);



More information about the devicetree-discuss mailing list