public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil+cisco@kernel.org>
To: Shrikant Raskar <raskar.shree97@gmail.com>,
	hverkuil@kernel.org, mchehab@kernel.org
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] media: saa6588: Fix unsafe debug printk macro
Date: Mon, 13 Oct 2025 12:35:38 +0200	[thread overview]
Message-ID: <958a157f-e01d-499c-9f3e-d19e33b1de74@kernel.org> (raw)
In-Reply-To: <20250923175927.4380-1-raskar.shree97@gmail.com>

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

  reply	other threads:[~2025-10-13 10:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-23 17:59 [PATCH] media: saa6588: Fix unsafe debug printk macro Shrikant Raskar
2025-10-13 10:35 ` Hans Verkuil [this message]
2025-10-24 11:45   ` Shrikant

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=958a157f-e01d-499c-9f3e-d19e33b1de74@kernel.org \
    --to=hverkuil+cisco@kernel.org \
    --cc=hverkuil@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=raskar.shree97@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox