From mboxrd@z Thu Jan 1 00:00:00 1970 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 F198E36124; Tue, 25 Feb 2025 05:55:18 +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=1740462919; cv=none; b=jnOx7XE4L96e3ByXsrkArxXSUwJF1lbOkKtOjv5Xb58XawyOiBIFjVcGd3OnmiD7zxKrks6tbZtnVFZypo3ZiPtTOgxKQNwhVt9LFXZxCNtvscrtIIb05qfeKpJenM9FCvy9KyreVf7bS/h7CqEhjDXU7qDdf+Z2sjnUCc4exOg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740462919; c=relaxed/simple; bh=z/n0ecmeuHsI6oH5v9VDQSdSll/BCv4bxwUSARxaT8c=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=nz8UNXbFYq7RLjv4InfpiL7oaPcSXqu2US2OhX63FF9ROvjsg1ccLD79MmV1HQSZ3+dTDot6zGMbkjSHF4lZuQxTA3NI6phuI6NZXndVznh3mDlXU7ls8aRwS8iek/xPfBOtOCvL5dSo6IDOq7LE0QIKO7PaopTRPchYexrYE5o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kWmwkQhl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kWmwkQhl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61F6CC4CEDD; Tue, 25 Feb 2025 05:55:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740462918; bh=z/n0ecmeuHsI6oH5v9VDQSdSll/BCv4bxwUSARxaT8c=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=kWmwkQhljPmntmcEC/IzNKPb7DCR31kahxvqoAOp4hqCBP6A7AZ+nIEvysYxYblE+ yHCa6Hp1qVKCIlQT/sdP3cMtGDrdX9Nf1zwPLJ1hWosxwYzNUlhjmiKZCMQY3JGNib XIKkJvt997eagCvwY7jV8OP4ZROf6FaR30dZW0Un657xBvOeGsk1n/jZEQ6Gc8N3li aJqTBNiCkldsbQdjoM4rYjYGq+5ZfFKjIQcJFMWdgtKMvPRScxJFyUH1W5bwssKfw7 PKsemGTkOXu/0P5fpUq34kCM3uh4uErwnF7MxlBWo1Qu+vWkCHsCPYKIGejD+oBvSB eVshhZ+lsyQIA== From: Andreas Hindborg To: "Janne Grunau" Cc: "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?Q?Bj=C3=B6rn?= Roy Baron , "Benno Lossin" , "Alice Ryhl" , "Trevor Gross" , "Masahiro Yamada" , "Nathan Chancellor" , "Nicolas Schier" , "Luis Chamberlain" , , , "Adam Bratschi-Kaye" , , "Petr Pavlu" , "Sami Tolvanen" , "Daniel Gomez" , "Simona Vetter" , "Greg KH" , Subject: Re: [PATCH v7 5/6] rust: str: add radix prefixed integer parsing functions In-Reply-To: <20250224223032.GA615664@robin.jannau.net> (Janne Grunau's message of "Mon, 24 Feb 2025 23:30:32 +0100") References: <20250218-module-params-v3-v7-0-5e1afabcac1b@kernel.org> <20250218-module-params-v3-v7-5-5e1afabcac1b@kernel.org> <20250224223032.GA615664@robin.jannau.net> User-Agent: mu4e 1.12.7; emacs 29.4 Date: Tue, 25 Feb 2025 06:54:45 +0100 Message-ID: <87tt8iy3fe.fsf@kernel.org> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain "Janne Grunau" writes: > On Tue, Feb 18, 2025 at 02:00:47PM +0100, Andreas Hindborg wrote: >> Add the trait `ParseInt` for parsing string representations of integers >> where the string representations are optionally prefixed by a radix >> specifier. Implement the trait for the primitive integer types. >> >> Signed-off-by: Andreas Hindborg >> --- >> rust/kernel/str.rs | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 118 insertions(+) >> >> diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs >> index db272d2198fcc..8b0d814b47f52 100644 >> --- a/rust/kernel/str.rs >> +++ b/rust/kernel/str.rs >> @@ -945,3 +945,121 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { > > [...] > >> + pub trait ParseInt: FromStrRadix + TryFrom { >> + /// Parse a string according to the description in [`Self`]. >> + fn from_str(src: &BStr) -> Result { >> + match src.deref() { >> + [b'-', rest @ ..] => { >> + let (radix, digits) = strip_radix(rest.as_ref()); >> + // 2's complement values range from -2^(b-1) to 2^(b-1)-1. >> + // So if we want to parse negative numbers as positive and >> + // later multiply by -1, we have to parse into a larger >> + // integer. We choose i128 as sufficiently large. >> + let val = i128::from_str_radix( > > The usage of i128 causes here following link errors on arm64 with > "rustc 1.84.1 (e71f9a9a9 2025-01-27) (Fedora 1.84.1-1.fc41)" > > | ld: rust/kernel.o: in function `::from_str_radix': > | /usr/lib/rustlib/src/rust/library/core/src/num/mod.rs:1563:(.text+0x3bc): undefined reference to `__muloti4' > | ld: /usr/lib/rustlib/src/rust/library/core/src/num/mod.rs:1563:(.text+0x440): undefined reference to `__muloti4' > | ld: rust/kernel.o: in function `::overflowing_mul': > | /usr/lib/rustlib/src/rust/library/core/src/num/int_macros.rs:2517:(.text+0x4b4): undefined reference to `__muloti4' > | ld: /usr/lib/rustlib/src/rust/library/core/src/num/int_macros.rs:2517:(.text+0x534): undefined reference to `__muloti4' > > The errors go away after exchanging i128 with i64 (while breaking the > parsing for large values). Thanks for reporting! I will have to find a better way to fix this issue then. Best regards, Andreas Hindborg