* lockdep tracing and using of printk return value ?
@ 2020-05-19 12:41 Joe Perches
2020-05-19 14:45 ` Peter Zijlstra
0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2020-05-19 12:41 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: Dmitry Vyukov, LKML, Andrew Morton, Will Deacon
Except for some ancient code in drivers/scsi, this code
may be the only kernel use of the printk return value.
Code that uses the printk return value in
kernel/locking/lockdep.c is odd because the printk
return length includes both the length of a KERN_<LEVEL>
prefix and the newline. depth also seems double counted.
Perhaps there's a better way to calculate this?
Maybe:
---
kernel/locking/lockdep.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 2fadc2635946..265227edc550 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -1960,11 +1960,9 @@ static void print_lock_class_header(struct lock_class *class, int depth)
for (bit = 0; bit < LOCK_USAGE_STATES; bit++) {
if (class->usage_mask & (1 << bit)) {
- int len = depth;
-
- len += printk("%*s %s", depth, "", usage_str[bit]);
- len += printk(KERN_CONT " at:\n");
- print_lock_trace(class->usage_traces[bit], len);
+ printk("%*s %s at:\n", depth, "", usage_str[bit]);
+ print_lock_trace(class->usage_traces[bit],
+ depth + 3 + strlen(usage_str[bit]);
}
}
printk("%*s }\n", depth, "");
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: lockdep tracing and using of printk return value ?
2020-05-19 12:41 lockdep tracing and using of printk return value ? Joe Perches
@ 2020-05-19 14:45 ` Peter Zijlstra
2020-05-19 17:21 ` Joe Perches
0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2020-05-19 14:45 UTC (permalink / raw)
To: Joe Perches; +Cc: Dmitry Vyukov, LKML, Andrew Morton, Will Deacon
On Tue, May 19, 2020 at 05:41:47AM -0700, Joe Perches wrote:
> Except for some ancient code in drivers/scsi, this code
> may be the only kernel use of the printk return value.
Is using the printk() return value a problem?
> Code that uses the printk return value in
> kernel/locking/lockdep.c is odd because the printk
> return length includes both the length of a KERN_<LEVEL>
> prefix and the newline. depth also seems double counted.
Yeah, it seems dodgy. OTOH printk() really ought to discard the
KERN_<level> crud from the return size.
> Perhaps there's a better way to calculate this?
>
> Maybe:
> ---
> kernel/locking/lockdep.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
> index 2fadc2635946..265227edc550 100644
> --- a/kernel/locking/lockdep.c
> +++ b/kernel/locking/lockdep.c
> @@ -1960,11 +1960,9 @@ static void print_lock_class_header(struct lock_class *class, int depth)
>
> for (bit = 0; bit < LOCK_USAGE_STATES; bit++) {
> if (class->usage_mask & (1 << bit)) {
> - int len = depth;
> -
> - len += printk("%*s %s", depth, "", usage_str[bit]);
> - len += printk(KERN_CONT " at:\n");
> - print_lock_trace(class->usage_traces[bit], len);
> + printk("%*s %s at:\n", depth, "", usage_str[bit]);
> + print_lock_trace(class->usage_traces[bit],
> + depth + 3 + strlen(usage_str[bit]);
> }
> }
> printk("%*s }\n", depth, "");
Doesn't seem crazy...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: lockdep tracing and using of printk return value ?
2020-05-19 14:45 ` Peter Zijlstra
@ 2020-05-19 17:21 ` Joe Perches
0 siblings, 0 replies; 3+ messages in thread
From: Joe Perches @ 2020-05-19 17:21 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: Dmitry Vyukov, LKML, Andrew Morton, Will Deacon
On Tue, 2020-05-19 at 16:45 +0200, Peter Zijlstra wrote:
> On Tue, May 19, 2020 at 05:41:47AM -0700, Joe Perches wrote:
> > Except for some ancient code in drivers/scsi, this code
> > may be the only kernel use of the printk return value.
>
> Is using the printk() return value a problem?
Maybe. The printk code isn't obviously correct.
https://lore.kernel.org/lkml/20200518204415.d1a3adaba597ce5b232b4b2a@linux-foundation.org/
> > Code that uses the printk return value in
> > kernel/locking/lockdep.c is odd because the printk
> > return length includes both the length of a KERN_<LEVEL>
> > prefix and the newline. depth also seems double counted.
>
> Yeah, it seems dodgy. OTOH printk() really ought to discard the
> KERN_<level> crud from the return size.
Or change it to the actual output of '<' level '>'
instead of the internal KERN_SOH level.
> > Perhaps there's a better way to calculate this?
> >
> > Maybe:
> > ---
> > kernel/locking/lockdep.c | 8 +++-----
> > 1 file changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
> > index 2fadc2635946..265227edc550 100644
> > --- a/kernel/locking/lockdep.c
> > +++ b/kernel/locking/lockdep.c
> > @@ -1960,11 +1960,9 @@ static void print_lock_class_header(struct lock_class *class, int depth)
> >
> > for (bit = 0; bit < LOCK_USAGE_STATES; bit++) {
> > if (class->usage_mask & (1 << bit)) {
> > - int len = depth;
> > -
> > - len += printk("%*s %s", depth, "", usage_str[bit]);
> > - len += printk(KERN_CONT " at:\n");
> > - print_lock_trace(class->usage_traces[bit], len);
> > + printk("%*s %s at:\n", depth, "", usage_str[bit]);
> > + print_lock_trace(class->usage_traces[bit],
> > + depth + 3 + strlen(usage_str[bit]);
> > }
> > }
> > printk("%*s }\n", depth, "");
>
> Doesn't seem crazy...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-05-19 17:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19 12:41 lockdep tracing and using of printk return value ? Joe Perches
2020-05-19 14:45 ` Peter Zijlstra
2020-05-19 17:21 ` Joe Perches
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.