media: saa6588: Fix unsafe debug printk macro
Subsystems (2)
PATCH 1/1 media: saa6588: Fix unsafe debug printk macro
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
--- drivers/media/i2c/saa6588.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/saa6588.c +1 -1
@@ -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;
Signature · 1 line
2.43.0
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hello CI team,
In the shared patch, printk gets KERN_<LEVEL> as an argument to macro.
Quoted 34 lines · Patchwork Integration
Dear Shrikant Raskar:
Thanks for your patches! Unfortunately the Media CI robot detected some issues:
# Test checkpatch:./0001-media-saa6588-Fix-unsafe-debug-printk-macro.patch checkpatch
WARNING:printk()should include KERN_<LEVEL> facility level
#29: FILE:drivers/media/i2c/saa6588.c:53:
+#definedprintk(fmt, args...)do { if (debug)printk(fmt, ##args); } while (0)total: 0 errors, 1 warnings, 0 checks, 8 lines checked
Please fix your series, and upload a new version. If you have a patchwork account, do not forget to mark the current series as Superseded.
For more details, check the full report at:
https://linux-media.pages.freedesktop.org/-/users/patchwork/-/jobs/84951660/artifacts/report.htm .Best regards, and Happy Hacking!
Media CI robot on behalf of the linux-media community.---
Check the latest rules for contributing your patches at:
https://docs.kernel.org/driver-api/media/maintainer-entry-profile.htmlIf you believe that the CI is wrong, kindly open an issue at
https://gitlab.freedesktop.org/linux-media/media-ci/-/issues or reply-all to this message.
Quoted 18 lines · Shrikant Raskar
The existing dprintk macro used an unwrapped
ifstatement, 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 defectsSigned-off-by Shrikant Raskar <[email protected]>--- drivers/media/i2c/saa6588.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/saa6588.c +0
-0
drivers/media/i2c/saa6588.c MODULE_LICENSE("GPL"); · line 56
Quoted 8 lines
drivers/media/i2c/saa6588.c +1
-1@@ -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
Quoted 35 lines · Hans Verkuil
Quoted 18 lines · Shrikant Raskar
The existing dprintk macro used an unwrapped
ifstatement, 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 defectsSigned-off-by Shrikant Raskar <[email protected]>--- drivers/media/i2c/saa6588.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/saa6588.c +0
-0drivers/media/i2c/saa6588.c MODULE_LICENSE("GPL"); · line 56
Quoted 8 lines
drivers/media/i2c/saa6588.c +1
-1@@ -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().
Quoted 5 lines
So I would propose to just drop dprintk, and instead change dprintk to
pr_infoandpr_cont. And add a 'if (debug)' insaa6588_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