From patchwork Fri Jan 5 02:34:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 18739 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5987860dyb; Thu, 4 Jan 2024 18:35:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqkWo2PU70hX8qIW+S3GQDJ24kQeKquhgIL0Ta1tIR7So1P76oprPzVcNvmGLLRKbUW4di X-Received: by 2002:a05:6a00:27a3:b0:6d9:b264:db94 with SMTP id bd35-20020a056a0027a300b006d9b264db94mr1394403pfb.39.1704422154139; Thu, 04 Jan 2024 18:35:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704422154; cv=none; d=google.com; s=arc-20160816; b=yyuwI5fHrjJVUGNvEIvMPeVXqEBP4kb2gpEQZ2oUCWiYmnUA7RPcLzt4zDJNUCMXBO WBEs0YZLOWRP8CernIu5o2lkv6sFnUS96A3bgZPemsCURuvz5lfQKGHsv8bsRF4ES5kU NykEGMj5bYdylo+OcCzp8YSngfFGO1X+mtZkXC/eKmDCeFGkdqBgtpUWKPQlNE4czkk8 GKwbHdqrlvIUYVWmEcKOQwJkgoEuDJc0jTL71yvL2PmJeDqGeag6xZh4I8JloKjC+lr5 JSzYbUrh0KYF7Vd3ZlWqp5JQHWCTA6HFAsQOFI2onKBWNqfsyMLNkHXybbBpCsEg9zV3 RMGA== 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:message-id:date:subject:to:from :dkim-signature:dkim-signature; bh=H0CJ8fANNvO2ixq7Pn+kIG0ltYTB4ZJd1BUKZhfIgRI=; fh=oFdJy8ofH0dpbBwpPJWhHphSjxNUmKzt4nt2sEDFdO8=; b=ejyGAeckjyTSVgDZk3wjH6CzYFPZDmKgD0ti1IOGtHw0IO7+H6JX0wUcTZJYcax+IO 61fsHYpRDpvMJsJ7hizHHu4T1PBPpb6FCdC6QzvHNonGRw95iAS373tkbVic8ZleUKBM tqIGaKMAzx2HB2CD/s7+x+tfEy53MpJvns93eC24B2FqDvfOZpTb5Wx+/n90BtjycS8M s8J38VOE2+IpOZGOcEsitN2B1DWVyVpGRkbm93AqaiQZrA1xnUbA87EFEQ5hOkHNxDp4 4bwKhoyYY52SxfcSVYsCDDJrbUzv6Doht5sFUf6u97ew5O7fFp0rouBMbhVOBsV+s5VJ EwNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="ce4/JgXB"; dkim=pass header.i=@suse.com header.s=susede1 header.b="ce4/JgXB"; spf=pass (google.com: domain of linux-kernel+bounces-17420-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17420-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p25-20020a056a000a1900b006d9a4feb0e9si509104pfh.158.2024.01.04.18.35.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 18:35:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17420-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="ce4/JgXB"; dkim=pass header.i=@suse.com header.s=susede1 header.b="ce4/JgXB"; spf=pass (google.com: domain of linux-kernel+bounces-17420-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17420-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id E9FFCB24196 for ; Fri, 5 Jan 2024 02:35:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 931E34C7E; Fri, 5 Jan 2024 02:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="ce4/JgXB"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="ce4/JgXB" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 C4F2420EB; Fri, 5 Jan 2024 02:35:32 +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 [IPv6:2a07:de40:b281:104: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-out1.suse.de (Postfix) with ESMTPS id 7D91421DFE; Fri, 5 Jan 2024 02:35:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1704422130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=H0CJ8fANNvO2ixq7Pn+kIG0ltYTB4ZJd1BUKZhfIgRI=; b=ce4/JgXBWP38apNl3rzbGK1QuSVkmQ6Pko+GF2QAlzzGnLJ06qLrhMihwuXxqnWLPD0osl ADI0IpQluppyOH11AFxNcf0hcCqRVqsbUah/9QM0jzIfroo2/Pv5LIkbHFNoyrmj1JbqYD K/2e3GOsbZSiwYN6yWbVPiXtywsgxlM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1704422130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=H0CJ8fANNvO2ixq7Pn+kIG0ltYTB4ZJd1BUKZhfIgRI=; b=ce4/JgXBWP38apNl3rzbGK1QuSVkmQ6Pko+GF2QAlzzGnLJ06qLrhMihwuXxqnWLPD0osl ADI0IpQluppyOH11AFxNcf0hcCqRVqsbUah/9QM0jzIfroo2/Pv5LIkbHFNoyrmj1JbqYD K/2e3GOsbZSiwYN6yWbVPiXtywsgxlM= 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 36972137E8; Fri, 5 Jan 2024 02:35:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id yJZQK+tql2XhbAAAD6G6ig (envelope-from ); Fri, 05 Jan 2024 02:35:23 +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, rdunlap@infradead.org Subject: [PATCH v4 0/4] kstrtox: introduce memparse_safe() Date: Fri, 5 Jan 2024 13:04:58 +1030 Message-ID: X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: **** X-Spam-Level: X-Spamd-Bar: / Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b="ce4/JgXB" X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-0.01 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; R_MISSING_CHARSET(2.50)[]; TO_DN_NONE(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[9]; NEURAL_HAM_SHORT(-0.20)[-0.995]; FREEMAIL_TO(0.00)[vger.kernel.org,linux-foundation.org,wanadoo.fr,linux.intel.com,ACULAB.COM,suse.de,linux-m68k.org,infradead.org]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-0.00)[24.27%]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; URIBL_BLOCKED(0.00)[suse.com:dkim]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[wanadoo.fr]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DWL_DNSWL_HI(-3.50)[suse.com:dkim]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -0.01 X-Rspamd-Queue-Id: 7D91421DFE X-Spam-Flag: NO X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787216164528628295 X-GMAIL-MSGID: 1787216164528628295 [CHANGELOG] v4: - Extra test cases for supported but not enabled suffixes - Comments update for memparse_safe() function v3: - Fix the 32bit pointer pattern in the test case The old pointer pattern for 32 bit systems is in fact 40 bits, which would still lead to sparse warning. The newer pattern is using UINTPTR_MAX to trim the pattern, then converted to a pointer, which should not cause any trimmed bits and make sparse happy. v2: - Make _parse_integer_fixup_radix() to always treat "0x" as hex This is to make sure invalid strings like "0x" or "0xG" to fail as expected for memparse_safe(). Or they would only parse the first 0, then leaving "x" for caller to handle. - Update the test case to include above failure cases This including: * "0x", just hex prefix without any suffix/follow up chars * "0xK", just hex prefix and a stray suffix * "0xY", hex prefix with an invalid char - Fix a bug in btrfs' conversion to memparse_safe() Where I forgot to delete the old memparse() line. - Fix a compiler warning on m68K On that platform, a pointer (32 bits) is smaller than unsigned long long (64 bits), which can cause static checker to warn. Qu Wenruo (4): kstrtox: always skip the leading "0x" even if no more valid chars kstrtox: introduce a safer version of memparse() kstrtox: add unit tests for memparse_safe() btrfs: migrate to the newer memparse_safe() helper arch/x86/boot/string.c | 2 +- fs/btrfs/ioctl.c | 6 +- fs/btrfs/super.c | 9 +- fs/btrfs/sysfs.c | 14 ++- include/linux/kernel.h | 8 +- include/linux/kstrtox.h | 15 +++ lib/cmdline.c | 4 +- lib/kstrtox.c | 101 ++++++++++++++++- lib/test-kstrtox.c | 244 ++++++++++++++++++++++++++++++++++++++++ 9 files changed, 394 insertions(+), 9 deletions(-)