LinuxTV Patchwork media: video-mux: fix null pointer dereferences

login
register
mail settings
Submitter Kangjie Lu
Date March 9, 2019, 7:20 a.m.
Message ID <20190309072056.4618-1-kjlu@umn.edu>
Download mbox | patch
Permalink /patch/54982/
State New
Delegated to: Hans Verkuil
Headers show

Comments

Kangjie Lu - March 9, 2019, 7:20 a.m.
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>
---
 drivers/media/platform/video-mux.c | 5 +++++
 1 file changed, 5 insertions(+)
Philipp Zabel - March 11, 2019, 9:18 a.m.
On Sat, 2019-03-09 at 01:20 -0600, Kangjie Lu wrote:
> 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>
> ---
>  drivers/media/platform/video-mux.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/media/platform/video-mux.c b/drivers/media/platform/video-mux.c
> index c33900e3c23e..4135165cdabe 100644
> --- a/drivers/media/platform/video-mux.c
> +++ b/drivers/media/platform/video-mux.c
> @@ -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

Thank you,
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

Patch

diff --git a/drivers/media/platform/video-mux.c b/drivers/media/platform/video-mux.c
index c33900e3c23e..4135165cdabe 100644
--- a/drivers/media/platform/video-mux.c
+++ b/drivers/media/platform/video-mux.c
@@ -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

Privacy Policy