From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754099AbdDQNfY (ORCPT ); Mon, 17 Apr 2017 09:35:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48414 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753167AbdDQNfT (ORCPT ); Mon, 17 Apr 2017 09:35:19 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0F4FAC04B936 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=bhe@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0F4FAC04B936 From: Baoquan He To: linux-kernel@vger.kernel.org Cc: keescook@chromium.org, dave.jiang@intel.com, dan.j.williams@intel.com, hpa@zytor.com, tglx@linutronix.de, mingo@kernel.org, dyoung@redhat.com, Baoquan He , Andrew Morton , Jessica Yu , Petr Mladek , Jens Axboe , Josh Triplett , zijun_hu , Larry Finger , Johannes Berg , Rasmus Villemoes , Gustavo Padovan , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Peter Zijlstra Subject: [PATCH 1/4] param: Move function next_arg to lib/cmdline.c for later reuse Date: Mon, 17 Apr 2017 21:34:56 +0800 Message-Id: <1492436099-4017-2-git-send-email-bhe@redhat.com> In-Reply-To: <1492436099-4017-1-git-send-email-bhe@redhat.com> References: <1492436099-4017-1-git-send-email-bhe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=n Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 17 Apr 2017 13:35:19 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org next_arg will be used to parse cmdline in x86/boot/compressed code, so move it to lib/cmdline.c for better code reuse. No change in functionality. Signed-off-by: Baoquan He Cc: Andrew Morton Cc: Jessica Yu Cc: Petr Mladek Cc: Jens Axboe Cc: Josh Triplett Cc: zijun_hu Cc: Larry Finger Cc: Johannes Berg Cc: Rasmus Villemoes Cc: Gustavo Padovan Cc: "Niklas Söderlund" Cc: Peter Zijlstra --- include/linux/kernel.h | 1 + kernel/params.c | 52 --------------------------------------------- lib/cmdline.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 52 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 4c26dc3..7ae2567 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -438,6 +438,7 @@ extern int get_option(char **str, int *pint); 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); +extern char *next_arg(char *args, char **param, char **val); extern int core_kernel_text(unsigned long addr); extern int core_kernel_data(unsigned long addr); diff --git a/kernel/params.c b/kernel/params.c index a6d6149..60b2d81 100644 --- a/kernel/params.c +++ b/kernel/params.c @@ -160,58 +160,6 @@ static int parse_one(char *param, return -ENOENT; } -/* You can use " around spaces, but can't escape ". */ -/* Hyphens and underscores equivalent in parameter names. */ -static char *next_arg(char *args, char **param, char **val) -{ - unsigned int i, equals = 0; - int in_quote = 0, quoted = 0; - char *next; - - if (*args == '"') { - args++; - in_quote = 1; - quoted = 1; - } - - for (i = 0; args[i]; i++) { - if (isspace(args[i]) && !in_quote) - break; - if (equals == 0) { - if (args[i] == '=') - equals = i; - } - if (args[i] == '"') - in_quote = !in_quote; - } - - *param = args; - if (!equals) - *val = NULL; - else { - args[equals] = '\0'; - *val = args + equals + 1; - - /* Don't include quotes in value. */ - if (**val == '"') { - (*val)++; - if (args[i-1] == '"') - args[i-1] = '\0'; - } - } - if (quoted && args[i-1] == '"') - args[i-1] = '\0'; - - if (args[i]) { - args[i] = '\0'; - next = args + i + 1; - } else - next = args + i; - - /* Chew up trailing spaces. */ - return skip_spaces(next); -} - /* Args looks like "foo=bar,bar2 baz=fuz wiz". */ char *parse_args(const char *doing, char *args, diff --git a/lib/cmdline.c b/lib/cmdline.c index 8f13cf7..6e3abfb 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c @@ -15,6 +15,7 @@ #include #include #include +#include /* * If a hyphen was found in get_option, this will handle the @@ -189,3 +190,59 @@ bool parse_option_str(const char *str, const char *option) return false; } + +/* + * Parse a string to get a param value pair. + * You can use " around spaces, but can't escape ". + * Hyphens and underscores equivalent in parameter names. + */ +char *next_arg(char *args, char **param, char **val) +{ + unsigned int i, equals = 0; + int in_quote = 0, quoted = 0; + char *next; + + if (*args == '"') { + args++; + in_quote = 1; + quoted = 1; + } + + for (i = 0; args[i]; i++) { + if (isspace(args[i]) && !in_quote) + break; + if (equals == 0) { + if (args[i] == '=') + equals = i; + } + if (args[i] == '"') + in_quote = !in_quote; + } + + *param = args; + if (!equals) + *val = NULL; + else { + args[equals] = '\0'; + *val = args + equals + 1; + + /* Don't include quotes in value. */ + if (**val == '"') { + (*val)++; + if (args[i-1] == '"') + args[i-1] = '\0'; + } + } + if (quoted && args[i-1] == '"') + args[i-1] = '\0'; + + if (args[i]) { + args[i] = '\0'; + next = args + i + 1; + } else + next = args + i; + + /* Chew up trailing spaces. */ + return skip_spaces(next); + //return next; +} -- 2.5.5