RE: [PATCH v4] scripts/checkpatch.pl: remove _deferred and _deferred_once false warning

From: Maninder Singh
Date: Tue Mar 01 2022 - 23:34:22 EST


Hi,

> On Mon, 2022-02-28 at 13:07 +0530, Maninder Singh wrote:
> > with commit 98e35f5894cf ("printk: git rid of [sched_delayed] message for
> > printk_deferred") printk_deferred and printk_deferred_once requires
> > LOGLEVEL in argument, but checkpatch.pl was not fixed and still reports
> > it as warning:
> >
> > WARNING: Possible unnecessary KERN_ALERT
> > printk_deferred(KERN_ALERT "checking deferred\n");
>
> I don't care for this patch at all.

But still it needs to be fixed, either with current suggested patch or with something else.

> There are many existing uses of printk_deferred both with and without a
> specific KERN_<LEVEL>.

Yes, Because earlier to this commit 98e35f5894cf, printk_deferred was expected
with KERN_WARNING by default.

- if (in_sched)
- text_len = scnprintf(text, sizeof(textbuf),
- KERN_WARNING "[sched_delayed] ");

But now it is aligned with normal printk level handling, only printing to console from current context
is avoided in case of deferred.
So earlier printk_deferred's should be fixed if it is meant to be printed on console with particular
level.

> printk_deferred currently always emits at LOGLEVEL_SCHED/KERN_DEFAULT.
>
> I think it's be better to modify vprintk_emit when LOGLEVEL_SCHED
> is used and if a KERN_<LEVEL> exists in the format, use it.
> Perhaps instead:
> ---
> kernel/printk/printk.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 1ce242f34d2be..6b5baf14f6d56 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -2247,7 +2247,13 @@ asmlinkage int vprintk_emit(int facility, int level,
> return 0;
>
> if (level == LOGLEVEL_SCHED) {
> - level = LOGLEVEL_DEFAULT;
> + level = printk_get_level(fmt);
> + if (level) {
> + level -= '0';
> + fmt = printk_skip_level(fmt);
> + } else {
> + level = LOGLEVEL_DEFAULT;
> + }
> in_sched = true;
> }

And I think it is already handled for printk (facility = 0).
after setting level to KERN_DEFAULT at first for in_sched case to make it normal
printk case as it is changed from vprintk_store as per the string in printk based on
current default loglevel.

int vprintk_store(int facility, int level,
const struct dev_printk_info *dev_info,
const char *fmt, va_list args)
{
...
/* Extract log level or control flags. */
if (facility == 0)
printk_parse_prefix(&prefix_buf[0], &level, &flags);
..


u16 printk_parse_prefix(const char *text, int *level,
enum printk_info_flags *flags)
{
..
case '0' ... '7':
if (level && *level == LOGLEVEL_DEFAULT)
*level = kern_level - '0';
break;
...
}

So, for printk, printk_deferred, printk_deferred_once, its level is picked if its provided.
thus level in printk_deferred is "not unnecessary".
And checkpatch.pl should not give w WARNING for this.


Thanks,
Maninder Singh