From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E70ED35693 for ; Wed, 28 Jan 2026 10:54:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:References:From:To:Cc: Subject:Message-Id:Date:Mime-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2KixMafTszUlvN2PkjdbOXmGAJmpfYFkyyZg/67lNC8=; b=gK3LkorZU5z6ib Sb9Bn7SxUkx2q3T/LBy4JiifP0OqlNmJKWhxUOKI+H6szGjrX75RLipcQdFibYK0vE1ERLq2iiCA2 gAFwIPweoCX/x7QFsZTT8XNEhDOrSLAYTgNr7AgAp3ZiF3JluSGlI+yFE1pTZVeaQgJqjnHj9aZhH fKMRA6pbtixBNJAHg6zRHMdUJOhmn1rMNgQwCIxI8JXigYY8n24IWlSmHOv9xgbaMQqF6q4q3mfKj Olt5DWdMOCw3L0f5eaMZJRGlhtnbAwHdLFFTzS88MuJYWnvhCPbkIOxoeuO3gpmSKtVpf9UYr4njE CNFu5UwKIqAhK9PWVWvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vl3BP-0000000FsNL-42XX; Wed, 28 Jan 2026 10:53:59 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vl3BN-0000000FsN1-3b10 for linux-riscv@lists.infradead.org; Wed, 28 Jan 2026 10:53:58 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id F17BD600AA; Wed, 28 Jan 2026 10:53:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1510AC2BCB0; Wed, 28 Jan 2026 10:53:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769597636; bh=VTLd7vd+WPNn7NR0v8u7rGagToa/9uYN3+K/raVxK/Q=; h=Date:Subject:Cc:To:From:References:In-Reply-To:From; b=MQQqeZn/PS82H2I0BiwGmgQ0Es/plFXiloDRMKmpxzUhvqPevwbL542+5QITNyZtU up/j2BkdX6VCiLztlMVnpPhqwdy/BhsErmW0jHE2rVRNULmxfLtrZ0skQN27sluyP6 a95zFRg1votKHCV6STIz1NUYtanysA/u9krLZ7CX0hKyiG1PUn6ZE+vHeARq0xVehX sXXnInrrgikf+WNsUYJqhwIlbS65UdHhXdx/hEwE5PHDMEkhzwm1W0tR/NgOwkhJwr logbW9QpMlEbl5C2uoY/5E6fCXt1GBQDTD6BWIqUVTnykJkc0f/oEGVzYl63/LjXtF wlaKiS7SLYHvg== Mime-Version: 1.0 Date: Wed, 28 Jan 2026 11:53:48 +0100 Message-Id: Subject: Re: [PATCH v2 1/5] gpu: nova-core: use checked arithmetic in FWSEC firmware parsing Cc: , "Paul Walmsley" , "Palmer Dabbelt" , "Albert Ou" , "Alexandre Ghiti" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Alexandre Courbot" , "John Hubbard" , "Alistair Popple" , "Timur Tabi" , "Edwin Peer" , "Zhi Wang" , "David Airlie" , "Simona Vetter" , "Bjorn Helgaas" , "Alex Gaynor" , "Dirk Behme" , , , , To: "Joel Fernandes" From: "Danilo Krummrich" References: <20260126202305.2526618-1-joelagnelf@nvidia.com> <20260126202305.2526618-2-joelagnelf@nvidia.com> In-Reply-To: <20260126202305.2526618-2-joelagnelf@nvidia.com> X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Mon Jan 26, 2026 at 9:23 PM CET, Joel Fernandes wrote: > @@ -267,7 +264,12 @@ fn new_fwsec(dev: &Device, bios: &Vbios, cmd: FwsecCommand) -> Re > let ucode = bios.fwsec_image().ucode(&desc)?; > let mut dma_object = DmaObject::from_data(dev, ucode)?; > > - let hdr_offset = usize::from_safe_cast(desc.imem_load_size() + desc.interface_offset()); > + // Compute hdr_offset = imem_load_size + interface_offset. I do get the idea behind those comments, but are we sure that's really a good idea? How do we ensure to keep them up to date in case we have to change the code? If we really want this, I'd at least chose a common syntax, e.g. // CALC: `imem_load_size + interface_offset` without the variable name the resulting value is assigned to. But I'd rather prefer to just drop those comments. > + let hdr_offset = desc > + .imem_load_size() > + .checked_add(desc.interface_offset()) > + .map(usize::from_safe_cast) > + .ok_or(EINVAL)?; > // SAFETY: we have exclusive access to `dma_object`. > let hdr: &FalconAppifHdrV1 = unsafe { transmute(&dma_object, hdr_offset) }?; _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D9A4D2592A for ; Wed, 28 Jan 2026 10:54:02 +0000 (UTC) Received: from kara.freedesktop.org (unknown [131.252.210.166]) by gabe.freedesktop.org (Postfix) with ESMTPS id 933A110E64B; Wed, 28 Jan 2026 10:54:00 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="MQQqeZn/"; dkim-atps=neutral Received: from kara.freedesktop.org (localhost [127.0.0.1]) by kara.freedesktop.org (Postfix) with ESMTP id 98AE040B86; Wed, 28 Jan 2026 10:44:58 +0000 (UTC) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=lists.freedesktop.org; s=20240201; t=1769597098; b=p+omAMj0ZKSPcutM9bL8ln+vsnbidtjMtQ1pa6q98hiL/dUchJW+DWuWflS6Z1Sq3KKW/ 1FCRIB1LTvjHhVA+7oJnTKrGyEAT+Yv6A8ceeczJZzpsIXiV30lMpLI2u4lILngiJLnLD3n iSK/KC5JTgwmle2xQJUytxs5i8vfUgCzvMgP3MZRngODeUNpYCmZIjt9xAUsp7/2WJmzrub nmhAiWXjdWjPqVhl94bjeWLRX1aV0rx0dy2BT0EdxEz5v8xnAUgdToje1xlQYGKusBtSQSo 8p2cgBXkNQr7VFr/tfk55nw2zYB8akI3BsuEa7QgrsCfjxzrp7u7JXU35LLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.freedesktop.org; s=20240201; t=1769597098; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=w3df7WxTd1E5PicIQ5FWEHWK5xN5bE78+m3fL4xVID0=; b=H75HyoeoV++GPFJYISf5ZY/JRBeIKcrDHUnkbxQcgHuTV8lEzwAoFR5DreayaPhmH1OXE NhgoJ5OJEhdzQEMQvUoNUCUB/IfKLBds1Swr+6hHEzwisjDVBvThI9B8gGDdn+tpPy/ChZr 42n1XnRTxTr/slZGGSXx0lXQpc9f5SOP0UPTlAsVVIYSpPhY6/MPGuNxeXVzh7r8OFFYel0 jNxZuqP0Vr1hCZjmmrJJzoUXFLMVAmEzdRaBwI8sQta7UjmFngDvumWzyNFu0JifExgdMY5 jUQ42DWiwidNUgzT99nM8PjsHIdefA3mK+nnBeknw84CGPvvMQFs9Y+hN7XQ== ARC-Authentication-Results: i=1; mail.freedesktop.org; dkim=pass header.d=kernel.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=kernel.org policy.dmarc=quarantine Authentication-Results: mail.freedesktop.org; dkim=pass header.d=kernel.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=kernel.org policy.dmarc=quarantine Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by kara.freedesktop.org (Postfix) with ESMTPS id E2A4B404D9 for ; Wed, 28 Jan 2026 10:44:55 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9E3D010E642; Wed, 28 Jan 2026 10:53:57 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id F17BD600AA; Wed, 28 Jan 2026 10:53:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1510AC2BCB0; Wed, 28 Jan 2026 10:53:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769597636; bh=VTLd7vd+WPNn7NR0v8u7rGagToa/9uYN3+K/raVxK/Q=; h=Date:Subject:Cc:To:From:References:In-Reply-To:From; b=MQQqeZn/PS82H2I0BiwGmgQ0Es/plFXiloDRMKmpxzUhvqPevwbL542+5QITNyZtU up/j2BkdX6VCiLztlMVnpPhqwdy/BhsErmW0jHE2rVRNULmxfLtrZ0skQN27sluyP6 a95zFRg1votKHCV6STIz1NUYtanysA/u9krLZ7CX0hKyiG1PUn6ZE+vHeARq0xVehX sXXnInrrgikf+WNsUYJqhwIlbS65UdHhXdx/hEwE5PHDMEkhzwm1W0tR/NgOwkhJwr logbW9QpMlEbl5C2uoY/5E6fCXt1GBQDTD6BWIqUVTnykJkc0f/oEGVzYl63/LjXtF wlaKiS7SLYHvg== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 28 Jan 2026 11:53:48 +0100 Message-Id: Subject: Re: [PATCH v2 1/5] gpu: nova-core: use checked arithmetic in FWSEC firmware parsing To: "Joel Fernandes" From: "Danilo Krummrich" References: <20260126202305.2526618-1-joelagnelf@nvidia.com> <20260126202305.2526618-2-joelagnelf@nvidia.com> In-Reply-To: <20260126202305.2526618-2-joelagnelf@nvidia.com> Message-ID-Hash: TT2AVTGKZZAPU6PBMWAP3FP3ZL6JUAXH X-Message-ID-Hash: TT2AVTGKZZAPU6PBMWAP3FP3ZL6JUAXH X-MailFrom: dakr@kernel.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: linux-kernel@vger.kernel.org, Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Alexandre Courbot , Alistair Popple , Zhi Wang , Simona Vetter , Bjorn Helgaas , Alex Gaynor , Dirk Behme , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, linux-riscv@lists.infradead.org X-Mailman-Version: 3.3.8 Precedence: list List-Id: Nouveau development list Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Mon Jan 26, 2026 at 9:23 PM CET, Joel Fernandes wrote: > @@ -267,7 +264,12 @@ fn new_fwsec(dev: &Device, bios: &Vbi= os, cmd: FwsecCommand) -> Re > let ucode =3D bios.fwsec_image().ucode(&desc)?; > let mut dma_object =3D DmaObject::from_data(dev, ucode)?; > =20 > - let hdr_offset =3D usize::from_safe_cast(desc.imem_load_size() += desc.interface_offset()); > + // Compute hdr_offset =3D imem_load_size + interface_offset. I do get the idea behind those comments, but are we sure that's really a go= od idea? How do we ensure to keep them up to date in case we have to change th= e code? If we really want this, I'd at least chose a common syntax, e.g. // CALC: `imem_load_size + interface_offset` without the variable name the resulting value is assigned to. But I'd rather prefer to just drop those comments. > + let hdr_offset =3D desc > + .imem_load_size() > + .checked_add(desc.interface_offset()) > + .map(usize::from_safe_cast) > + .ok_or(EINVAL)?; > // SAFETY: we have exclusive access to `dma_object`. > let hdr: &FalconAppifHdrV1 =3D unsafe { transmute(&dma_object, h= dr_offset) }?; 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 D51BB3382FA; Wed, 28 Jan 2026 10:53:56 +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=1769597636; cv=none; b=CqWJJ4vvSOQbLT4G3QRAJFv8esYF/XxcQDHqoIyou/g4fYEQyOdsmDlRPksoGAUXrxO3h+vyZ9ViKMPeAFxHT/UiNEZnMODIYO0kMyR3W17q5zXZWRwazaIfw13C/XPbu87ZWkk3sUkJpn9LsEu78RCT9xSm6BgVO8g2ncH391M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769597636; c=relaxed/simple; bh=VTLd7vd+WPNn7NR0v8u7rGagToa/9uYN3+K/raVxK/Q=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:Cc:To:From: References:In-Reply-To; b=indOSPQtA8br4ZfCl0ILhaFUBD+sbe13XkCtSic3wIhupwVtCBGlJuK8uQwlpaq6YRqAUKNHe8VqNiR/YQ1Vaamec5KTP99Bf7Vb3kFaTrMuNmn/lrHcpfJxTbW6TaZFzOmDskuGzgXvs7UWmyM884IK0RblEAdRKOgKjmpK6UY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MQQqeZn/; 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="MQQqeZn/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1510AC2BCB0; Wed, 28 Jan 2026 10:53:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769597636; bh=VTLd7vd+WPNn7NR0v8u7rGagToa/9uYN3+K/raVxK/Q=; h=Date:Subject:Cc:To:From:References:In-Reply-To:From; b=MQQqeZn/PS82H2I0BiwGmgQ0Es/plFXiloDRMKmpxzUhvqPevwbL542+5QITNyZtU up/j2BkdX6VCiLztlMVnpPhqwdy/BhsErmW0jHE2rVRNULmxfLtrZ0skQN27sluyP6 a95zFRg1votKHCV6STIz1NUYtanysA/u9krLZ7CX0hKyiG1PUn6ZE+vHeARq0xVehX sXXnInrrgikf+WNsUYJqhwIlbS65UdHhXdx/hEwE5PHDMEkhzwm1W0tR/NgOwkhJwr logbW9QpMlEbl5C2uoY/5E6fCXt1GBQDTD6BWIqUVTnykJkc0f/oEGVzYl63/LjXtF wlaKiS7SLYHvg== Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 28 Jan 2026 11:53:48 +0100 Message-Id: Subject: Re: [PATCH v2 1/5] gpu: nova-core: use checked arithmetic in FWSEC firmware parsing Cc: , "Paul Walmsley" , "Palmer Dabbelt" , "Albert Ou" , "Alexandre Ghiti" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Alexandre Courbot" , "John Hubbard" , "Alistair Popple" , "Timur Tabi" , "Edwin Peer" , "Zhi Wang" , "David Airlie" , "Simona Vetter" , "Bjorn Helgaas" , "Alex Gaynor" , "Dirk Behme" , , , , To: "Joel Fernandes" From: "Danilo Krummrich" References: <20260126202305.2526618-1-joelagnelf@nvidia.com> <20260126202305.2526618-2-joelagnelf@nvidia.com> In-Reply-To: <20260126202305.2526618-2-joelagnelf@nvidia.com> On Mon Jan 26, 2026 at 9:23 PM CET, Joel Fernandes wrote: > @@ -267,7 +264,12 @@ fn new_fwsec(dev: &Device, bios: &Vbi= os, cmd: FwsecCommand) -> Re > let ucode =3D bios.fwsec_image().ucode(&desc)?; > let mut dma_object =3D DmaObject::from_data(dev, ucode)?; > =20 > - let hdr_offset =3D usize::from_safe_cast(desc.imem_load_size() += desc.interface_offset()); > + // Compute hdr_offset =3D imem_load_size + interface_offset. I do get the idea behind those comments, but are we sure that's really a go= od idea? How do we ensure to keep them up to date in case we have to change th= e code? If we really want this, I'd at least chose a common syntax, e.g. // CALC: `imem_load_size + interface_offset` without the variable name the resulting value is assigned to. But I'd rather prefer to just drop those comments. > + let hdr_offset =3D desc > + .imem_load_size() > + .checked_add(desc.interface_offset()) > + .map(usize::from_safe_cast) > + .ok_or(EINVAL)?; > // SAFETY: we have exclusive access to `dma_object`. > let hdr: &FalconAppifHdrV1 =3D unsafe { transmute(&dma_object, h= dr_offset) }?;