All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: saa7146: Avoid using BUG_ON as an assertion
@ 2019-12-15 19:21 Aditya Pakki
  2019-12-16 10:22 ` Markus Elfring
  0 siblings, 1 reply; 2+ messages in thread
From: Aditya Pakki @ 2019-12-15 19:21 UTC (permalink / raw)
  To: pakki001
  Cc: kjlu, Hans Verkuil, Mauro Carvalho Chehab, linux-media, linux-kernel

In video_begin and video_end, saa7146_format_by_fourcc can return
NULL and is checked via BUG_ON. However, by returning the error
to the callers upstream, we can avoid the crash and handle it via
recovery code.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
 drivers/media/common/saa7146/saa7146_video.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/common/saa7146/saa7146_video.c b/drivers/media/common/saa7146/saa7146_video.c
index d16122039b0c..1b6b5d43ad3e 100644
--- a/drivers/media/common/saa7146/saa7146_video.c
+++ b/drivers/media/common/saa7146/saa7146_video.c
@@ -345,7 +345,8 @@ static int video_begin(struct saa7146_fh *fh)
 
 	fmt = saa7146_format_by_fourcc(dev, vv->video_fmt.pixelformat);
 	/* we need to have a valid format set here */
-	BUG_ON(NULL == fmt);
+	if (NULL == fmt)
+		return -EINVAL;
 
 	if (0 != (fmt->flags & FORMAT_IS_PLANAR)) {
 		resource = RESOURCE_DMA1_HPS|RESOURCE_DMA2_CLP|RESOURCE_DMA3_BRS;
@@ -398,7 +399,8 @@ static int video_end(struct saa7146_fh *fh, struct file *file)
 
 	fmt = saa7146_format_by_fourcc(dev, vv->video_fmt.pixelformat);
 	/* we need to have a valid format set here */
-	BUG_ON(NULL == fmt);
+	if (NULL == fmt)
+		return -EINVAL;
 
 	if (0 != (fmt->flags & FORMAT_IS_PLANAR)) {
 		resource = RESOURCE_DMA1_HPS|RESOURCE_DMA2_CLP|RESOURCE_DMA3_BRS;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] media: saa7146: Avoid using BUG_ON as an assertion
  2019-12-15 19:21 [PATCH] media: saa7146: Avoid using BUG_ON as an assertion Aditya Pakki
@ 2019-12-16 10:22 ` Markus Elfring
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2019-12-16 10:22 UTC (permalink / raw)
  To: Aditya Pakki, linux-media
  Cc: linux-kernel, Hans Verkuil, Kangjie Lu, Mauro Carvalho Chehab

…
> +++ b/drivers/media/common/saa7146/saa7146_video.c
@@ -345,7 +345,8 @@ static int video_begin(struct saa7146_fh *fh)
…
-	BUG_ON(NULL == fmt);
+	if (NULL == fmt)
…

Would you like to express a null pointer check in a succinct way?

+	if (!fmt)


Will the tag “Fixes” become helpful for the change description?

Regards,
Markus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-16 10:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-15 19:21 [PATCH] media: saa7146: Avoid using BUG_ON as an assertion Aditya Pakki
2019-12-16 10:22 ` Markus Elfring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.