diff mbox

[2/2] DMA: PL330: Check the pointer returned by kzalloc

Message ID 1347875423-7970-2-git-send-email-sachin.kamat@linaro.org
State Accepted
Headers show

Commit Message

Sachin Kamat Sept. 17, 2012, 9:50 a.m. UTC
kzalloc could return NULL. Hence add a check to avoid
NULL pointer dereference.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
 drivers/dma/pl330.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

Comments

Jassi Brar Sept. 17, 2012, 11:59 a.m. UTC | #1
On Mon, Sep 17, 2012 at 3:20 PM, Sachin Kamat <sachin.kamat@linaro.org> wrote:
> kzalloc could return NULL. Hence add a check to avoid
> NULL pointer dereference.
>
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>

Patch 1 and 2, both
Acked-by: Jassi Brar <jassisinghbrar@gmail.com>
Vinod Koul Sept. 18, 2012, 3:36 a.m. UTC | #2
On Mon, 2012-09-17 at 15:20 +0530, Sachin Kamat wrote:
> kzalloc could return NULL. Hence add a check to avoid
> NULL pointer dereference.
> 
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
> ---
>  drivers/dma/pl330.c |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
> index 018a445..5d3bbcd 100644
> --- a/drivers/dma/pl330.c
> +++ b/drivers/dma/pl330.c
> @@ -2930,6 +2930,11 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
>  		num_chan = max_t(int, pi->pcfg.num_peri, pi->pcfg.num_chan);
>  
>  	pdmac->peripherals = kzalloc(num_chan * sizeof(*pch), GFP_KERNEL);
> +	if (!pdmac->peripherals) {
> +		ret = -ENOMEM;
> +		dev_err(&adev->dev, "unable to allocate pdmac->peripherals\n");
> +		goto probe_err5;
> +	}
>  
>  	for (i = 0; i < num_chan; i++) {
>  		pch = &pdmac->peripherals[i];

Thanks applied both to fixes. 
I have cc'ed stable as well
diff mbox

Patch

diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index 018a445..5d3bbcd 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -2930,6 +2930,11 @@  pl330_probe(struct amba_device *adev, const struct amba_id *id)
 		num_chan = max_t(int, pi->pcfg.num_peri, pi->pcfg.num_chan);
 
 	pdmac->peripherals = kzalloc(num_chan * sizeof(*pch), GFP_KERNEL);
+	if (!pdmac->peripherals) {
+		ret = -ENOMEM;
+		dev_err(&adev->dev, "unable to allocate pdmac->peripherals\n");
+		goto probe_err5;
+	}
 
 	for (i = 0; i < num_chan; i++) {
 		pch = &pdmac->peripherals[i];