OSDN Git Service

media: video-mux: fix null pointer dereferences
authorKangjie Lu <kjlu@umn.edu>
Sat, 9 Mar 2019 07:20:56 +0000 (02:20 -0500)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Fri, 29 Mar 2019 11:42:37 +0000 (07:42 -0400)
devm_kcalloc may fail and return a null pointer. The fix returns
-ENOMEM upon failures to avoid null pointer dereferences.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/platform/video-mux.c

index 0ba3075..d8cd5f5 100644 (file)
@@ -419,9 +419,14 @@ static int video_mux_probe(struct platform_device *pdev)
        vmux->active = -1;
        vmux->pads = devm_kcalloc(dev, num_pads, sizeof(*vmux->pads),
                                  GFP_KERNEL);
+       if (!vmux->pads)
+               return -ENOMEM;
+
        vmux->format_mbus = devm_kcalloc(dev, num_pads,
                                         sizeof(*vmux->format_mbus),
                                         GFP_KERNEL);
+       if (!vmux->format_mbus)
+               return -ENOMEM;
 
        for (i = 0; i < num_pads; i++) {
                vmux->pads[i].flags = (i < num_pads - 1) ? MEDIA_PAD_FL_SINK