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

From: Ben Hutchings
Date: Sun Oct 07 2012 - 19:26:31 EST


3.2-stable review patch. If anyone has any objections, please let me know.

------------------

From: Sachin Kamat <sachin.kamat@xxxxxxxxxx>

commit 61c6e7531d3b66b33187b8cdd700fd8ab93ffd62 upstream.

kzalloc could return NULL. Hence add a check to avoid
NULL pointer dereference.

Signed-off-by: Sachin Kamat <sachin.kamat@xxxxxxxxxx>
Acked-by: Jassi Brar <jassisinghbrar@xxxxxxxxx>
Signed-off-by: Vinod Koul <vinod.koul@xxxxxxxxxxxxxxx>
[bwh: Backported to 3.2: adjust context and error label]
Signed-off-by: Ben Hutchings <ben@xxxxxxxxxxxxxxx>
---
drivers/dma/pl330.c | 5 +++++
1 file changed, 5 insertions(+)

--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -858,6 +858,11 @@ pl330_probe(struct amba_device *adev, co
/* Initialize channel parameters */
num_chan = max(pdat ? pdat->nr_valid_peri : 0, (u8)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_err4;
+ }

for (i = 0; i < num_chan; i++) {
pch = &pdmac->peripherals[i];


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/