lockdep tracing and using of printk return value ?
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(-)
kernel/locking/lockdep.c +3 -5
@@ -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,"" );
Peter Zijlstra
maintainerQuoted 2 lines · Joe Perches
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?
Quoted 4 lines
Code that uses the printk return value in
kernel/locking/lockdep.cis 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.
Quoted 16 lines
Perhaps there's a better way to calculate this?
Maybe:
--- kernel/locking/lockdep.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)kernel/locking/lockdep.c +0
-1@@ -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;
kernel/locking/lockdep.c static void print_lock_class_header(struct lock_class *class, int depth) · line 1968
Quoted 10 lines
kernel/locking/lockdep.c +3
-4- - 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...
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines · Joe Perches
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/[email protected]/
Quoted 7 lines
Quoted 4 lines
Code that uses the printk return value in
kernel/locking/lockdep.cis 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.
Quoted 28 lines
Quoted 16 lines
Perhaps there's a better way to calculate this?
Maybe:
--- kernel/locking/lockdep.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)kernel/locking/lockdep.c +0
-1@@ -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;kernel/locking/lockdep.c static void print_lock_class_header(struct lock_class *class, int depth) · line 1968
Quoted 10 lines
kernel/locking/lockdep.c +3
-4- - 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...