Skip to contentSkip to conversation

media: allegro: add the missed check for v4l2_m2m_ctx_init

PATCH Superseded Chuhong Yuan 3 participants 3 messages Dec 9, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: allegro: add the missed check for v4l2_m2m_ctx_init

allegro_open() misses a check for v4l2_m2m_ctx_init(). Add a check and error handling code to fix it.

Fixes f20387dfd065 ("media: allegro: add Allegro DVT video IP core driver")
---
 drivers/staging/media/allegro-dvt/allegro-core.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/staging/media/allegro-dvt/allegro-core.c +7 -0
index 6f0cd0784786..5f1d454b41bb 100644
@@ -2341,6 +2341,13 @@ static int allegro_open(struct file *file)
 	channel->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, channel,
 						allegro_queue_init);
 
+	if (IS_ERR(channel->fh.m2m_ctx)) {
+		v4l2_fh_del(&channel->fh);
+		v4l2_fh_exit(&channel->fh);
+		kfree(channel);
+		return PTR_ERR(channel->fh.m2m_ctx);
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.24.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Chuhong Yuan

allegro_open() misses a check for v4l2_m2m_ctx_init(). Add a check and error handling code to fix it.

Fixes f20387dfd065 ("media: allegro: add Allegro DVT video IP core driver")
Quoted 22 lines
---
 drivers/staging/media/allegro-dvt/allegro-core.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/staging/media/allegro-dvt/allegro-core.c +7 -0
index 6f0cd0784786..5f1d454b41bb 100644
@@ -2341,6 +2341,13 @@ static int allegro_open(struct file *file)
 	channel->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, channel,
 						allegro_queue_init);
 
+	if (IS_ERR(channel->fh.m2m_ctx)) {
+		v4l2_fh_del(&channel->fh);
+		v4l2_fh_exit(&channel->fh);
+		kfree(channel);
+		return PTR_ERR(channel->fh.m2m_ctx);
+	}
+
 	return 0;
 }
 
#2 lore raw
In reply to Chuhong Yuan

drivers/staging/media/allegro-dvt/allegro-core.c static int allegro_open(struct file *file) · line 2347

Quoted 12 lines · Chuhong Yuan
drivers/staging/media/allegro-dvt/allegro-core.c +4 -0
index 6f0cd0784786..5f1d454b41bb 100644
@@ -2341,6 +2341,13 @@ static int allegro_open(struct file *file)
 	channel->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, channel,
 						allegro_queue_init);
 
+	if (IS_ERR(channel->fh.m2m_ctx)) {
+		v4l2_fh_del(&channel->fh);
+		v4l2_fh_exit(&channel->fh);
+		kfree(channel);
                      ^^^^^^^

Free

drivers/staging/media/allegro-dvt/allegro-core.c static int allegro_open(struct file *file) · line 2348

Quoted 1 line
drivers/staging/media/allegro-dvt/allegro-core.c +1 -0
+		return PTR_ERR(channel->fh.m2m_ctx);
                               ^^^^^^^^^^^^^^^^^^^

Dereferencing freed memory.

regards,
dan carpenter

Quoted 2 lines
drivers/staging/media/allegro-dvt/allegro-core.c +2 -0
+	}
+