Commit d9504573 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by jiayingbao
Browse files

lib/cmdline: Allow get_options() to take 0 to validate the input

mainline inclusion
from mainline-v5.12-rc1
commit 0ea09083
category: feature
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I8WOEC

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0ea09083116de44f1a938482fb704bbfcc7ae6f4



-------------------------------------

Allow get_options() to take 0 as a number of integers parameter to validate
the input.

Intel-SIG: commit 0ea09083 lib/cmdline: Allow get_options() to take 0 to validate the input.
Backport Intel_tpmi base driver.

Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
[ Yingbao Jia: amend commit log ]
Signed-off-by: default avatarYingbao Jia <yingbao.jia@intel.com>
parent f7344bb5
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -85,6 +85,9 @@ EXPORT_SYMBOL(get_option);
 *	full, or when no more numbers can be retrieved from the
 *	string.
 *
 *	When @nints is 0, the function just validates the given @str and
 *	returns the amount of parseable integers as described below.
 *
 *	Return value is the character in the string which caused
 *	the parse to end (typically a null terminator, if @str is
 *	completely parseable).
@@ -92,15 +95,20 @@ EXPORT_SYMBOL(get_option);

char *get_options(const char *str, int nints, int *ints)
{
	bool validate = (nints == 0);
	int res, i = 1;

	while (i < nints) {
		res = get_option((char **)&str, ints + i);
	while (i < nints || validate) {
		int *pint = validate ? ints : ints + i;

		res = get_option((char **)&str, pint);
		if (res == 0)
			break;
		if (res == 3) {
			int n = validate ? 0 : nints - i;
			int range_nums;
			range_nums = get_range((char **)&str, ints + i, nints - i);

			range_nums = get_range((char **)&str, pint, n);
			if (range_nums < 0)
				break;
			/*