usb: chipidea: usbmisc_imx: fix a possible NULL dereference
authorLABBE Corentin <clabbe.montjoie@gmail.com>
Thu, 12 Nov 2015 07:43:33 +0000 (08:43 +0100)
committerPeter Chen <peter.chen@freescale.com>
Wed, 18 Nov 2015 07:27:12 +0000 (15:27 +0800)
of_match_device could return NULL, and so cause a NULL pointer
dereference later. Renaming tmp_dev to of_id (like all others do) in the
process.

Reported-by: coverity (CID 1324135)
Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
Signed-off-by: Peter Chen <peter.chen@freescale.com>
drivers/usb/chipidea/usbmisc_imx.c

index fcea4eb36eeedbceac777ecd8d676e5ede74cba6..ab8b027e8cc870615d399abb631849875db72427 100644 (file)
@@ -500,7 +500,11 @@ static int usbmisc_imx_probe(struct platform_device *pdev)
 {
        struct resource *res;
        struct imx_usbmisc *data;
-       struct of_device_id *tmp_dev;
+       const struct of_device_id *of_id;
+
+       of_id = of_match_device(usbmisc_imx_dt_ids, &pdev->dev);
+       if (!of_id)
+               return -ENODEV;
 
        data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
        if (!data)
@@ -513,9 +517,7 @@ static int usbmisc_imx_probe(struct platform_device *pdev)
        if (IS_ERR(data->base))
                return PTR_ERR(data->base);
 
-       tmp_dev = (struct of_device_id *)
-               of_match_device(usbmisc_imx_dt_ids, &pdev->dev);
-       data->ops = (const struct usbmisc_ops *)tmp_dev->data;
+       data->ops = (const struct usbmisc_ops *)of_id->data;
        platform_set_drvdata(pdev, data);
 
        return 0;