From: pratikshinde320@gmail.com (Pratik Shinde)
Subject: [PATCH v2] erofs-utils: code for handling incorrect debug level.
Date: Sun, 4 Aug 2019 13:49:43 +0530 [thread overview]
Message-ID: <20190804081943.20666-1-pratikshinde320@gmail.com> (raw)
handling the case of incorrect debug level.
Added an enumerated type for supported debug levels.
Using 'atoi' in place of 'parse_num_from_str'.
Signed-off-by: Pratik Shinde <pratikshinde320 at gmail.com>
---
include/erofs/print.h | 18 +++++++++++++-----
mkfs/main.c | 19 ++++++++-----------
2 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/include/erofs/print.h b/include/erofs/print.h
index bc0b8d4..296cbbf 100644
--- a/include/erofs/print.h
+++ b/include/erofs/print.h
@@ -12,6 +12,15 @@
#include "config.h"
#include <stdio.h>
+enum {
+ EROFS_MSG_MIN = 0,
+ EROFS_ERR = 0,
+ EROFS_WARN = 2,
+ EROFS_INFO = 3,
+ EROFS_DBG = 7,
+ EROFS_MSG_MAX = 9
+};
+
#define FUNC_LINE_FMT "%s() Line[%d] "
#ifndef pr_fmt
@@ -19,7 +28,7 @@
#endif
#define erofs_dbg(fmt, ...) do { \
- if (cfg.c_dbg_lvl >= 7) { \
+ if (cfg.c_dbg_lvl >= EROFS_DBG) { \
fprintf(stdout, \
pr_fmt(fmt), \
__func__, \
@@ -29,7 +38,7 @@
} while (0)
#define erofs_info(fmt, ...) do { \
- if (cfg.c_dbg_lvl >= 3) { \
+ if (cfg.c_dbg_lvl >= EROFS_INFO) { \
fprintf(stdout, \
pr_fmt(fmt), \
__func__, \
@@ -40,7 +49,7 @@
} while (0)
#define erofs_warn(fmt, ...) do { \
- if (cfg.c_dbg_lvl >= 2) { \
+ if (cfg.c_dbg_lvl >= EROFS_WARN) { \
fprintf(stdout, \
pr_fmt(fmt), \
__func__, \
@@ -51,7 +60,7 @@
} while (0)
#define erofs_err(fmt, ...) do { \
- if (cfg.c_dbg_lvl >= 0) { \
+ if (cfg.c_dbg_lvl >= EROFS_ERR) { \
fprintf(stderr, \
"Err: " pr_fmt(fmt), \
__func__, \
@@ -64,4 +73,3 @@
#endif
-
diff --git a/mkfs/main.c b/mkfs/main.c
index fdb65fd..d915d00 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -30,16 +30,6 @@ static void usage(void)
fprintf(stderr, " -EX[,...] X=extended options\n");
}
-u64 parse_num_from_str(const char *str)
-{
- u64 num = 0;
- char *endptr = NULL;
-
- num = strtoull(str, &endptr, 10);
- BUG_ON(num == ULLONG_MAX);
- return num;
-}
-
static int parse_extended_opts(const char *opts)
{
#define MATCH_EXTENTED_OPT(opt, token, keylen) \
@@ -108,7 +98,14 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
break;
case 'd':
- cfg.c_dbg_lvl = parse_num_from_str(optarg);
+ cfg.c_dbg_lvl = atoi(optarg);
+ if (cfg.c_dbg_lvl < EROFS_MSG_MIN
+ || cfg.c_dbg_lvl > EROFS_MSG_MAX) {
+ fprintf(stderr,
+ "invalid debug level %d\n",
+ cfg.c_dbg_lvl);
+ return -EINVAL;
+ }
break;
case 'E':
--
2.9.3
next reply other threads:[~2019-08-04 8:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-04 8:19 Pratik Shinde [this message]
2019-08-04 10:16 ` [PATCH v2] erofs-utils: code for handling incorrect debug level Gao Xiang
2019-08-04 10:33 ` Pratik Shinde
2019-08-04 11:31 ` Gao Xiang
2019-08-04 11:39 ` Pratik Shinde
2019-08-04 12:57 ` Li Guifu
2019-08-04 15:25 ` Gao Xiang
2019-08-04 15:41 ` Li Guifu
2019-08-04 15:51 ` Gao Xiang
2019-08-04 19:02 ` Pratik Shinde
2019-08-05 2:20 ` Gao Xiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190804081943.20666-1-pratikshinde320@gmail.com \
--to=pratikshinde320@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.