Message ID | 20180806155025.8912-1-vasilyev@ispras.ru (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2,1/2] media: davinci: vpif_display: Mix memory leak on probe error path | expand |
Hi, Thanks for the patch. On Mon, Aug 6, 2018 at 4:50 PM Anton Vasilyev <vasilyev@ispras.ru> wrote: > > If vpif_probe() fails on v4l2_device_register() then memory allocated > at initialize_vpif() for global vpif_obj.dev[i] become unreleased. > > The patch adds deallocation of vpif_obj.dev[i] on the probe error path. > > Found by Linux Driver Verification project (linuxtesting.org). > > Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru> > --- > v2: divided the original patch into two and made stylistic fixes based > on the Prabhakar's rewiev. > --- > drivers/media/platform/davinci/vpif_display.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > Acked-by: Lad, Prabhakar <prabhakar.csengg@gmail.com> Cheers, --Prabhakar Lad
diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c index 7be636237acf..d9e578ac79c2 100644 --- a/drivers/media/platform/davinci/vpif_display.c +++ b/drivers/media/platform/davinci/vpif_display.c @@ -1271,7 +1271,7 @@ static __init int vpif_probe(struct platform_device *pdev) err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev); if (err) { v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n"); - return err; + goto vpif_free; } while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) { @@ -1314,7 +1314,9 @@ static __init int vpif_probe(struct platform_device *pdev) if (vpif_obj.sd[i]) vpif_obj.sd[i]->grp_id = 1 << i; } - vpif_probe_complete(); + err = vpif_probe_complete(); + if (err) + goto probe_subdev_out; } else { vpif_obj.notifier.subdevs = vpif_obj.config->asd; vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0]; @@ -1334,6 +1336,9 @@ static __init int vpif_probe(struct platform_device *pdev) kfree(vpif_obj.sd); vpif_unregister: v4l2_device_unregister(&vpif_obj.v4l2_dev); +vpif_free: + for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) + kfree(vpif_obj.dev[i]); return err; }
If vpif_probe() fails on v4l2_device_register() then memory allocated at initialize_vpif() for global vpif_obj.dev[i] become unreleased. The patch adds deallocation of vpif_obj.dev[i] on the probe error path. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru> --- v2: divided the original patch into two and made stylistic fixes based on the Prabhakar's rewiev. --- drivers/media/platform/davinci/vpif_display.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)