Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1314065rdb; Sat, 23 Dec 2023 01:59:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1RMu2cwEakMGsSpteKDLA5qarfU8R+5/Sf9OuU8ZK/OBFuQORIJiIGz1XrKABgQUr0nVu X-Received: by 2002:a05:6a21:3397:b0:18b:f90d:9d84 with SMTP id yy23-20020a056a21339700b0018bf90d9d84mr3256578pzb.54.1703325586370; Sat, 23 Dec 2023 01:59:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703325586; cv=none; d=google.com; s=arc-20160816; b=qPm9YfJGVmm6h7vRWKgY7xslG/f2NZTqiya1X3OOzRQkG/Or9QTWINazI1RObCqL4y SpDt5GEG8Zl923eeCwh8OsxortQ30KFhehk1QawjoybpaLfs0338jKeklQ0kf+sD/PHe QqrQ5KAIw+xHnSgBzuVXKMsg5f3D4ghb0ieA9jES84Ubhh9BcrN16Lds+9YFNN5U4E/e Z3OR/A0YUfRMQ7UGEwMmrEQOXVCsSxNU2Vhl1/aOYFBlFXOfYoVNxhvon8R49MYTBdgl lokatbQObkU5fEUzTQqLNfP7nW868DbVP85wN4L7f56drxl8VzP0E42rkRKn9TNJfTS4 /ckQ== 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=Mu2YVbnchgZ4Y9RHvJToIjCQwioq6Ym5s/G+NLbihEc=; fh=aq23pSLwbr03HoKdXnGr0/uCxlT9OZ+QQ/0yofwyUC8=; b=RH7ysDZSW1SRY6cGOl204PLmRwXT4kMua5O8trK2OeXOF/Iiu4QIWwbAKH48EOEN4u oEMr58nKc5TPr+MR/hz/+kkYEa0AXdPnIfMiUF84X8MlVe/c3LMEVGRP9GP3osW+fLjf 8L6LBUWAUVzz+utvA6lJme+5MEGXFndXL4VYAkQ0gZGXnJ5MswNSDGvkWIm31A/n46YC ms1fgeTMXHNWb/oFxYKrhnrpq1CYYn1cVqegCF+LMR4vqBNxNGf3onB58tSWEQLjZWuk EyWCK3d0i6ujNS0fTrHUlB/XjE3u23BidP0HyuOlWjdDqhVRRTQBoGTDXI534RRk6FtL 2a1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=a3b4Lo+A; dkim=pass header.i=@suse.com header.s=susede1 header.b=a3b4Lo+A; spf=pass (google.com: domain of linux-kernel+bounces-10372-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10372-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l30-20020a63571e000000b00577475ee5f6si4672775pgb.618.2023.12.23.01.59.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Dec 2023 01:59:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10372-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=a3b4Lo+A; dkim=pass header.i=@suse.com header.s=susede1 header.b=a3b4Lo+A; spf=pass (google.com: domain of linux-kernel+bounces-10372-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10372-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 44016284282 for ; Sat, 23 Dec 2023 09:59:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4200FDF6C; Sat, 23 Dec 2023 09:58:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="a3b4Lo+A"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="a3b4Lo+A" 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 E0C6BDDC2; Sat, 23 Dec 2023 09:58:48 +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 26FA81FD3C; Sat, 23 Dec 2023 09:58:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1703325527; 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=Mu2YVbnchgZ4Y9RHvJToIjCQwioq6Ym5s/G+NLbihEc=; b=a3b4Lo+AzQzJk2ptQoP4ZuFzGlrViiy1CGi27Hni8jQa+AOC2r/Cc+uogcKK+HDlSvAlQO dGdrGwl1dMq8bmNwfmRqAsWF9eTp+3MpA5KBiighYWuIaURyZ31QBQacTpL9L/VMBirLuC dm0cyUIasWHcQGPvuhi5ElDD1/zjD+s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1703325527; 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=Mu2YVbnchgZ4Y9RHvJToIjCQwioq6Ym5s/G+NLbihEc=; b=a3b4Lo+AzQzJk2ptQoP4ZuFzGlrViiy1CGi27Hni8jQa+AOC2r/Cc+uogcKK+HDlSvAlQO dGdrGwl1dMq8bmNwfmRqAsWF9eTp+3MpA5KBiighYWuIaURyZ31QBQacTpL9L/VMBirLuC dm0cyUIasWHcQGPvuhi5ElDD1/zjD+s= 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 8805C1392C; Sat, 23 Dec 2023 09:58:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id eACRClOvhmXmcgAAD6G6ig (envelope-from ); Sat, 23 Dec 2023 09:58:43 +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 Subject: [PATCH 3/3] btrfs: migrate to the newer memparse_safe() helper Date: Sat, 23 Dec 2023 20:28:07 +1030 Message-ID: <6dfa53ded887caa2269c1beeaedcff086342339a.1703324146.git.wqu@suse.com> 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 Content-Transfer-Encoding: 8bit X-Spam-Score: 1.90 X-Spamd-Result: default: False [1.90 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_DN_NONE(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; RCPT_COUNT_SEVEN(0.00)[7]; FREEMAIL_TO(0.00)[vger.kernel.org,linux-foundation.org,wanadoo.fr,linux.intel.com,ACULAB.COM,suse.de]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[wanadoo.fr]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: * X-Spam-Flag: NO 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 --- fs/btrfs/ioctl.c | 8 ++++++-- fs/btrfs/super.c | 8 ++++++++ fs/btrfs/sysfs.c | 14 +++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 4e50b62db2a8..8bfd4b4ccf02 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1175,8 +1175,12 @@ static noinline int btrfs_ioctl_resize(struct file *file, mod = 1; sizestr++; } - new_size = memparse(sizestr, &retptr); - if (*retptr != '\0' || new_size == 0) { + + ret = memparse_safe(sizestr, MEMPARSE_SUFFIXES_DEFAULT, + &new_size, &retptr); + if (ret < 0) + goto out_finish; + if (*retptr != '\0') { ret = -EINVAL; goto out_finish; } diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 3a677b808f0f..2bb6ea525e89 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -400,6 +400,14 @@ 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: + int ret; + + 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; + } ctx->max_inline = memparse(param->string, NULL); break; case Opt_acl: 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) -- 2.43.0