genirq: Bump the size of the local variable for sprintf()
PATCH 1/1 genirq: Bump the size of the local variable for sprintf()
GCC is not happy about sprintf() call on a buffer that might be too small for the given formatting string.
kernel/irq/debugfs.c:233:26: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
Fix this by bumping the size of the local variable for sprintf().
--- kernel/irq/debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/irq/debugfs.c +1 -1
@@ -225,7 +225,7 @@ void irq_debugfs_copy_devname(int irq, struct device *dev)void irq_add_debugfs_entry (unsigned int irq,struct irq_desc *desc) { -char name [10 ]; +char name [12 ];if (!irq_dir || !desc || desc->debugfs_file)return ;
Signature · 1 line
2.47.2
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: a4a39c81e1043b153bde3ef5cb3cf94222ffd918 Gitweb: https://git.kernel.org/tip/a4a39c81e1043b153bde3ef5cb3cf94222ffd918 Author: Andy Shevchenko <[email protected]> AuthorDate: Thu, 15 May 2025 11:55:16 +03:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 15 May 2025 16:28:09 +02:00
genirq: Bump the size of the local variable for sprintf()
GCC is not happy about a sprintf() call on a buffer that might be too small for the given formatting string.
kernel/irq/debugfs.c:233:26: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
Fix this by bumping the size of the local variable for sprintf().
--- kernel/irq/debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/irq/debugfs.c +1 -1
@@ -225,7 +225,7 @@ void irq_debugfs_copy_devname(int irq, struct device *dev)void irq_add_debugfs_entry (unsigned int irq,struct irq_desc *desc) { -char name [10 ]; +char name [12 ];if (!irq_dir || !desc || desc->debugfs_file)return ;
Quoted 19 lines · Andy Shevchenko
GCC is not happy about
sprintf()call on a buffer that might be too small for the given formatting string.
kernel/irq/debugfs.c:233:26: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]Fix this by bumping the size of the local variable for
sprintf().Reported-by kernel test robot <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- kernel/irq/debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/irq/debugfs.c +0
-0
kernel/irq/debugfs.c void irq_debugfs_copy_devname(int irq, struct device *dev) · line 228
Quoted 5 lines
kernel/irq/debugfs.c +1
-1@@ -225,7 +225,7 @@ void irq_debugfs_copy_devname(int irq, struct device *dev)void irq_add_debugfs_entry (unsigned int irq,struct irq_desc *desc) { -char name [10 ]; +char name [12 ];
The max irq is ~ 512000, if I am counting correctly, so 7 B should be actually enough for everybody ;).
But well, can we silence the warning in a better way? I doubt that...
Quoted 3 lines
kernel/irq/debugfs.c +0
-0if (!irq_dir || !desc || desc->debugfs_file)return ;
Signature · 2 lines
js suse labs
Quoted 1 line · Jiri Slaby
On 15. 05. 25, 10:55, Andy Shevchenko wrote:
...
Quoted 5 lines
kernel/irq/debugfs.c void irq_debugfs_copy_devname(int irq, struct device *dev) · line 228
Quoted 2 lines
kernel/irq/debugfs.c +1
-1-char name [10 ]; +char name [12 ];The max irq is ~ 512000, if I am counting correctly, so 7 B should be actually enough for everybody ;).
GCC can't proved it. And FWIW, on current Debian unstable (GCC 14?) I can't reproduce this. In any case this doesn't increase stack usage AFAICT, the array already have reserved 12 or 16 bytes.
Quoted 1 line
But well, can we silence the warning in a better way? I doubt that...
With the above said, I think it's pretty much close to the best way. But if you find anything better, I also would like to learn.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 1 line · Jiri Slaby
On 15. 05. 25, 10:55, Andy Shevchenko wrote:
...
Quoted 5 lines
kernel/irq/debugfs.c void irq_debugfs_copy_devname(int irq, struct device *dev) · line 228
Quoted 2 lines
kernel/irq/debugfs.c +1
-1-char name [10 ]; +char name [12 ];The max irq is ~ 512000, if I am counting correctly, so 7 B should be actually enough for everybody ;).
Quoted 3 lines
GCC can't proved it. And FWIW, on current Debian unstable (GCC 14?) I can't reproduce this. In any case this doesn't increase stack usage AFAICT, the array already have reserved 12 or 16 bytes.
Yes, sure, I am not disputing the fix.
Quoted 4 lines
Quoted 1 line
But well, can we silence the warning in a better way? I doubt that...
With the above said, I think it's pretty much close to the best way. But if you find anything better, I also would like to learn.
Perhaps next in row would be using snprintf(), but dunno if it's better at all.
Signature · 2 lines
js suse labs
Quoted 3 lines · Jiri Slaby
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Jiri Slaby
On 15. 05. 25, 10:55, Andy Shevchenko wrote:
...
Quoted 12 lines
Quoted 9 lines
Quoted 5 lines
kernel/irq/debugfs.c void irq_debugfs_copy_devname(int irq, struct device *dev) · line 228
Quoted 2 lines
kernel/irq/debugfs.c +1
-1-char name [10 ]; +char name [12 ];The max irq is ~ 512000, if I am counting correctly, so 7 B should be actually enough for everybody ;).
GCC can't proved it. And FWIW, on current Debian unstable (GCC 14?) I can't reproduce this. In any case this doesn't increase stack usage AFAICT, the array already have reserved 12 or 16 bytes.
Yes, sure, I am not disputing the fix.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
But well, can we silence the warning in a better way? I doubt that...
With the above said, I think it's pretty much close to the best way. But if you find anything better, I also would like to learn.
Perhaps next in row would be using
snprintf(), but dunno if it's better at all.
Try it. I believe you will get the same result. The problem is not in 'n' or 'n'-less variant, the problem is that GCC can't prove the limits of the input value.
Signature · 2 lines
With Best Regards, Andy Shevchenko