Skip to contentSkip to conversation

media: video-mux: fix null pointer dereferences

PATCH In review Kangjie Lu 2 participants 2 messages Mar 9, 2019 – Mar 11, 2019

Subsystems (2)
lore
Share & tools
lore

Kangjie Lu

author
#0 lore raw

PATCH 1/1 media: video-mux: fix null pointer dereferences

devm_kcalloc may fail and return a null pointer. The fix returns -ENOMEM upon failures to avoid null pointer dereferences.

---
 drivers/media/platform/video-mux.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/media/platform/video-mux.c +5 -0
index c33900e3c23e..4135165cdabe 100644
@@ -399,9 +399,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
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Kangjie Lu

devm_kcalloc may fail and return a null pointer. The fix returns -ENOMEM upon failures to avoid null pointer dereferences.

---
 drivers/media/platform/video-mux.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/media/platform/video-mux.c +1 -0
index c33900e3c23e..4135165cdabe 100644
@@ -399,9 +399,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)

drivers/media/platform/video-mux.c static int video_mux_probe(struct platform_device *pdev) · line 412

Quoted 10 lines
drivers/media/platform/video-mux.c +4 -0
+		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

Thank you,

regards
Philipp