lkml.org 
[lkml]   [2018]   [Sep]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 2/2] printk: Add KBUILD_MODNAME and correct bare use of unsigned
On Wed 2018-09-19 11:06:21, Sergey Senozhatsky wrote:
> On (09/19/18 01:17), zhe.he@windriver.com wrote:
> > Add KBUILD_MODNAME to make prints more clear.
>
> No strong opinion. I'm OK with this change.
>
> > And use 'unsigned int' intead of 'unsigned' according to
> > checkpatch.pl's suggestion.
>
> I don't think that "unsigned int" is the right thing to use there.
>
> > if (console_seq < log_first_seq) {
> > len = sprintf(text, "** %u printk messages dropped **\n",
> > - (unsigned)(log_first_seq - console_seq));
> > + (unsigned int)(log_first_seq - console_seq));
>
> Both log_first_seq and console_seq are u64.
>
> log_first_seq - console_seq
>
> thus, *in theory*, can be larger than "unsigned int". So I'd just avoid cast
> and use an appropriate for u64 %llu sprintf() specifier. Something like below,
> perhaps:
>
> ---
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index f73ea9dd6f46..4b8c5832bf14 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -2408,8 +2408,9 @@ void console_unlock(void)
> printk_safe_enter_irqsave(flags);
> raw_spin_lock(&logbuf_lock);
> if (console_seq < log_first_seq) {
> - len = sprintf(text, "** %u printk messages dropped **\n",
> - (unsigned int)(log_first_seq - console_seq));
> + len = sprintf(text,
> + "** %llu printk messages dropped **\n",
> + log_first_seq - console_seq);

This looks like a better solution.

Also please, define pr_fmt and fix the casting in separate patches.

Best Regards,
Petr

\
 
 \ /
  Last update: 2018-09-19 13:20    [W:0.053 / U:0.576 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site