* [PATCH] media: saa6588: Fix unsafe debug printk macro
@ 2025-09-23 17:59 Shrikant Raskar
2025-10-13 10:35 ` Hans Verkuil
0 siblings, 1 reply; 3+ messages in thread
From: Shrikant Raskar @ 2025-09-23 17:59 UTC (permalink / raw)
To: hverkuil, mchehab; +Cc: linux-media, linux-kernel, Shrikant Raskar
The existing dprintk macro used an unwrapped `if` statement, which can lead
to logic errors when used in if/else constructs. This patch wraps the macro
in a do { } while (0) block to ensure safe usage.
This change resolves the following checkpatch error:
ERROR: Macros starting with if should be enclosed by a do - while loop to
avoid possible if/else logic defects
Signed-off-by: Shrikant Raskar <raskar.shree97@gmail.com>
---
drivers/media/i2c/saa6588.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/i2c/saa6588.c b/drivers/media/i2c/saa6588.c
index fb09e4560d8a..71d34d229564 100644
--- a/drivers/media/i2c/saa6588.c
+++ b/drivers/media/i2c/saa6588.c
@@ -50,7 +50,7 @@ MODULE_LICENSE("GPL");
#define UNSET (-1U)
#define PREFIX "saa6588: "
-#define dprintk if (debug) printk
+#define dprintk(fmt, args...) do { if (debug) printk(fmt, ##args); } while (0)
struct saa6588 {
struct v4l2_subdev sd;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] media: saa6588: Fix unsafe debug printk macro
2025-09-23 17:59 [PATCH] media: saa6588: Fix unsafe debug printk macro Shrikant Raskar
@ 2025-10-13 10:35 ` Hans Verkuil
2025-10-24 11:45 ` Shrikant
0 siblings, 1 reply; 3+ messages in thread
From: Hans Verkuil @ 2025-10-13 10:35 UTC (permalink / raw)
To: Shrikant Raskar, hverkuil, mchehab; +Cc: linux-media, linux-kernel
On 23/09/2025 19:59, Shrikant Raskar wrote:
> The existing dprintk macro used an unwrapped `if` statement, which can lead
> to logic errors when used in if/else constructs. This patch wraps the macro
> in a do { } while (0) block to ensure safe usage.
>
> This change resolves the following checkpatch error:
> ERROR: Macros starting with if should be enclosed by a do - while loop to
> avoid possible if/else logic defects
>
> Signed-off-by: Shrikant Raskar <raskar.shree97@gmail.com>
> ---
> drivers/media/i2c/saa6588.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/i2c/saa6588.c b/drivers/media/i2c/saa6588.c
> index fb09e4560d8a..71d34d229564 100644
> --- a/drivers/media/i2c/saa6588.c
> +++ b/drivers/media/i2c/saa6588.c
> @@ -50,7 +50,7 @@ MODULE_LICENSE("GPL");
>
> #define UNSET (-1U)
> #define PREFIX "saa6588: "
> -#define dprintk if (debug) printk
> +#define dprintk(fmt, args...) do { if (debug) printk(fmt, ##args); } while (0)
>
> struct saa6588 {
> struct v4l2_subdev sd;
I think we can do better than this.
Looking at how dprintk is used in this driver, I see that in almost all cases
it is preceded by a 'if (debug > X)' condition. Except for one occurrence in
saa6588_configure().
So I would propose to just drop dprintk, and instead change dprintk to
pr_info and pr_cont. And add a 'if (debug)' in saa6588_configure().
Actually, v4l2_info(&s->sd, ...) would be even better, then the PREFIX can
be dropped as well.
Regards,
Hans
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] media: saa6588: Fix unsafe debug printk macro
2025-10-13 10:35 ` Hans Verkuil
@ 2025-10-24 11:45 ` Shrikant
0 siblings, 0 replies; 3+ messages in thread
From: Shrikant @ 2025-10-24 11:45 UTC (permalink / raw)
To: Hans Verkuil; +Cc: hverkuil, mchehab, linux-media, linux-kernel
On Mon, Oct 13, 2025 at 4:05 PM Hans Verkuil <hverkuil+cisco@kernel.org> wrote:
>
> On 23/09/2025 19:59, Shrikant Raskar wrote:
> > The existing dprintk macro used an unwrapped `if` statement, which can lead
> > to logic errors when used in if/else constructs. This patch wraps the macro
> > in a do { } while (0) block to ensure safe usage.
> >
> > This change resolves the following checkpatch error:
> > ERROR: Macros starting with if should be enclosed by a do - while loop to
> > avoid possible if/else logic defects
> >
> > Signed-off-by: Shrikant Raskar <raskar.shree97@gmail.com>
> > ---
> > drivers/media/i2c/saa6588.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/media/i2c/saa6588.c b/drivers/media/i2c/saa6588.c
> > index fb09e4560d8a..71d34d229564 100644
> > --- a/drivers/media/i2c/saa6588.c
> > +++ b/drivers/media/i2c/saa6588.c
> > @@ -50,7 +50,7 @@ MODULE_LICENSE("GPL");
> >
> > #define UNSET (-1U)
> > #define PREFIX "saa6588: "
> > -#define dprintk if (debug) printk
> > +#define dprintk(fmt, args...) do { if (debug) printk(fmt, ##args); } while (0)
> >
> > struct saa6588 {
> > struct v4l2_subdev sd;
>
> I think we can do better than this.
>
> Looking at how dprintk is used in this driver, I see that in almost all cases
> it is preceded by a 'if (debug > X)' condition. Except for one occurrence in
> saa6588_configure().
>
> So I would propose to just drop dprintk, and instead change dprintk to
> pr_info and pr_cont. And add a 'if (debug)' in saa6588_configure().
>
> Actually, v4l2_info(&s->sd, ...) would be even better, then the PREFIX can
> be dropped as well.
Thank you so much for reviewing my patch and sharing your feedback.
I will drop the dprintk macro and will use the v4l2_info() helper as
you suggested. I will share the v2 patch shortly.
Regards,
Shrikant
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-24 11:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-23 17:59 [PATCH] media: saa6588: Fix unsafe debug printk macro Shrikant Raskar
2025-10-13 10:35 ` Hans Verkuil
2025-10-24 11:45 ` Shrikant
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox