asoc: tegra: fix NULL pointer dereference
Deepak Nibade [Tue, 30 Jul 2013 08:42:20 +0000 (13:42 +0530)]
- fix Coverity issues
- fix dereference of null pointer
  Coverity id : 23721
  Coverity id : 23735

Bug 1329327

Change-Id: I877959ab5446e09648a52fd18fd4a219c3f01e7e
Signed-off-by: Deepak Nibade <dnibade@nvidia.com>
Reviewed-on: http://git-master/r/255453
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Sri Krishna Chowdary <schowdary@nvidia.com>
Reviewed-by: Sumit Bhattacharya <sumitb@nvidia.com>

sound/soc/tegra/tegra_dmic.c
sound/soc/tegra/tegra_wm8903.c

index 44324a2..abeaee5 100644 (file)
@@ -654,7 +654,10 @@ static int __devexit asoc_dmic_remove(struct platform_device *pdev)
        snd_soc_unregister_dai(&pdev->dev);
        iounmap(dmic->io_base);
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       release_mem_region(res->start, resource_size(res));
+       if (res)
+               release_mem_region(res->start, resource_size(res));
+       else
+               dev_err(&pdev->dev, "failed to get memory resource\n");
 
        if (dmic->parent)
                clk_put(dmic->parent);
index 5b5aad6..113d8fd 100644 (file)
@@ -821,6 +821,15 @@ static int tegra_wm8903_driver_probe(struct platform_device *pdev)
        if (pdev->dev.platform_data) {
                memcpy(pdata, card->dev->platform_data, sizeof(*pdata));
        } else if (np) {
+               pdata = devm_kzalloc(&pdev->dev,
+                       sizeof(struct tegra_asoc_platform_data), GFP_KERNEL);
+               if (!pdata) {
+                       dev_err(&pdev->dev,
+                               "no memory for tegra_asoc_platform_data\n");
+                       ret = -ENOMEM;
+                       goto err;
+               }
+
                pdata->gpio_spkr_en = of_get_named_gpio(np,
                                                "nvidia,spkr-en-gpios", 0);
                if (pdata->gpio_spkr_en == -EPROBE_DEFER)