From patchwork Wed Nov 20 10:51:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: guanjing X-Patchwork-Id: 13881015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D395D63926 for ; Wed, 20 Nov 2024 10:52:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2284E6B0083; Wed, 20 Nov 2024 05:52:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B1C76B0089; Wed, 20 Nov 2024 05:52:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02C756B008A; Wed, 20 Nov 2024 05:52:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D009F6B0083 for ; Wed, 20 Nov 2024 05:52:31 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8AED340A49 for ; Wed, 20 Nov 2024 10:52:31 +0000 (UTC) X-FDA: 82806158526.05.F80A621 Received: from cmccmta1.chinamobile.com (cmccmta4.chinamobile.com [111.22.67.137]) by imf19.hostedemail.com (Postfix) with ESMTP id 036CD1A000C for ; Wed, 20 Nov 2024 10:51:23 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.hostedemail.com: domain of guanjing@cmss.chinamobile.com designates 111.22.67.137 as permitted sender) smtp.mailfrom=guanjing@cmss.chinamobile.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732099764; a=rsa-sha256; cv=none; b=jGsdYL4j4nB+/ueYk40r7BZpu2UHw6WPprEKKXAvyAktBjBKucURU7QQnw9sqUYxZ4LrIa 1MIZ5KFoKDd9/nCRKAIK+ilJxnaGKx69t0MZZgDD0fHibNU8P6v1oFN9bmkGv60+hvscT4 Ze7uGDhhwnOGUmrqKTXnoYMJfLpvxNU= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.hostedemail.com: domain of guanjing@cmss.chinamobile.com designates 111.22.67.137 as permitted sender) smtp.mailfrom=guanjing@cmss.chinamobile.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732099764; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=3x7rlh3cC/r+6we4a15WRQNj05etGc+gfVS6og/hANQ=; b=Apd39+XTuanx32xIR6Z39ohAvzcR1MsVn/w0PY6NGNx/UKGTnKf8xip2JK/EyxnJg1mJQk /hvLr7Nzeu9Nc1dUj+O/FbCBWEbveFYAJP7QVs3lrXwac2jwsTkj6BY8JzMj1vwuU4jnSF tvu5rjz4+odvJrox9CRiXr9Dx3qdttA= X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from spf.mail.chinamobile.com (unknown[10.188.0.87]) by rmmx-syy-dmz-app04-12004 (RichMail) with SMTP id 2ee4673dbf68fc3-268cd; Wed, 20 Nov 2024 18:52:25 +0800 (CST) X-RM-TRANSID: 2ee4673dbf68fc3-268cd X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from localhost.localdomain (unknown[223.108.79.101]) by rmsmtp-syy-appsvr09-12009 (RichMail) with SMTP id 2ee9673dbf5635b-7f187; Wed, 20 Nov 2024 18:52:25 +0800 (CST) X-RM-TRANSID: 2ee9673dbf5635b-7f187 From: guanjing To: krisman@kernel.org, hughd@google.com, akpm@linux-foundation.org, andrealmeid@igalia.com, brauner@kernel.org, tytso@mit.edu Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, guanjing Subject: [PATCH v1] tmpfs: Unsigned expression compared with zero Date: Wed, 20 Nov 2024 18:51:50 +0800 Message-Id: <20241120105150.24008-1-guanjing@cmss.chinamobile.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Stat-Signature: s8hpao4qzhsyy5mkzowp46sngu6i64ah X-Rspamd-Queue-Id: 036CD1A000C X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1732099883-151690 X-HE-Meta: U2FsdGVkX189Lh8RJ/ysJ3z91Eii6ecUoQHqaXbb4nMyweoruqjbtDLPX46RNHql6uQuUumpHD5VX5bj8Jf3+PFN0VRV0MZHngezAvA37wYDjmcoZ9IClcnh0QqmWpSwFBddz3qSr643daNx7PxSvJGv1GdmQgd+CDab3LoJ3emJz2xSAUzVho1MEwU7EX08iUyLQiLqSS3zQ6MHgN290heWqIVM3FDPu6oguFI5hNk8xmRPK3L6vGTYECKFi9saxdYC4i9CL7oATEuF1PWbDLgyhBzvTJfsz6GudiMcqUZPvywTd6QjyoH7SmcDD+kBaLN3KPgSkQfTXy0Wsgk4pHMk0F23kb+xUBwhcf8/BjZs2DdRg/IJSWiQe3dVPCplDqpcOPXkMuDRjVkH667ixppfgbC7tKi6mYzJRZ4ME+0f/1hcLC41T3o5F42qIJDlxHpPT5cj+ztYQ/DbO8P5aIHWl9+osLKfKdK/p1mIZ8ckQZVyMRckbQ7TPfc260SLaldTB4B4y2I07D7kUpXQup/UzUBL9BCXr8hYyCHFhJmlwodnoj2aRoBbUBLQl0QJDzTXRm5QPxgbvu+dplY+pxqEriDpUf4zIensS+aC9Pkc0RN+yNZAIJYUCF9a4d2hQz5EQuTu9DlUDU507noowIs4pJDD37nOks07S64caFnmN0HWizLQnXxQy/JoSzphFtVmJZfYIurLkHzzkpH5TIQoqTaQpHiD0do1RiGR7bLYVWG9kxB88jpiM7lNSCOZKJOhw/rLY6qiZlsXGCVQjUEQMkibS7OlM8vEfJwdE1E3XH3vvleb8DswWmPlbetGSCdJFUHw34kE7R/GHe2RnOkY3kmzcjdgpPAzh0zjvPtqMVnELZZAUC1PBU+2vgfk3FBfUONX0UcI5/S1BuOjUSX4MQD3lxAo8WWUGdoAReQz5FsHNfCxUqv27xfLy1IBVmmJvruVk46X35oO/4F 551u11ny z33nacscy8SyxWp5meMN/qtozidEeQosv52P1IOSJD0SeT2Y1K/4zLJkMtxqic+QgYPPj X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The return value from the call to utf8_parse_version() is not of the unsigned type. However, the return value is being assigned to an unsigned int variable 'version'. This will result in the inability to handle errors that occur when parsing a UTF-8 version number from a string. Additionally, this patch can help eliminate the following Coccicheck warning: mm/shmem.c:4378:6-13: WARNING: Unsigned expression compared with zero: version < 0 Fixes: 58e55efd6c72 ("tmpfs: Add casefold lookup support") Signed-off-by: guanjing --- fs/unicode/utf8-core.c | 9 +++++---- include/linux/unicode.h | 2 +- mm/shmem.c | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/fs/unicode/utf8-core.c b/fs/unicode/utf8-core.c index 6fc9ab8667e6..c54dc7ac5ce6 100644 --- a/fs/unicode/utf8-core.c +++ b/fs/unicode/utf8-core.c @@ -219,9 +219,9 @@ EXPORT_SYMBOL(utf8_unload); * * @version: input string * - * Returns the parsed version on success, negative code on error + * Returns 0 on success, negative code on error */ -int utf8_parse_version(char *version) +int utf8_parse_version(char *version_str, unsigned int *version) { substring_t args[3]; unsigned int maj, min, rev; @@ -230,13 +230,14 @@ int utf8_parse_version(char *version) {0, NULL} }; - if (match_token(version, token, args) != 1) + if (match_token(version_str, token, args) != 1) return -EINVAL; if (match_int(&args[0], &maj) || match_int(&args[1], &min) || match_int(&args[2], &rev)) return -EINVAL; - return UNICODE_AGE(maj, min, rev); + *version = UNICODE_AGE(maj, min, rev); + return 0; } EXPORT_SYMBOL(utf8_parse_version); diff --git a/include/linux/unicode.h b/include/linux/unicode.h index 5e6b212a2aed..7de545bc66cb 100644 --- a/include/linux/unicode.h +++ b/include/linux/unicode.h @@ -78,6 +78,6 @@ int utf8_casefold_hash(const struct unicode_map *um, const void *salt, struct unicode_map *utf8_load(unsigned int version); void utf8_unload(struct unicode_map *um); -int utf8_parse_version(char *version); +int utf8_parse_version(char *version_str, unsigned int *version); #endif /* _LINUX_UNICODE_H */ diff --git a/mm/shmem.c b/mm/shmem.c index ccb9629a0f70..7d07f649a8df 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4368,14 +4368,15 @@ static int shmem_parse_opt_casefold(struct fs_context *fc, struct fs_parameter * unsigned int version = UTF8_LATEST; struct unicode_map *encoding; char *version_str = param->string + 5; + int ret; if (!latest_version) { if (strncmp(param->string, "utf8-", 5)) return invalfc(fc, "Only UTF-8 encodings are supported " "in the format: utf8-"); - version = utf8_parse_version(version_str); - if (version < 0) + ret = utf8_parse_version(version_str, &version); + if (ret < 0) return invalfc(fc, "Invalid UTF-8 version: %s", version_str); }