Skip to contentSkip to conversation

Replaced printk() with pr_err() in lustre

PATCH Superseded Tina Johnson 3 participants 6 messages Mar 1, 2015 Staging

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Replaced printk() with pr_err() in lustre

The following patches replaces printk() with pr_err() to remove the checkpatch warning:

Prefer [subsystem eg: netdev]_err([subsystem]dev)

Tina Johnson (2):
staging: lustre: lustre: libcfs: Replaced printk() with pr_err()
staging: lustre: lustre: libcfs: Replaced printk() with pr_err()

 drivers/staging/lustre/lustre/libcfs/module.c    |    4 ++--
 drivers/staging/lustre/lustre/libcfs/tracefile.c |   19 +++++++++----------
 2 files changed, 11 insertions(+), 12 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/2 staging: lustre: lustre: libcfs: Replaced printk() with pr_err()

The following checkpatch warning was fixed:

Prefer [subsystem eg: netdev]_err([subsystem]dev

with the help of Coccinelle. The following semantic patch was used:

@a@
expression e;
@@

printk(e,...);

@script:python b@
e << a.e;
y;
@@

import re
match = re.match('KERN_ERR ', e);
if (match == None):
cocci.include_match(False)

else:

    m = re.sub('KERN_ERR ', '', e)
    coccinelle.y = m;

@c@
expression a.e;
identifier b.y;
@@

- printk(e,
+ pr_err(y,
...);

---
 drivers/staging/lustre/lustre/libcfs/module.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/lustre/lustre/libcfs/module.c +2 -2
index 7dc77dd..e05d181 100644
@@ -347,7 +347,7 @@ static int init_libcfs_module(void)
 
 	rc = libcfs_debug_init(5 * 1024 * 1024);
 	if (rc < 0) {
-		printk(KERN_ERR "LustreError: libcfs_debug_init: %d\n", rc);
+		pr_err("LustreError: libcfs_debug_init: %d\n", rc);
 		return rc;
 	}
 
@@ -433,7 +433,7 @@ static void exit_libcfs_module(void)
 
 	rc = libcfs_debug_cleanup();
 	if (rc)
-		printk(KERN_ERR "LustreError: libcfs_debug_cleanup: %d\n",
+		pr_err("LustreError: libcfs_debug_cleanup: %d\n",
 		       rc);
 
 	libcfs_arch_cleanup();
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [Outreachy kernel] [PATCH 1/2] staging: lustre: lustre: libcfs: Replaced printk() with pr_err()

drivers/staging/lustre/lustre/libcfs/module.c static void exit_libcfs_module(void) · line 437

Quoted 7 lines
drivers/staging/lustre/lustre/libcfs/module.c +1 -1
@@ -433,7 +433,7 @@ static void exit_libcfs_module(void)
 
 	rc = libcfs_debug_cleanup();
 	if (rc)
-		printk(KERN_ERR "LustreError: libcfs_debug_cleanup: %d\n",
+		pr_err("LustreError: libcfs_debug_cleanup: %d\n",
 		       rc);

A newline could be removed here.

julia

#3 lore raw

PATCH 2/2 staging: lustre: lustre: libcfs: Replaced printk() with pr_err()

In reply to Tina Johnson

The following checkpatch warning was fixed:

Prefer [subsystem eg: netdev]_err([subsystem]dev

with the help of Coccinelle. The following semantic patch was used:

@a@
expression e;
@@

printk(e,...);

@script:python b@
e << a.e;
y;
@@

import re
match = re.match('KERN_ERR ', e);
if (match == None):
cocci.include_match(False)

else:

    m = re.sub('KERN_ERR ', '', e)
    coccinelle.y = m;

@c@
expression a.e;
identifier b.y;
@@

- printk(e,
+ pr_err(y,
...);

---
 drivers/staging/lustre/lustre/libcfs/tracefile.c |   19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/staging/lustre/lustre/libcfs/tracefile.c +9 -10
index eb65b50..0f617d5 100644
@@ -224,8 +224,7 @@ static struct cfs_trace_page *cfs_trace_get_tage(struct cfs_trace_cpu_data *tcd,
 	 */
 
 	if (len > PAGE_CACHE_SIZE) {
-		printk(KERN_ERR
-		       "cowardly refusing to write %lu bytes in a page\n", len);
+		pr_err("cowardly refusing to write %lu bytes in a page\n", len);
 		return NULL;
 	}
 
@@ -688,7 +687,7 @@ int cfs_tracefile_dump_all_pages(char *filename)
 	if (IS_ERR(filp)) {
 		rc = PTR_ERR(filp);
 		filp = NULL;
-		printk(KERN_ERR "LustreError: can't open %s for dump: rc %d\n",
+		pr_err("LustreError: can't open %s for dump: rc %d\n",
 		      filename, rc);
 		goto out;
 	}
@@ -726,7 +725,7 @@ int cfs_tracefile_dump_all_pages(char *filename)
 	MMSPACE_CLOSE;
 	rc = vfs_fsync(filp, 1);
 	if (rc)
-		printk(KERN_ERR "sync returns %d\n", rc);
+		pr_err("sync returns %d\n", rc);
 close:
 	filp_close(filp, NULL);
 out:
@@ -1048,21 +1047,21 @@ static int tracefiled(void *arg)
 			int i;
 
 			printk(KERN_ALERT "Lustre: trace pages aren't empty\n");
-			printk(KERN_ERR "total cpus(%d): ",
+			pr_err("total cpus(%d): ",
 			       num_possible_cpus());
 			for (i = 0; i < num_possible_cpus(); i++)
 				if (cpu_online(i))
-					printk(KERN_ERR "%d(on) ", i);
+					pr_err("%d(on) ", i);
 				else
-					printk(KERN_ERR "%d(off) ", i);
-			printk(KERN_ERR "\n");
+					pr_err("%d(off) ", i);
+			pr_err("\n");
 
 			i = 0;
 			list_for_each_entry_safe(tage, tmp, &pc.pc_pages,
 						     linkage)
-				printk(KERN_ERR "page %d belongs to cpu %d\n",
+				pr_err("page %d belongs to cpu %d\n",
 				       ++i, tage->cpu);
-			printk(KERN_ERR "There are %d pages unwritten\n",
+			pr_err("There are %d pages unwritten\n",
 			       i);
 		}
 		__LASSERT(list_empty(&pc.pc_pages));
Signature · 1 line
1.7.10.4
#4 lore raw

Re: [Outreachy kernel] [PATCH 2/2] staging: lustre: lustre: libcfs: Replaced printk() with pr_err()

drivers/staging/lustre/lustre/libcfs/tracefile.c static int tracefiled(void *arg) · line 1051

Quoted 5 lines · On Sunday 01 March 2015 23:45:07 Tina Johnson wrote:
                        printk(KERN_ALERT "Lustre: trace pages aren't empty\n");
drivers/staging/lustre/lustre/libcfs/tracefile.c +1 -1
-                       printk(KERN_ERR "total cpus(%d): ",
+                       pr_err("total cpus(%d): ",
                               num_possible_cpus());

Here it would be nice to move the second argument into the same line as the start of the pr_err() expression.

drivers/staging/lustre/lustre/libcfs/tracefile.c static int tracefiled(void *arg) · line 1057

Quoted 9 lines
                        for (i = 0; i < num_possible_cpus(); i++)
                                if (cpu_online(i))
drivers/staging/lustre/lustre/libcfs/tracefile.c +3 -3
-                                       printk(KERN_ERR "%d(on) ", i);
+                                       pr_err("%d(on) ", i);
                                else
-                                       printk(KERN_ERR "%d(off) ", i);
-                       printk(KERN_ERR "\n");
+                                       pr_err("%d(off) ", i);
+                       pr_err("\n");

This is unfortunately wrong, although the bug was preexisting:

When you have printk that does not end in '\n', the following printk must leave out the 'KERN_ERR' format modifier and use KERN_CONT instead. These should all be pr_cont() instead of pr_err.

Arnd

#5 lore raw

Re: [Outreachy kernel] [PATCH 2/2] staging: lustre: lustre: libcfs: Replaced printk() with pr_err()

In reply to Tina Johnson

drivers/staging/lustre/lustre/libcfs/tracefile.c int cfs_tracefile_dump_all_pages(char *filename) · line 691

Quoted 7 lines
drivers/staging/lustre/lustre/libcfs/tracefile.c +1 -1
@@ -688,7 +687,7 @@ int cfs_tracefile_dump_all_pages(char *filename)
 	if (IS_ERR(filp)) {
 		rc = PTR_ERR(filp);
 		filp = NULL;
-		printk(KERN_ERR "LustreError: can't open %s for dump: rc %d\n",
+		pr_err("LustreError: can't open %s for dump: rc %d\n",
 		      filename, rc);

filename could be moved to the right a little, to be in line with the first argument.

drivers/staging/lustre/lustre/libcfs/tracefile.c static int tracefiled(void *arg) · line 1065

Quoted 3 lines
drivers/staging/lustre/lustre/libcfs/tracefile.c +1 -1
-			printk(KERN_ERR "There are %d pages unwritten\n",
+			pr_err("There are %d pages unwritten\n",
 			       i);

A newline could be removed here.

julia