Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6567492rdb; Tue, 2 Jan 2024 06:17:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOr01Nf0wxW2xp5FdGJNNQSyA2IQ4T9W5m0W1R3B52BD/BturPXqfLJJCHcxXgboMq6Utv X-Received: by 2002:a05:6870:d0c3:b0:1fb:51e:bc17 with SMTP id k3-20020a056870d0c300b001fb051ebc17mr20892856oaa.30.1704205024140; Tue, 02 Jan 2024 06:17:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704205024; cv=none; d=google.com; s=arc-20160816; b=bXph7fwcsfLU0/ThsLAnZLjdffAJgwDz2lN+iXou08LsvjZfFwdqESj35XkJDCbegE KkW86AsNs1WTZibtbuyQy8OeLLHmoCP97UOQXyKsZoTaR+CsnLTlhLL+ix5cJkGSBho8 XEFVkbvCrjlPVcgHXn8wWrAuOj+yPj1AqYn5h86EWTlG3i3673HAjO5Ce4M8QsFSa7kc IiuOiYhaN6zvmWfRtCUiNuEpHqtpCXNEI6Ze5KdOyh6rH8kzq1zdQ1HGUQfk7OzgrGP/ D08vh5A1b0drvlJEkpJySHKDxLKr5/hPgpZGo2bDD0V5qXLyLzqi232u4riWs8FEJU8C gG+Q== 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 :subject:cc:to:from:date; bh=0i7WvcmgA+GXIt24wsFwELsZxLUnjf1OOz16Pa4UEsw=; fh=NdDGMlRGVvuO/h+Plv/28uBZxcw6zw5kNsKEcaVqvxA=; b=M7W0okAAz5LHu+qBcLSRTq9YI2iQ6RuEyiLDpTxHhiiS6LBGkF3XX6Dgj5kPfcC7Re yzrX0tTslxC5/NmZv+CcydSe6QJObrODDVs8fRapuUlIrAYszPdsfJ4DCZF7fd3LXsuJ MWr0JgT8ZEqs4WyiyRqhRLiFEHg3XncQvW7NeMRZnd04oA7sxywQPtQMgvJzzUrhvwoH vSPxVuyhPbcjkhktHzyNXc/5fLhszli4JzC19CgmBpMM3QvyenU8bWzihIf+y7Swi0iW PfgIiGt3QJhYLvq4eh7Y7bd9x3JMYKfcVzO/QDPZ8U7xuzXsANqbxr8x4CPMUUPDOaQi lMcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14472-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14472-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id pj15-20020a05620a1d8f00b0077dba4b9e95si26290846qkn.742.2024.01.02.06.17.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 06:17:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14472-linux.lists.archive=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; spf=pass (google.com: domain of linux-kernel+bounces-14472-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14472-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de 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 8C17E1C22282 for ; Tue, 2 Jan 2024 14:17:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E44412B95; Tue, 2 Jan 2024 14:16:44 +0000 (UTC) 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 2526211722; Tue, 2 Jan 2024 14:16:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de 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-out2.suse.de (Postfix) with ESMTPS id 478D81FD60; Tue, 2 Jan 2024 14:16:40 +0000 (UTC) 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 24A201340C; Tue, 2 Jan 2024 14:16:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 86yjMMQalGWUXQAAD6G6ig (envelope-from ); Tue, 02 Jan 2024 14:16:36 +0000 Date: Wed, 3 Jan 2024 01:16:22 +1100 From: David Disseldorp To: Qu Wenruo Cc: 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 Subject: Re: [PATCH v2 1/4] kstrtox: always skip the leading "0x" even if no more valid chars Message-ID: <20240103011622.144d62d0@echidna> 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-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 478D81FD60 On Tue, 2 Jan 2024 14:42:11 +1030, Qu Wenruo wrote: > Currently the invalid string "0x" (only hex prefix, no valid chars > followed) would make _parse_integer_fixup_radix() to treat it as octal. > > This is due to the fact that the function would only auto-detect hex if > and only if there is any valid hex char after "0x". > Or it would only go octal instead. > > Thankfully this won't affect our unit test, as "0x" would still be > treated as failure. > Since we treat the result as octal, the result value would be 0, leaving > "x" as the tailing char and still fail kstrtox() functions. > > But for the incoming memparse_safe(), the remaining string would still > be consumed by the caller, and we need to properly treat "0x" as an > invalid string. > > So this patch would make _parse_integer_fixup_radix() to forcefully go > hex no matter if there is any valid char following. > > Signed-off-by: Qu Wenruo > --- > lib/kstrtox.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/kstrtox.c b/lib/kstrtox.c > index d586e6af5e5a..41c9a499bbf3 100644 > --- a/lib/kstrtox.c > +++ b/lib/kstrtox.c > @@ -27,7 +27,7 @@ const char *_parse_integer_fixup_radix(const char *s, unsigned int *base) > { > if (*base == 0) { > if (s[0] == '0') { > - if (_tolower(s[1]) == 'x' && isxdigit(s[2])) > + if (_tolower(s[1]) == 'x') > *base = 16; > else > *base = 8; There's a copy of this function in arch/x86/boot/string.c which should probably remain consistent (or be removed). Aside from that, this looks good to me: Reviewed-by: David Disseldorp