Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1531871pxb; Thu, 28 Jan 2021 20:57:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJy4wtLmcQAepgPvPgqOSssjDPagG6HjB2n48PT4vwF293XzmDFyG804d5upqUG81FoFjE/s X-Received: by 2002:a17:907:2458:: with SMTP id yw24mr2827880ejb.333.1611896240331; Thu, 28 Jan 2021 20:57:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611896240; cv=none; d=google.com; s=arc-20160816; b=v2J/VXV6ywHDVEDsMruEsj8bZMl2J1D2miBCxL3Na8xAeWVYZFP0zGjqRR3xMY7jcO SVfjUjDE79zsyUdXEj+YDXertKRI6sTamW/hxtEpbfjwYJBP6GfHzz2/QoBZDFcdydca VQlqFczJ+/AZ46RntdQ1wtxSGB1pDzIQg1Qc8dTuxPFxbKevJO4LWSSfr+dW+KP+ffsM 8PI6cY9nY9mHYOL3limJc9lOEZ8361qclRHH+NW4Q2+gob4kRoC+NxcsL5czYKSUVg43 N2+zgAUS4bYjoEo0DJcgkvZ9DyZ/gNjctvjDCrH2rH6c+gPK/hEospuDQvjxp4ieAOy2 Fd8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=+4lFL9J/fpvewY0eqAzG8Uo2jmyFke22lXYFSeznaDM=; b=ZqUD3AtoBAueNhx6p2/flCXIVfWTOyrMdkk3go8oblS8kH+36/NgVWWs1Ho3g/Yb6f Yv8QrzA1uimO/LsHq5BrGw7P+3e1mWqTHRSmREokkOJDF/mUN0IU3yM8HWa2/hPneytn U0EB54kQfkuh3YmJhkTR06IKqxpgOQKNUMpzbBoHOFNNMqS8uXcGnqrUVTh7hSW5GWdY GzcslAtMZKFJcmgRDDNI16KLjNc3HBSFiUi96jMcvN5WUWcT7PlsggO29CEVvDlIuCuR 4rUEHH4peeFFPjdPUcB0/sEItvBIfRZVtkS364SDkhIL6L5SFRFVoKn2lvG8rQTK21HJ /7Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synology.com header.s=123 header.b=W7tkzYH0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synology.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e20si4011347ejs.246.2021.01.28.20.56.56; Thu, 28 Jan 2021 20:57:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@synology.com header.s=123 header.b=W7tkzYH0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synology.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231990AbhA2Exp (ORCPT + 99 others); Thu, 28 Jan 2021 23:53:45 -0500 Received: from mail.synology.com ([211.23.38.101]:44588 "EHLO synology.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232007AbhA2Exd (ORCPT ); Thu, 28 Jan 2021 23:53:33 -0500 Received: from localhost.localdomain (unknown [10.17.36.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by synology.com (Postfix) with ESMTPSA id 3ADA6CE781CF; Fri, 29 Jan 2021 12:52:51 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1611895971; bh=Zin92eGm3uQ3NA2MvXwbiph99acq62tN+NV0r8KQUNg=; h=From:To:Cc:Subject:Date; b=W7tkzYH0p+RtQcDOs1TU9AcWxYKAgXWenV4G+QdRvCfCDJxpd16vWdmMZVuFFB6/D rh86LUlypGcpYLeqgwaW2Mw3G9Lw4cd/zZ+trjDpA+j84rtrwZ0hteb7NM9I7OMaP8 OKetVteEeKmotnz7/3lKXl22tmaM4/SR5aWFFtCc= From: bingjingc To: viro@zeniv.linux.org.uk, jack@suse.com, jack@suse.cz, axboe@kernel.dk, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, cccheng@synology.com, bingjingc@synology.com, robbieko@synology.com, willy@infradead.org, rdunlap@infradead.org, miklos@szeredi.hu Subject: [PATCH v3 1/3] parser: add unsigned int parser Date: Fri, 29 Jan 2021 12:52:42 +0800 Message-Id: <20210129045242.10268-1-bingjingc@synology.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Synology-MCP-Status: no X-Synology-Spam-Flag: no X-Synology-Spam-Status: score=0, required 6, WHITELIST_FROM_ADDRESS 0 X-Synology-Virus-Status: no Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: BingJing Chang Will be used by fs parsing options Reviewed-by: Robbie Ko Reviewed-by: Chung-Chiang Cheng Signed-off-by: BingJing Chang --- include/linux/parser.h | 1 + lib/parser.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/linux/parser.h b/include/linux/parser.h index 89e2b23..dd79f45 100644 --- a/include/linux/parser.h +++ b/include/linux/parser.h @@ -29,6 +29,7 @@ typedef struct { int match_token(char *, const match_table_t table, substring_t args[]); int match_int(substring_t *, int *result); +int match_uint(substring_t *s, unsigned int *result); int match_u64(substring_t *, u64 *result); int match_octal(substring_t *, int *result); int match_hex(substring_t *, int *result); diff --git a/lib/parser.c b/lib/parser.c index f5b3e5d..7785e41 100644 --- a/lib/parser.c +++ b/lib/parser.c @@ -188,6 +188,28 @@ int match_int(substring_t *s, int *result) } EXPORT_SYMBOL(match_int); +/* + * match_uint - scan a decimal representation of an integer from a substring_t + * @s: substring_t to be scanned + * @result: resulting integer on success + * + * Description: Attempts to parse the &substring_t @s as a decimal integer. On + * success, sets @result to the integer represented by the string and returns 0. + * Returns -ENOMEM, -EINVAL, or -ERANGE on failure. + */ +int match_uint(substring_t *s, unsigned int *result) +{ + int err = -ENOMEM; + char *buf = match_strdup(s); + + if (buf) { + err = kstrtouint(buf, 10, result); + kfree(buf); + } + return err; +} +EXPORT_SYMBOL(match_uint); + /** * match_u64: - scan a decimal representation of a u64 from * a substring_t -- 2.7.4