Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: ubi: Add logging functions ubi_msg, ubi_warn and ubi_err

Using logging functions instead of macros can reduce overall object size.

$ size drivers/mtd/ubi/built-in.o*
text data bss dec hex filename
271620 163364 73696 508680 7c308 drivers/mtd/ubi/built-in.o.allyesconfig.new
287638 165380 73504 526522 808ba drivers/mtd/ubi/built-in.o.allyesconfig.old
87728 3780 504 92012 1676c drivers/mtd/ubi/built-in.o.defconfig.new
97084 3780 504 101368 18bf8 drivers/mtd/ubi/built-in.o.defconfig.old

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Richard Weinberger <richard@nod.at>

authored by

Joe Perches and committed by
Richard Weinberger
58d303de 3e7f2c51

+59 -6
+49
drivers/mtd/ubi/misc.c
··· 153 153 return 0; 154 154 return 1; 155 155 } 156 + 157 + /* Normal UBI messages */ 158 + void ubi_msg(const struct ubi_device *ubi, const char *fmt, ...) 159 + { 160 + struct va_format vaf; 161 + va_list args; 162 + 163 + va_start(args, fmt); 164 + 165 + vaf.fmt = fmt; 166 + vaf.va = &args; 167 + 168 + pr_notice(UBI_NAME_STR "%d: %pV\n", ubi->ubi_num, &vaf); 169 + 170 + va_end(args); 171 + } 172 + 173 + /* UBI warning messages */ 174 + void ubi_warn(const struct ubi_device *ubi, const char *fmt, ...) 175 + { 176 + struct va_format vaf; 177 + va_list args; 178 + 179 + va_start(args, fmt); 180 + 181 + vaf.fmt = fmt; 182 + vaf.va = &args; 183 + 184 + pr_warn(UBI_NAME_STR "%d warning: %ps: %pV\n", 185 + ubi->ubi_num, __builtin_return_address(0), &vaf); 186 + 187 + va_end(args); 188 + } 189 + 190 + /* UBI error messages */ 191 + void ubi_err(const struct ubi_device *ubi, const char *fmt, ...) 192 + { 193 + struct va_format vaf; 194 + va_list args; 195 + 196 + va_start(args, fmt); 197 + 198 + vaf.fmt = fmt; 199 + vaf.va = &args; 200 + 201 + pr_err(UBI_NAME_STR "%d error: %ps: %pV\n", 202 + ubi->ubi_num, __builtin_return_address(0), &vaf); 203 + va_end(args); 204 + }
+10 -6
drivers/mtd/ubi/ubi.h
··· 49 49 /* UBI name used for character devices, sysfs, etc */ 50 50 #define UBI_NAME_STR "ubi" 51 51 52 + struct ubi_device; 53 + 52 54 /* Normal UBI messages */ 53 - #define ubi_msg(ubi, fmt, ...) pr_notice(UBI_NAME_STR "%d: " fmt "\n", \ 54 - ubi->ubi_num, ##__VA_ARGS__) 55 + __printf(2, 3) 56 + void ubi_msg(const struct ubi_device *ubi, const char *fmt, ...); 57 + 55 58 /* UBI warning messages */ 56 - #define ubi_warn(ubi, fmt, ...) pr_warn(UBI_NAME_STR "%d warning: %s: " fmt "\n", \ 57 - ubi->ubi_num, __func__, ##__VA_ARGS__) 59 + __printf(2, 3) 60 + void ubi_warn(const struct ubi_device *ubi, const char *fmt, ...); 61 + 58 62 /* UBI error messages */ 59 - #define ubi_err(ubi, fmt, ...) pr_err(UBI_NAME_STR "%d error: %s: " fmt "\n", \ 60 - ubi->ubi_num, __func__, ##__VA_ARGS__) 63 + __printf(2, 3) 64 + void ubi_err(const struct ubi_device *ubi, const char *fmt, ...); 61 65 62 66 /* Background thread name pattern */ 63 67 #define UBI_BGT_NAME_PATTERN "ubi_bgt%dd"