public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] locking/lockdep: fix format-truncation compiler-warning
@ 2023-10-11 19:14 Lucy Mielke
  2023-10-11 22:11 ` Ingo Molnar
  0 siblings, 1 reply; 3+ messages in thread
From: Lucy Mielke @ 2023-10-11 19:14 UTC (permalink / raw)
  To: peterz, mingo, will, longman, boqun.feng; +Cc: linux-kernel

Compiler: gcc x86_64 v13.2.1
Config: allyesconfig, "treat warnings as errors" unset

This fixes a warning emitted by gcc, stating the output may be
truncated. The fix included increasing the buffer size to the one
denoted by gcc.

Signed-off-by: Lucy Mielke <lucymielke@icloud.com>
---
 kernel/locking/lockdep_proc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index 15fdc7fa5c68..e2bfb1db589d 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -440,7 +440,7 @@ static void snprint_time(char *buf, size_t bufsiz, s64 nr)
 
 static void seq_time(struct seq_file *m, s64 time)
 {
-	char num[15];
+	char num[22];
 
 	snprint_time(num, sizeof(num), time);
 	seq_printf(m, " %14s", num);
-- 
2.41.0


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

* Re: [PATCH] locking/lockdep: fix format-truncation compiler-warning
  2023-10-11 19:14 [PATCH] locking/lockdep: fix format-truncation compiler-warning Lucy Mielke
@ 2023-10-11 22:11 ` Ingo Molnar
  2023-10-12 10:16   ` Lucy Mielke
  0 siblings, 1 reply; 3+ messages in thread
From: Ingo Molnar @ 2023-10-11 22:11 UTC (permalink / raw)
  To: Lucy Mielke; +Cc: peterz, mingo, will, longman, boqun.feng, linux-kernel


* Lucy Mielke <lucymielke@icloud.com> wrote:

> Compiler: gcc x86_64 v13.2.1
> Config: allyesconfig, "treat warnings as errors" unset
> 
> This fixes a warning emitted by gcc, stating the output may be
> truncated. The fix included increasing the buffer size to the one
> denoted by gcc.

Mind including the output by GCC in the changelog?

>  static void seq_time(struct seq_file *m, s64 time)
>  {
> -	char num[15];
> +	char num[22];
>  
>  	snprint_time(num, sizeof(num), time);
>  	seq_printf(m, " %14s", num);

Fun.

So this:

static void snprint_time(char *buf, size_t bufsiz, s64 nr)
{
        s64 div;
        s32 rem;

        nr += 5; /* for display rounding */
        div = div_s64_rem(nr, 1000, &rem);
        snprintf(buf, bufsiz, "%lld.%02d", (long long)div, (int)rem/10);
}

... actually needs 21+1 bytes?

Which I suppose is true - longest s64 is "-9223372036854775808"-ish, which 
converted to the fixed-point float format above is "-9223372036854775.80": 
21 bytes, plus termination is another byte: 22.

Maybe put this into the changelog too, instead of relying on magic GCC 
calculations only. :-)

Thanks,

	Ingo

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

* Re: [PATCH] locking/lockdep: fix format-truncation compiler-warning
  2023-10-11 22:11 ` Ingo Molnar
@ 2023-10-12 10:16   ` Lucy Mielke
  0 siblings, 0 replies; 3+ messages in thread
From: Lucy Mielke @ 2023-10-12 10:16 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: peterz, mingo, will, longman, boqun.feng, linux-kernel

Am Thu, Oct 12, 2023 at 12:11:13AM +0200 schrieb Ingo Molnar:
> 
> Mind including the output by GCC in the changelog?
> 

Sure, let me resend the patch then :)

> ... actually needs 21+1 bytes?
> 
> Which I suppose is true - longest s64 is "-9223372036854775808"-ish, which 
> converted to the fixed-point float format above is "-9223372036854775.80": 
> 21 bytes, plus termination is another byte: 22.
> 
> Maybe put this into the changelog too, instead of relying on magic GCC 
> calculations only. :-)

I can include it as well, of course!

Mit freundlichen Grüßen / Best regards,
	Lucy

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-11 19:14 [PATCH] locking/lockdep: fix format-truncation compiler-warning Lucy Mielke
2023-10-11 22:11 ` Ingo Molnar
2023-10-12 10:16   ` Lucy Mielke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox