[PATCH] sched: change printk(KERN_<LEVEL>.. to pr_<level>()

Yu Zhe posted 1 patch 3 years, 11 months ago
kernel/sched/core.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
[PATCH] sched: change printk(KERN_<LEVEL>.. to pr_<level>()
Posted by Yu Zhe 3 years, 11 months ago
Prefer pr_<level>(...  to printk(KERN_<LEVEL> ..., change them.

Signed-off-by: Yu Zhe <yuzhe@nfschina.com>
---
 kernel/sched/core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index a247f8d9d417..4522bb3bbafb 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5602,7 +5602,7 @@ static noinline void __schedule_bug(struct task_struct *prev)
 	if (oops_in_progress)
 		return;
 
-	printk(KERN_ERR "BUG: scheduling while atomic: %s/%d/0x%08x\n",
+	pr_err("BUG: scheduling while atomic: %s/%d/0x%08x\n",
 		prev->comm, prev->pid, preempt_count());
 
 	debug_show_held_locks(prev);
@@ -5636,7 +5636,7 @@ static inline void schedule_debug(struct task_struct *prev, bool preempt)
 
 #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
 	if (!preempt && READ_ONCE(prev->__state) && prev->non_block_count) {
-		printk(KERN_ERR "BUG: scheduling in a non-blocking section: %s/%d/%i\n",
+		pr_err("BUG: scheduling in a non-blocking section: %s/%d/%i\n",
 			prev->comm, prev->pid, prev->non_block_count);
 		dump_stack();
 		add_taint(TAINT_WARN, LOCKDEP_STILL_OK);
@@ -9370,7 +9370,7 @@ static void dump_rq_tasks(struct rq *rq, const char *loglvl)
 
 	lockdep_assert_rq_held(rq);
 
-	printk("%sCPU%d enqueued tasks (%u total):\n", loglvl, cpu, rq->nr_running);
+	pr_warn("%sCPU%d enqueued tasks (%u total):\n", loglvl, cpu, rq->nr_running);
 	for_each_process_thread(g, p) {
 		if (task_cpu(p) != cpu)
 			continue;
@@ -9378,7 +9378,7 @@ static void dump_rq_tasks(struct rq *rq, const char *loglvl)
 		if (!task_on_rq_queued(p))
 			continue;
 
-		printk("%s\tpid: %d, name: %s\n", loglvl, p->pid, p->comm);
+		pr_warn("%s\tpid: %d, name: %s\n", loglvl, p->pid, p->comm);
 	}
 }
 
@@ -9773,8 +9773,8 @@ void __cant_sleep(const char *file, int line, int preempt_offset)
 		return;
 	prev_jiffy = jiffies;
 
-	printk(KERN_ERR "BUG: assuming atomic context at %s:%d\n", file, line);
-	printk(KERN_ERR "in_atomic(): %d, irqs_disabled(): %d, pid: %d, name: %s\n",
+	pr_err("BUG: assuming atomic context at %s:%d\n", file, line);
+	pr_err("in_atomic(): %d, irqs_disabled(): %d, pid: %d, name: %s\n",
 			in_atomic(), irqs_disabled(),
 			current->pid, current->comm);
 
-- 
2.25.1
Re: [PATCH] sched: change printk(KERN_<LEVEL>.. to pr_<level>()
Posted by Dan Carpenter 3 years, 11 months ago
On Thu, May 26, 2022 at 02:10:31AM -0700, Yu Zhe wrote:
> @@ -9370,7 +9370,7 @@ static void dump_rq_tasks(struct rq *rq, const char *loglvl)
>  
>  	lockdep_assert_rq_held(rq);
>  
> -	printk("%sCPU%d enqueued tasks (%u total):\n", loglvl, cpu, rq->nr_running);
> +	pr_warn("%sCPU%d enqueued tasks (%u total):\n", loglvl, cpu, rq->nr_running);
                                                        ^^^^^^

Your patch is wrong.  The code aready has loglvl but as a variable.

Don't start sending checkpatch stuff to kernel/sched.  Better to get
some experience in drivers/staging/ because Greg deliberately leaves a
lot of garbage code for people to clean up and get experience.

regards,
dan carpenter
Re: [PATCH] sched: change printk(KERN_<LEVEL>.. to pr_<level>()
Posted by Joe Perches 3 years, 11 months ago
On Thu, 2022-05-26 at 02:10 -0700, Yu Zhe wrote:
> Prefer pr_<level>(...  to printk(KERN_<LEVEL> ..., change them.

Do remember that checkpatch is just a guide and isn't always correct.

You are responsible for verifying that anything it suggests is
converted properly.

> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
[]
> @@ -9370,7 +9370,7 @@ static void dump_rq_tasks(struct rq *rq, const char *loglvl)
>  
>  	lockdep_assert_rq_held(rq);
>  
> -	printk("%sCPU%d enqueued tasks (%u total):\n", loglvl, cpu, rq->nr_running);
> +	pr_warn("%sCPU%d enqueued tasks (%u total):\n", loglvl, cpu, rq->nr_running);

This is _not_ a good change.

Do please look to see what loglvl is and if this change is appropriate.

>  	for_each_process_thread(g, p) {
>  		if (task_cpu(p) != cpu)
>  			continue;
> @@ -9378,7 +9378,7 @@ static void dump_rq_tasks(struct rq *rq, const char *loglvl)
>  		if (!task_on_rq_queued(p))
>  			continue;
>  
> -		printk("%s\tpid: %d, name: %s\n", loglvl, p->pid, p->comm);
> +		pr_warn("%s\tpid: %d, name: %s\n", loglvl, p->pid, p->comm);

here too.