[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1610382798-4528-1-git-send-email-zhaowei1102@thundersoft.com>
Date: Mon, 11 Jan 2021 08:33:17 -0800
From: Wesley Zhao <zhaowei1102@...ndersoft.com>
To: akpm@...ux-foundation.org
Cc: andriy.shevchenko@...ux.intel.com, keescook@...omium.org,
tglx@...utronix.de, kerneldev@...smulder.nl, nivedita@...m.mit.edu,
joe@...ches.com, gpiccoli@...onical.com, aquini@...hat.com,
gustavoars@...nel.org, zhaowei1102@...ndersoft.com,
ojeda@...nel.org, ndesaulniers@...ogle.com,
linux-kernel@...r.kernel.org, david@...hat.com,
dan.j.williams@...el.com, guohanjun@...wei.com,
mchehab+huawei@...nel.org
Subject: [PATCH 1/2] lib/cmdline: add new function get_option_ull()
From: "Wesley.Zhao" <zhaowei1102@...ndersoft.com>
In the future we would pass the unsigned long long parameter
like(0x123456781234) in cmdline on the 64bit platform, so add a new
option parse function get_option_ull()
Signed-off-by: Wesley.Zhao <zhaowei1102@...ndersoft.com>
---
include/linux/kernel.h | 1 +
lib/cmdline.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index f7902d8..5568133 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -348,6 +348,7 @@ extern __scanf(2, 0)
int vsscanf(const char *, const char *, va_list);
extern int get_option(char **str, int *pint);
+extern int get_option_ull(char **str, unsigned long long *pull);
extern char *get_options(const char *str, int nints, int *ints);
extern unsigned long long memparse(const char *ptr, char **retptr);
extern bool parse_option_str(const char *str, const char *option);
diff --git a/lib/cmdline.c b/lib/cmdline.c
index b390dd0..2d089a2 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -80,6 +80,41 @@ int get_option(char **str, int *pint)
EXPORT_SYMBOL(get_option);
/**
+ * get_option_ull - Parse unsigned long long from an option string
+ * @str: option string
+ * @pull: (output) unsigned long long value parsed from @str
+ *
+ * Read an unsigned long long from an option string; if available accept a subsequent
+ * comma as well.
+ *
+ * Return values:
+ * 0 - no ull in string
+ * 1 - ull found, no subsequent comma
+ * 2 - ull found including a subsequent comma
+ * 3 - hyphen found to denote a range
+ */
+
+int get_option_ull(char **str, unsigned long long *pull)
+{
+ char *cur = *str;
+
+ if (!cur || !(*cur))
+ return 0;
+ *pull = simple_strtoull(cur, str, 0);
+ if (cur == *str)
+ return 0;
+ if (**str == ',') {
+ (*str)++;
+ return 2;
+ }
+ if (**str == '-')
+ return 3;
+
+ return 1;
+}
+EXPORT_SYMBOL(get_option_ull);
+
+/**
* get_options - Parse a string into a list of integers
* @str: String to be parsed
* @nints: size of integer array
--
2.7.4
Powered by blists - more mailing lists