spi: pl022: Add missing error check for devm_kzalloc
authorKiran Padwal <kiran.padwal@smartplayin.com>
Thu, 18 Sep 2014 07:27:47 +0000 (12:57 +0530)
committerMark Brown <broonie@kernel.org>
Thu, 18 Sep 2014 18:14:16 +0000 (11:14 -0700)
Currently this driver is missing a check on the return value of devm_kzalloc,
which would cause a NULL pointer dereference in a OOM situation.

This patch adds a missing check.

Signed-off-by: Kiran Padwal <kiran.padwal@smartplayin.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-pl022.c

index 1189cfd96477c7cb53236d110b4a077b3aeb270a..7f13f3f7198bb21b9f790d163fe4830dda9aee6f 100644 (file)
@@ -2100,6 +2100,10 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
        pl022->vendor = id->data;
        pl022->chipselects = devm_kzalloc(dev, num_cs * sizeof(int),
                                          GFP_KERNEL);
+       if (!pl022->chipselects) {
+               status = -ENOMEM;
+               goto err_no_mem;
+       }
 
        /*
         * Bus Number Which has been Assigned to this SSP controller
@@ -2241,6 +2245,7 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
        amba_release_regions(adev);
  err_no_ioregion:
  err_no_gpio:
+ err_no_mem:
        spi_master_put(master);
        return status;
 }