From patchwork Thu Dec 5 09:45:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weikang Guo X-Patchwork-Id: 13894921 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 22888E7716C for ; Thu, 5 Dec 2024 09:45:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E2376B007B; Thu, 5 Dec 2024 04:45:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 793536B0082; Thu, 5 Dec 2024 04:45:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 659B26B0083; Thu, 5 Dec 2024 04:45:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 496F36B007B for ; Thu, 5 Dec 2024 04:45:54 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E451C1A13EB for ; Thu, 5 Dec 2024 09:45:53 +0000 (UTC) X-FDA: 82860423282.21.20420B5 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf04.hostedemail.com (Postfix) with ESMTP id 508654001B for ; Thu, 5 Dec 2024 09:45:35 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=M3ZmU7I+; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of guoweikang.kernel@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=guoweikang.kernel@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733391945; a=rsa-sha256; cv=none; b=HORYGCKE9vJcJ5qQAaEyc3qjQfMrVwJTGDpu0jKrZDSJlHMrLz4XzocmTLwjF+njjBCToo wvszwpPR6qQTBzkcbp49qG9TAafua/8tIIXu9uAhLq1Fyhiq8tsNV2oHvPWkaXOu4g6XfP XoYiiZt9wGXn+KWXmt8iChdrkALtw5Y= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=M3ZmU7I+; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of guoweikang.kernel@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=guoweikang.kernel@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733391945; 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:dkim-signature; bh=sSCTRtTZFzC38u5ELH86ExDbi7PEAa9+kuBPOpVRQXg=; b=k8R1dA85HfK9PjQ1x+QoL2aoQjk38crrgi/LnAK2X2XOQls5LKLyLvG3iFG5yDMODkorxM L8yRr3e3q4H7lkudck7UQVYVxdtDt+eJNO+X2KU1MIrZ47utYVhN/5q604TDfTJKvjwVuk VcAYPVS4Pv63TsmomYiRNzw62FcW6jw= Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7fd20129dceso81299a12.2 for ; Thu, 05 Dec 2024 01:45:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733391951; x=1733996751; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=sSCTRtTZFzC38u5ELH86ExDbi7PEAa9+kuBPOpVRQXg=; b=M3ZmU7I+8U0wdzFwhnNMDpdMrTXty1pK6eaiFE6yrTjTL9i69iIJjp9+cWQ7PQu7p6 4MLTYfgpCTY0JVXv9UWLlHezaIGkgskAJDOqxf3k9fJchX1gaAlsikyli/khOaxabEwm X6kOKHPruwh4ADS+OXLwMTAatv3Ewyi7wNnOxo2dbutouS5cnevKC4NeU8E4Z7klVf6w 87n5tn7yBLuQl/7KbTH3tw6PM5dl9phiOFbBTzoC8SYTsxyrXflc1gczBAaW1Dn2ht5B SfcEf9xcnd38lU88zHK5Ou3fEkf0Rvd6mpzixbguzpoGrOQLYYPUsQbYHl4vsWvoyLyi 5YFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733391951; x=1733996751; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sSCTRtTZFzC38u5ELH86ExDbi7PEAa9+kuBPOpVRQXg=; b=JRDl3nh9WephqtywIBlqICjaJj7ncXlAGjiGQudc9pNCYFXtryS9AZV2QqtFFc9wE4 izOMaSg5Kwo9tcNlYGj+05HUH1m9l9+KKFJ0E8kF1VbZIdGh2BgGpSEU25+SFUTCmgsy CQaDalOWk4+f/OIDGnbcTBFVl7LTAigRDeY8wJe4QkeOJsyh5NALTdwnfWCWzoIhHlAr cvUjs29P8vBPPBRwZJVZJkbK8ddMDpV/9GOLkSSVdm6Zoo7rdUixzEif9P2vkKglfkPt DFdlzLszL90+tNrZB5vd85r5RpcuFDvjFn4823pm+LNy32rZHyc9RTNeubjSNIwR5VbP zaDQ== X-Forwarded-Encrypted: i=1; AJvYcCV/umfW4ykQSoSwyHwgiQNqIGCXYQm9htAf8veVHadKc4DbbHNghCMdEU99J/BLRMOmDuAe/OJ2AQ==@kvack.org X-Gm-Message-State: AOJu0YxXTEyFZBBA4wFZ9tOe0k049QJfsWaQx8JG1SxQETTqon5tTQpu NFtyTnifmsEmBsSqZB9isVz57jRKGEOSD3FdlEjFj2Lkfml3ZxId X-Gm-Gg: ASbGnctozvlnsZNDb6Nibqeows1fDs76ykon3O6qc2XwAOSYnOfsxbfZozog4ABXFtO mMXiKgorQXTFmMvX2tWJeGRV/u9iaduFHKzPfw06DYEP4rAHQLONReRUeK9DwDRkqpW4WAFoI2J sMBlxU7/hkiv6a3YHO/hpb2Va8zCFf7PTzU2XREwdO3mC5qs6QTW3IcVSQ8jEoqN3fh/2i+HXGH yKsOfd5aUP/GgrztUN69TZDKb1hZl0fhCEmxoyOo/ZfXT7oUd/yF+Fc0HolnHjhy3gwLRLZAA== X-Google-Smtp-Source: AGHT+IEdC91bc1pFn/Lu1UYwciLcGwDw8pC1DZiNh/OvhZTcQykXZV+bgtvqpQ9MycoZffLtElbsiw== X-Received: by 2002:a05:6a20:430b:b0:1d9:c78f:4207 with SMTP id adf61e73a8af0-1e1653b7c9amr13021353637.11.1733391950622; Thu, 05 Dec 2024 01:45:50 -0800 (PST) Received: from localhost.localdomain ([36.110.106.149]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725a2a90542sm889686b3a.106.2024.12.05.01.45.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 01:45:50 -0800 (PST) From: Guo Weikang To: amir73il@gmail.com, Hugh Dickins , Andrew Morton Cc: Guo Weikang , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/shmem: Refactor to reuse vfs_parse_monolithic_sep for option parsing Date: Thu, 5 Dec 2024 17:45:21 +0800 Message-Id: <20241205094521.1244678-1-guoweikang.kernel@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 508654001B X-Stat-Signature: z4697bdsfq97iizw5oi7b5xkw5iwsnd1 X-HE-Tag: 1733391935-166972 X-HE-Meta: U2FsdGVkX19x4hxB4BSxw/thzn4UMYeUlmjhLI+OnfKfmFvkBqFLIwLYLzRCotUWmHFXl+Cz5afGtZtli/Ph5ILU3aRqyKi+yvAFVO6sjAzGg5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UVO6k0bSzYjI8tqOMoCrsJXSOmT5DJiX7MWoIQYqvAQ9XQl+V1hLZaPhPJLMJGXgj7B9YC2wMMs3vCr6YLNSq8gO1q9BfVbseWmjJTlr7f3FIEvXmTkbIlWRqhPdFqju5FIBYJdneyCSLjyjH58igaofyhTr0xzyYfc6BXDJQXy93yU6rcC+wvo9ZFWSBdxxuEZGbQeMkQQwfaN9VKuZFiH5ywYYDBt6GgLn5CA64zQehFo5/jv1uGKFwpwzVaizT6mNmkl6rQTtwTqihM4spG3YkTu+BVMEqQOchEbcGDD0kUsrMIU8udKBsMfigZvo= 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 `shmem_parse_options` function is refactored to use `vfs_parse_monolithic_sep` with a custom separator function, `shmem_next_opt`. This eliminates redundant logic for parsing comma-separated options and ensures consistency with other kernel code that uses the same interface. The `vfs_parse_monolithic_sep()` helper, introduced in commit e001d1447cd4 ("fs: factor out vfs_parse_monolithic_sep() helper"). Signed-off-by: Guo Weikang --- mm/shmem.c | 65 +++++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index d23602a33f31..c9c5862848e6 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4646,48 +4646,37 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) return invalfc(fc, "Bad value for '%s'", param->key); } -static int shmem_parse_options(struct fs_context *fc, void *data) +static char *shmem_next_opt(char **s) { - char *options = data; + char *sbegin = *s; + char *p; - if (options) { - int err = security_sb_eat_lsm_opts(options, &fc->security); - if (err) - return err; - } + if (sbegin == NULL) + return NULL; - while (options != NULL) { - char *this_char = options; - for (;;) { - /* - * NUL-terminate this option: unfortunately, - * mount options form a comma-separated list, - * but mpol's nodelist may also contain commas. - */ - options = strchr(options, ','); - if (options == NULL) - break; - options++; - if (!isdigit(*options)) { - options[-1] = '\0'; - break; - } - } - if (*this_char) { - char *value = strchr(this_char, '='); - size_t len = 0; - int err; - - if (value) { - *value++ = '\0'; - len = strlen(value); - } - err = vfs_parse_fs_string(fc, this_char, value, len); - if (err < 0) - return err; + /* + * NUL-terminate this option: unfortunately, + * mount options form a comma-separated list, + * but mpol's nodelist may also contain commas. + */ + for (;;) { + p = strchr(*s, ','); + if (p == NULL) + break; + *s = p + 1; + if (!isdigit(*(p+1))) { + *p = '\0'; + return sbegin; } } - return 0; + + *s = NULL; + return sbegin; +} + +static int shmem_parse_monolithic(struct fs_context *fc, void *data) +{ + return vfs_parse_monolithic_sep(fc, data, shmem_next_opt); } /* @@ -5037,7 +5026,7 @@ static const struct fs_context_operations shmem_fs_context_ops = { .free = shmem_free_fc, .get_tree = shmem_get_tree, #ifdef CONFIG_TMPFS - .parse_monolithic = shmem_parse_options, + .parse_monolithic = shmem_parse_monolithic, .parse_param = shmem_parse_one, .reconfigure = shmem_reconfigure, #endif