From patchwork Wed Jan 3 23:27:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 184873 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5319635dyb; Wed, 3 Jan 2024 15:29:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3hQThWQPb7n6YDaTvFUMuV3DfrISRvO0GOGr/iatmXFIhsoHeQtHi8d3AArBntbSRMCIQ X-Received: by 2002:a05:620a:1a89:b0:77d:9d58:5467 with SMTP id bl9-20020a05620a1a8900b0077d9d585467mr24745694qkb.29.1704324595390; Wed, 03 Jan 2024 15:29:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704324595; cv=none; d=google.com; s=arc-20160816; b=Q0WdbVMEmZgz3CmAzGPwoYtEHwRZVX1rvmAdsI3oLGfKYo55Q3CvEXIsJbWwChkKxD /ozP28S6qzzajQnu2usiM5ZSolK2HuCi3nthBR9Tvgxm+11PQAHhdy9x33LJX2ULTTMo K87dEmgyad3cHO8wOxUHA6JKMQGNC05PbauoO84OkA90fo0SdsfjUvhNQUF5eV1TYIVg kD8N4luZVxaZEpLVH8jLbd4u10aP+cg5AUSbV5brTVG1zmeUiBFJOBuK2Ix/KFvs8kzV HmLeUkq/JeEJU4VWMDds+nwqrJYuJ0DeDRSMf611KABCr9JP8h9CMEii481PTzFErFir eztg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature:dkim-signature; bh=1VzFgHrE0lFC+VNDDj8M8pUUWESRusrMT1ddLdCqdXU=; fh=5WEccoI3MXPoqgQkOYurL1AQ0GZs+h36FarqzwkCNds=; b=UrqOd0VP8NMDEXK3ABGWcT7Rk3xuEO/wE/pUNTsOzr42KSmQMAM/EcB5ZBatkxtVr7 cho76xs146V5oT6r5xBf6j3kBAxHd9NjRfrJmiG3ij7FDGhLQKW6/bi0uLSOgXp+H2r2 azHChTZprE/lDifTb2JNfQhXSA9fdEf9dC3lcWiQEYsPfsbE7o9d/48ZIZf+7BADBvIN 2piPlnIWyqBHq4A9YXYuF2Qnu5kfmZQ8T144XHDoKwKj+HStBKYT3bLhnen/QaBM0cA5 xSibz0EW+2epPbpkcj6pVT/xCbco99K8EdGUSxhhbqtJRKKANvXsu1UIX8NXn73VVTlB r1EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=iA7DfiSb; dkim=pass header.i=@suse.com header.s=susede1 header.b=iA7DfiSb; spf=pass (google.com: domain of linux-kernel+bounces-16119-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16119-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c18-20020a37e112000000b0077d98a59c9bsi28168889qkm.440.2024.01.03.15.29.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 15:29:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16119-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=iA7DfiSb; dkim=pass header.i=@suse.com header.s=susede1 header.b=iA7DfiSb; spf=pass (google.com: domain of linux-kernel+bounces-16119-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16119-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6FFC31C249DF for ; Wed, 3 Jan 2024 23:29:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF3FA20B09; Wed, 3 Jan 2024 23:28:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="iA7DfiSb"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="iA7DfiSb" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F806208DA; Wed, 3 Jan 2024 23:28:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BE9E81F7D1; Wed, 3 Jan 2024 23:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1704324513; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1VzFgHrE0lFC+VNDDj8M8pUUWESRusrMT1ddLdCqdXU=; b=iA7DfiSbWuoqRI5TWOUFau6fl2Av6d4rlxS18czGmXygf2JiWqTLpUX0zMfjvHGxXWafnA 5igBLXuHcaGK6XTrgJYXCAvh3BIAWNSn7UGa1AgCL0eD2Hb4A6VLW8oMdB4/SvkkJa6bx7 MLnd/qJWxNX8INbpyA1IlAtra82H82A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1704324513; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1VzFgHrE0lFC+VNDDj8M8pUUWESRusrMT1ddLdCqdXU=; b=iA7DfiSbWuoqRI5TWOUFau6fl2Av6d4rlxS18czGmXygf2JiWqTLpUX0zMfjvHGxXWafnA 5igBLXuHcaGK6XTrgJYXCAvh3BIAWNSn7UGa1AgCL0eD2Hb4A6VLW8oMdB4/SvkkJa6bx7 MLnd/qJWxNX8INbpyA1IlAtra82H82A= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 88D031398A; Wed, 3 Jan 2024 23:28:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id 8G8ZCZ3tlWWXTgAAD6G6ig (envelope-from ); Wed, 03 Jan 2024 23:28:29 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, christophe.jaillet@wanadoo.fr, andriy.shevchenko@linux.intel.com, David.Laight@ACULAB.COM, ddiss@suse.de, geert@linux-m68k.org Subject: [PATCH v3 4/4] btrfs: migrate to the newer memparse_safe() helper Date: Thu, 4 Jan 2024 09:57:51 +1030 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: ***** X-Spam-Score: 5.34 X-Spamd-Result: default: False [5.34 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[wanadoo.fr]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.06)[-0.293]; NEURAL_SPAM_LONG(3.50)[1.000]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.de:email]; FREEMAIL_TO(0.00)[vger.kernel.org,linux-foundation.org,wanadoo.fr,linux.intel.com,ACULAB.COM,suse.de,linux-m68k.org]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787113866872961800 X-GMAIL-MSGID: 1787113866872961800 The new helper has better error report and correct overflow detection, furthermore the old @retptr behavior is also kept, thus there should be no behavior change. Signed-off-by: Qu Wenruo Reviewed-by: David Disseldorp --- fs/btrfs/ioctl.c | 6 +++++- fs/btrfs/super.c | 9 ++++++++- fs/btrfs/sysfs.c | 14 +++++++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 4e50b62db2a8..cb63f50a2078 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1175,7 +1175,11 @@ static noinline int btrfs_ioctl_resize(struct file *file, mod = 1; sizestr++; } - new_size = memparse(sizestr, &retptr); + + ret = memparse_safe(sizestr, MEMPARSE_SUFFIXES_DEFAULT, + &new_size, &retptr); + if (ret < 0) + goto out_finish; if (*retptr != '\0' || new_size == 0) { ret = -EINVAL; goto out_finish; diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 3a677b808f0f..0f29fd692e0f 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -263,6 +263,8 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param) { struct btrfs_fs_context *ctx = fc->fs_private; struct fs_parse_result result; + /* Only for memparse_safe() caller. */ + int ret; int opt; opt = fs_parse(fc, btrfs_fs_parameters, param, &result); @@ -400,7 +402,12 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param) ctx->thread_pool_size = result.uint_32; break; case Opt_max_inline: - ctx->max_inline = memparse(param->string, NULL); + ret = memparse_safe(param->string, MEMPARSE_SUFFIXES_DEFAULT, + &ctx->max_inline, NULL); + if (ret < 0) { + btrfs_err(NULL, "invalid string \"%s\"", param->string); + return ret; + } break; case Opt_acl: if (result.negated) { diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 84c05246ffd8..6846572496a6 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -762,6 +762,7 @@ static ssize_t btrfs_chunk_size_store(struct kobject *kobj, struct btrfs_fs_info *fs_info = to_fs_info(get_btrfs_kobj(kobj)); char *retptr; u64 val; + int ret; if (!capable(CAP_SYS_ADMIN)) return -EPERM; @@ -776,7 +777,10 @@ static ssize_t btrfs_chunk_size_store(struct kobject *kobj, if (space_info->flags & BTRFS_BLOCK_GROUP_SYSTEM) return -EPERM; - val = memparse(buf, &retptr); + ret = memparse_safe(buf, MEMPARSE_SUFFIXES_DEFAULT, &val, &retptr); + if (ret < 0) + return ret; + /* There could be trailing '\n', also catch any typos after the value */ retptr = skip_spaces(retptr); if (*retptr != 0 || val == 0) @@ -1779,10 +1783,14 @@ static ssize_t btrfs_devinfo_scrub_speed_max_store(struct kobject *kobj, { struct btrfs_device *device = container_of(kobj, struct btrfs_device, devid_kobj); - char *endptr; unsigned long long limit; + char *endptr; + int ret; + + ret = memparse_safe(buf, MEMPARSE_SUFFIXES_DEFAULT, &limit, &endptr); + if (ret < 0) + return ret; - limit = memparse(buf, &endptr); /* There could be trailing '\n', also catch any typos after the value. */ endptr = skip_spaces(endptr); if (*endptr != 0)