lkml.org 
[lkml]   [2018]   [Sep]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH v2 2/2] printk: Add KBUILD_MODNAME and correct bare use of unsigned
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);

/* messages are gone, move to first one */
console_seq = log_first_seq;
---
Steven, Petr, any objections?

-ss

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