Skip to contentSkip to conversation

erofs: simplify definition of the log functions

PATCH Superseded Gou Hao 2 participants 2 messages Oct 18, 2024 – Nov 13, 2024 EROFS file system

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Gou Hao

author
#0 lore raw

PATCH 1/1 erofs: simplify definition of the log functions

using printk instead of pr_info/err, reduce
redundant code.

---
 fs/erofs/internal.h |  9 ++++-----
 fs/erofs/super.c    | 28 +++++++---------------------
 2 files changed, 11 insertions(+), 26 deletions(-)
fs/erofs/internal.h +4 -5
index 4efd578d7c62..ae87e855e815 100644
@@ -24,14 +24,13 @@
 #undef pr_fmt
 #define pr_fmt(fmt) "erofs: " fmt
 
-__printf(3, 4) void _erofs_err(struct super_block *sb,
+__printf(3, 4) void _erofs_printk(struct super_block *sb,
 			       const char *function, const char *fmt, ...);
 #define erofs_err(sb, fmt, ...)	\
-	_erofs_err(sb, __func__, fmt "\n", ##__VA_ARGS__)
-__printf(3, 4) void _erofs_info(struct super_block *sb,
-			       const char *function, const char *fmt, ...);
+	_erofs_printk(sb, __func__, KERN_ERR fmt "\n", ##__VA_ARGS__)
 #define erofs_info(sb, fmt, ...) \
-	_erofs_info(sb, __func__, fmt "\n", ##__VA_ARGS__)
+	_erofs_printk(sb, __func__, KERN_INFO fmt "\n", ##__VA_ARGS__)
+
 #ifdef CONFIG_EROFS_FS_DEBUG
 #define DBG_BUGON               BUG_ON
 #else
fs/erofs/super.c +7 -21
index 666873f745da..64c3258ddf9a 100644
@@ -18,37 +18,23 @@
 
 static struct kmem_cache *erofs_inode_cachep __read_mostly;
 
-void _erofs_err(struct super_block *sb, const char *func, const char *fmt, ...)
+void _erofs_printk(struct super_block *sb, const char *func, const char *fmt, ...)
 {
 	struct va_format vaf;
 	va_list args;
+	int level;
 
 	va_start(args, fmt);
 
-	vaf.fmt = fmt;
+	level = printk_get_level(fmt);
+	vaf.fmt = printk_skip_level(fmt);
 	vaf.va = &args;
 
 	if (sb)
-		pr_err("(device %s): %s: %pV", sb->s_id, func, &vaf);
+		printk("%c%c(device %s): %s: %pV",
+				KERN_SOH_ASCII, level, sb->s_id, func, &vaf);
 	else
-		pr_err("%s: %pV", func, &vaf);
-	va_end(args);
-}
-
-void _erofs_info(struct super_block *sb, const char *func, const char *fmt, ...)
-{
-	struct va_format vaf;
-	va_list args;
-
-	va_start(args, fmt);
-
-	vaf.fmt = fmt;
-	vaf.va = &args;
-
-	if (sb)
-		pr_info("(device %s): %pV", sb->s_id, &vaf);
-	else
-		pr_info("%pV", &vaf);
+		printk("%c%c%s: %pV", KERN_SOH_ASCII, level, func, &vaf);
 	va_end(args);
 }
 
Signature · 1 line
2.43.0
#1 lore raw

Hi Hao,

Sorry for late response due to my long vacation.

Quoted 2 lines · Gou Hao

using printk instead of pr_info/err, reduce
redundant code.

Use printk instead of pr_info/err to reduce
redundant code.

Quoted 41 lines
---
  fs/erofs/internal.h |  9 ++++-----
  fs/erofs/super.c    | 28 +++++++---------------------
  2 files changed, 11 insertions(+), 26 deletions(-)
fs/erofs/internal.h +4 -5
index 4efd578d7c62..ae87e855e815 100644
@@ -24,14 +24,13 @@
  #undef pr_fmt
  #define pr_fmt(fmt) "erofs: " fmt
 
-__printf(3, 4) void _erofs_err(struct super_block *sb,
+__printf(3, 4) void _erofs_printk(struct super_block *sb,
  			       const char *function, const char *fmt, ...);
  #define erofs_err(sb, fmt, ...)	\
-	_erofs_err(sb, __func__, fmt "\n", ##__VA_ARGS__)
-__printf(3, 4) void _erofs_info(struct super_block *sb,
-			       const char *function, const char *fmt, ...);
+	_erofs_printk(sb, __func__, KERN_ERR fmt "\n", ##__VA_ARGS__)
  #define erofs_info(sb, fmt, ...) \
-	_erofs_info(sb, __func__, fmt "\n", ##__VA_ARGS__)
+	_erofs_printk(sb, __func__, KERN_INFO fmt "\n", ##__VA_ARGS__)
+
  #ifdef CONFIG_EROFS_FS_DEBUG
  #define DBG_BUGON               BUG_ON
  #else
fs/erofs/super.c +1 -1
index 666873f745da..64c3258ddf9a 100644
@@ -18,37 +18,23 @@
 
  static struct kmem_cache *erofs_inode_cachep __read_mostly;
 
-void _erofs_err(struct super_block *sb, const char *func, const char *fmt, ...)
+void _erofs_printk(struct super_block *sb, const char *func, const char *fmt, ...)
  {

fs/erofs/super.c line 31

Quoted 10 lines
fs/erofs/super.c +3 -1
  	struct va_format vaf;
  	va_list args;
+	int level;
 
  	va_start(args, fmt);
 
-	vaf.fmt = fmt;
+	level = printk_get_level(fmt);
+	vaf.fmt = printk_skip_level(fmt);
  	vaf.va = &args;

Let's get rid of const char *func, for all cases since I think it's not very helpful indeed.

Thanks,
Gao Xiang