From patchwork Mon Feb 12 16:08:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 199880 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp14704dyb; Mon, 12 Feb 2024 08:08:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWDL00V8FYlAb8dzhNsE7BWttAVoNcjqy1P8FK7OCdhgdDpAwQeLz7mU5poBXyzfWDEe7UvaCv+KVzD4oo8th4CBB2O6Q== X-Google-Smtp-Source: AGHT+IEehcT4XdTRPBExdGgvogfM4pYHhjo65HUrSthhHk/yln8aKclrYR/tAsOVeFV0mNgThIQl X-Received: by 2002:a05:620a:20ca:b0:785:8c17:dfa1 with SMTP id f10-20020a05620a20ca00b007858c17dfa1mr8026317qka.61.1707754121794; Mon, 12 Feb 2024 08:08:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707754121; cv=pass; d=google.com; s=arc-20160816; b=W1OZXjQBFxdTkEeFd0kLckO4Cvd8WDhn9DEjmVCeYm8x9owo2KSgIcRkWXZGTYbW7m Sjp5T97TGmkQoUHk7L/EDs1btlA/o/we+bLAKAzuNpL8ROiJ3ABod4z1pausUOgYioQh 0ZX+JBdHnasE2GY+6f/aeVgJK6zCnGLSe5oTAXVO84MMjENVg2uzox03zzNFXJGnXfgY 6zUgJQGOULUCousJ6zCbH/xGV3QpUDEWGKH6/WOExEQqAyJ934GvcyfNRTSY6EwCiW1o FxSnSZ66fMP0rLvFDesQKGqjqtgvLEL+XXtNxwH5qY94xE0C4xEsIlz9ZaCXoXcBTDqE TzyA== ARC-Message-Signature: i=2; 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:message-id:date:subject:cc:to :from:dkim-signature; bh=/2InhzdCdbdALy1oJYLX4A2t+MNMq246GQ8Jswg6qq4=; fh=vElnJGoLz7NzHL20f3qrOWbcMXUTSusUywxHZIdxbaM=; b=mUl4oMN8vOAZCngfuXgK8GZ0L/k9Xluh39KPbWX0YUyjtyekgYuWBf35lvwRWJ1gCS H+Qt728cWQxsAzedhkiai8wnusJVMH4Iem+vp94s9D/LxWHo8542anUdeLk/yDSCII6M Lk2/7eNPPxWXwfTgxSZBEoEaWOhIHbKC5bSQFZ1L943VHBZpbDQHyVVt+Q9CaC45iU2c smeBChfCE70FcOYAOSezo7YUivVitGbAyJdgFCRimTzhP/WpXJswmB7UM5axR0RU9ps+ rAdKnY0fz8x7gRI09aMzSTCLq1F6aua4zlRaP2lXH5n3gwm3+ylHpxITeurEGQGNeExM ptdA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y2cu4EFD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-61937-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61937-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCUzdywFyQg5d11RmxDWM4C+OoMzRlp695//OPp35518LBJR905DseLV38mGV7S0fUgagttpD7uG9HGadC3gtnJ3tVUTng== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h2-20020a05620a244200b00785c8ba81d6si5655145qkn.728.2024.02.12.08.08.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 08:08:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61937-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y2cu4EFD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-61937-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61937-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 9182C1C21AB6 for ; Mon, 12 Feb 2024 16:08:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D698B3D0CF; Mon, 12 Feb 2024 16:08:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Y2cu4EFD" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31C853D0A9 for ; Mon, 12 Feb 2024 16:08:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707754107; cv=none; b=qXePAiaR2WEC0D1NGP9A2A2Se1IA3P4c2GOojGVlPCSFtmS7KS6Jr0ktPupwNmVI6eGpyB+ePSkniKdXWu79yFBGFAE0Uf0ndvtjIWwgmxx1WeL8Lt5G5T9gJTLLMBdiblJfo4WQrb2Wg61lUsOezozYg5vF6IB01i3TxZA2tgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707754107; c=relaxed/simple; bh=Ms3jETJiDb4EcBDYV1Y+i+GWoHhcisMI0xE0j1gpI2U=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=qEl6lgIbisSlfx4WYVTes1dNxmnOjhGPmBG84QnVR/Qe8F4nbycD9xPGSujYJprh+3NnwUyaTvkI4gQXHBxGH4IwgPdZmmLcJwBbPKPHmgQfGZUqShlCk86/SldSYXFd4fERF6x5PH2N2c8ilsHyCK1A6DG/GUQddTvbOv93WoE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Y2cu4EFD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FDACC433F1; Mon, 12 Feb 2024 16:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707754105; bh=Ms3jETJiDb4EcBDYV1Y+i+GWoHhcisMI0xE0j1gpI2U=; h=From:To:Cc:Subject:Date:From; b=Y2cu4EFD9qnbjoBlUafM0p11mG6L9waqaPUOVxb3yX9hTK5vzLE9F8XWhDI6IcLmg Tp4nhkaXMZnGfzGPa3ksH8oosIPoxTCPn9h0P1mQ38KhCX7faXRb+3ZGdm3ck0jmLN 5+8rkiYhkXB4jgwbr0iq5ni1uful1cNP/MKAi8vZFSBGPs6kw8uY+BQhYWHQ2rt217 RMs8GsQDU/BM2pcdXtCyJeBym5B/Zd60gUBjLWDLJayQD6E02/ahNkwrPnaS/W57fE 4/wjDkVOivyTfojCafXj/cFOs2MfI4qIw69QFGMs6+Jn7t+xOp8ncAiQACXa+6laJK zhskNU2ffhURg== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH] f2fs: compress: fix to check zstd compress level correctly in mount option Date: Tue, 13 Feb 2024 00:08:18 +0800 Message-Id: <20240212160818.1020903-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790709986417329714 X-GMAIL-MSGID: 1790709986417329714 f2fs only support to config zstd compress level w/ a positive number due to layout design, but since commit e0c1b49f5b67 ("lib: zstd: Upgrade to latest upstream zstd version 1.4.10"), zstd supports negative compress level, so that zstd_min_clevel() may return a negative number, then w/ below mount option, .compress_level can be configed w/ a negative number, which is not allowed to f2fs, let's add check condition to avoid it. mount -o compress_algorithm=zstd:4294967295 /dev/sdx /mnt/f2fs Fixes: 00e120b5e4b5 ("f2fs: assign default compression level") Signed-off-by: Chao Yu --- fs/f2fs/super.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 1b718bebfaa1..a29b8e25a2ed 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -669,7 +669,7 @@ static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str) #ifdef CONFIG_F2FS_FS_ZSTD static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str) { - unsigned int level; + int level; int len = 4; if (strlen(str) == len) { @@ -683,9 +683,15 @@ static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str) f2fs_info(sbi, "wrong format, e.g. :"); return -EINVAL; } - if (kstrtouint(str + 1, 10, &level)) + if (kstrtoint(str + 1, 10, &level)) return -EINVAL; + /* f2fs does not support negative compress level now */ + if (level < 0) { + f2fs_info(sbi, "do not support negative compress level: %d", level); + return -ERANGE; + } + if (!f2fs_is_compress_level_valid(COMPRESS_ZSTD, level)) { f2fs_info(sbi, "invalid zstd compress level: %d", level); return -EINVAL;