From nobody Sun Feb 8 05:30:22 2026 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 12E3915B100 for ; Wed, 10 Apr 2024 11:58:43 +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=1712750323; cv=none; b=HOlJlHHVFUfpb9WIx0B633kWLmc595poMSczKwcnpRjSIO0NeG8oCkYlXCd+svIb8vBboC3xHgQzod2SZMRkLUFCONmAsOjUUv1WodDtsccx8bpZfqi3+XvPAblekD94S2KP6OE1W7XWAueFzmq0Jz10DOdSKkvrGwQRxOIRHSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712750323; c=relaxed/simple; bh=hLF5VZ17pcPT+iEdSikbSqPPdiOP/ae+ULNTI7IT42U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H9CmxL6qrp7pkWemFyJ3xzfPBHew8tnpE7z69HBpt4Cu9We0fv4nHmPFAXdA08F6UWg7DhG0egEpudIUVjVYBn+wTAWUQH6OOLO9e1LwHF4XICSd1dozPyfaMZ5C+OuoekmNYlrPca1tS8JaVKNMZlKmjHbFkwG81iWZzmhzpOo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g6+1JWy2; 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="g6+1JWy2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93A5BC43390; Wed, 10 Apr 2024 11:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712750322; bh=hLF5VZ17pcPT+iEdSikbSqPPdiOP/ae+ULNTI7IT42U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g6+1JWy2ltqVeLACEyfTQQ8B+ANNmaXO+i0uHM7LnBIiDhS1LVx6wLMBWvpq4UqAh zWU3yRPQs2pq5PSPzXMOwdKbEQqkQr2U8unUIwUM4PvfhQyDpoOYk+dZNInNtTtUS4 6ppi8bYj/seXUUzuAhIDE5P8hzJEZ9YVQID5aiNMntUxHpoyMNIHrNbdUsVOuUVL8G WjZC5VblrRl7YHzpdl21FfZpPC1F0r0O1V8IYzh3NetWJ6s3d1jPIv2HKl53/5icQY CM9EDjCCZxcRoWthEsmsuV/zS+SKcSCoD2RNLV6TZjgqEvtPeMuvh8T8Jw/QTIoG/h wXyzcc/GWqRBA== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Daire McNamara , Cyril Jean , linux-kernel@vger.kernel.org Subject: [PATCH v1 1/5] firmware: microchip: support writing bitstream info to flash Date: Wed, 10 Apr 2024 12:58:04 +0100 Message-ID: <20240410-shabby-fineness-6e8662cf44e2@spud> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410-opulently-epic-8654bdac3422@spud> References: <20240410-opulently-epic-8654bdac3422@spud> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4272; i=conor.dooley@microchip.com; h=from:subject:message-id; bh=Mheo3lXIW1m+cEZnaJh1zYtTPgF5wFDCI953hFakqwY=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDGlidVe62P1CVnpYFjuaKwXP62QWc3Jrz97DM+0aE1N6f WLQ1A8dpSwMYhwMsmKKLIm3+1qk1v9x2eHc8xZmDisTyBAGLk4BmEjQQkaGbX8bv/nsVs6/Zzg1 xar7tOK50F95VywLck++bknStJ69l+EP11/9D2nJW8xXhEm0H5+f/NTF7eR7J7cbLucUOzcvfCn NCQA= X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Conor Dooley Updating the FPGA image might bring with it changes visible to Linux, so it is helpful to also co-locate dt-overlays that describe the new image contents. If these are packaged in a specific format [1] (detected by first 4 bytes being MCHP, since FPGA images have no magic), load the file to the reserved 1 MiB region immediately after the directory in flash. The Beagle-V Fire's "gateware" already creates these files and puts them in flash [2]. Link: exists on confluence, needs to be made public Link: https://openbeagle.org/beaglev-fire/gateware/-/blob/main/gateware_scr= ipts/generate_gateware_overlays.py?ref_type=3Dheads [2] Signed-off-by: Conor Dooley --- drivers/firmware/microchip/mpfs-auto-update.c | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/drivers/firmware/microchip/mpfs-auto-update.c b/drivers/firmwa= re/microchip/mpfs-auto-update.c index 32394c24b37d..33343e83373c 100644 --- a/drivers/firmware/microchip/mpfs-auto-update.c +++ b/drivers/firmware/microchip/mpfs-auto-update.c @@ -71,8 +71,9 @@ #define AUTO_UPDATE_UPGRADE_DIRECTORY (AUTO_UPDATE_DIRECTORY_WIDTH * AUTO_= UPDATE_UPGRADE_INDEX) #define AUTO_UPDATE_BLANK_DIRECTORY (AUTO_UPDATE_DIRECTORY_WIDTH * AUTO_UP= DATE_BLANK_INDEX) #define AUTO_UPDATE_DIRECTORY_SIZE SZ_1K -#define AUTO_UPDATE_RESERVED_SIZE SZ_1M -#define AUTO_UPDATE_BITSTREAM_BASE (AUTO_UPDATE_DIRECTORY_SIZE + AUTO_UPDA= TE_RESERVED_SIZE) +#define AUTO_UPDATE_INFO_BASE AUTO_UPDATE_DIRECTORY_SIZE +#define AUTO_UPDATE_INFO_SIZE SZ_1M +#define AUTO_UPDATE_BITSTREAM_BASE (AUTO_UPDATE_DIRECTORY_SIZE + AUTO_UPDA= TE_INFO_SIZE) =20 #define AUTO_UPDATE_TIMEOUT_MS 60000 =20 @@ -86,6 +87,17 @@ struct mpfs_auto_update_priv { bool cancel_request; }; =20 +static bool mpfs_auto_update_is_bitstream_info(const u8 *data, u32 size) +{ + if (size < 4) + return false; + + if (data[0] =3D=3D 0x4d && data[1] =3D=3D 0x43 && data[2] =3D=3D 0x48 && = data[3] =3D=3D 0x50) + return true; + + return false; +} + static enum fw_upload_err mpfs_auto_update_prepare(struct fw_upload *fw_up= loader, const u8 *data, u32 size) { @@ -287,22 +299,37 @@ static int mpfs_auto_update_write_bitstream(struct fw= _upload *fw_uploader, const loff_t directory_address =3D AUTO_UPDATE_UPGRADE_DIRECTORY; size_t erase_size =3D AUTO_UPDATE_DIRECTORY_SIZE; size_t bytes_written =3D 0; + bool is_info =3D mpfs_auto_update_is_bitstream_info(data, size); u32 image_address; int ret; =20 erase_size =3D round_up(erase_size, (u64)priv->flash->erasesize); =20 - image_address =3D AUTO_UPDATE_BITSTREAM_BASE + - AUTO_UPDATE_UPGRADE_INDEX * priv->size_per_bitstream; + if (is_info) + image_address =3D AUTO_UPDATE_INFO_BASE; + else + image_address =3D AUTO_UPDATE_BITSTREAM_BASE + + AUTO_UPDATE_UPGRADE_INDEX * priv->size_per_bitstream; =20 buffer =3D devm_kzalloc(priv->dev, erase_size, GFP_KERNEL); if (!buffer) return -ENOMEM; =20 - ret =3D mpfs_auto_update_set_image_address(priv, buffer, image_address, d= irectory_address); - if (ret) { - dev_err(priv->dev, "failed to set image address in the SPI directory: %d= \n", ret); - goto out; + /* + * For bitstream info, the descriptor is written to a fixed offset, + * so there is no need to set the image address. + */ + if (!is_info) { + ret =3D mpfs_auto_update_set_image_address(priv, buffer, image_address, = directory_address); + if (ret) { + dev_err(priv->dev, "failed to set image address in the SPI directory: %= d\n", ret); + return ret; + } + } else { + if (size > AUTO_UPDATE_INFO_SIZE) { + dev_err(priv->dev, "bitstream info exceeds permitted size\n"); + return -ENOSPC; + } } =20 /* @@ -334,6 +361,7 @@ static int mpfs_auto_update_write_bitstream(struct fw_u= pload *fw_uploader, const } =20 *written =3D bytes_written; + dev_info(priv->dev, "Wrote 0x%zx bytes to the flash\n", bytes_written); =20 out: devm_kfree(priv->dev, buffer); @@ -360,6 +388,9 @@ static enum fw_upload_err mpfs_auto_update_write(struct= fw_upload *fw_uploader, goto out; } =20 + if (mpfs_auto_update_is_bitstream_info(data, size)) + goto out; + ret =3D mpfs_auto_update_verify_image(fw_uploader); if (ret) err =3D FW_UPLOAD_ERR_FW_INVALID; --=20 2.43.0 From nobody Sun Feb 8 05:30:22 2026 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 2FE9F15B142 for ; Wed, 10 Apr 2024 11:58:44 +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=1712750325; cv=none; b=qonpyIbGLIY8oBuTiJQdgwPCGrPU0CCfCswybRPLuR1GhLY2VYX6YdMoj2u1IhJdqPxNj/CN8G67NRroKn8AC+qtBy8cgAY3yfkmLQZjwYG1oGPdF+mngQztyqxD9lPscIN363t5iK+82a0IH0D1JogfPxO2GmcoHkgkPlTYpV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712750325; c=relaxed/simple; bh=miFooV5xlwUAoCg/5+WmOIw7hiB7FtagEK3Q2jQpBdo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DCzeHN2JABkNFCCXbTdNihU8nP9HMCjdS6XQuTR/hJ5TWfmuuGzyOZfwDwGDWwcqIHL10oKkw9NFZTWmNncanNxWooiQeLebvKTpvz8MYX+HNbEKEZshlcjfV0ymon/lKPUXczWO51mXEO1Vct5VmQdcEFjN+SpjgaOgCLcNlZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LzkTexlU; 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="LzkTexlU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B724C43394; Wed, 10 Apr 2024 11:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712750324; bh=miFooV5xlwUAoCg/5+WmOIw7hiB7FtagEK3Q2jQpBdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LzkTexlUdZzTNblZagdSguoN7Auvwyg5ucQMjlq+cptVQwFQ4S867LO/VGgVQ25q1 VTUXuPxX2YRuFFbOfc+vkQY7WlmW5Jdt4DKt79iebKHmaX7ED+HaeoHFIT0C4ugRL+ rJgJeQsfQG7vm+75L4d7106btgyKMPzToYMmFkXkIS+VxRVQqrhSrvjrzFh3Ga72Gp LbgeBgxre8b7e4fJX64eavrDEv51lh66jxVdQb6vp/RIU6mjy0blehj1w31tybG7kY hfFnXfndpz7KzVwYlROXa+6YdsGM3E40qG5qSaBTLDqrFnbcD4/e2rWYvxmOVYVvlv Oplqn6rf66Z5g== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Daire McNamara , Cyril Jean , linux-kernel@vger.kernel.org Subject: [PATCH v1 2/5] firmware: microchip: don't unconditionally print validation success Date: Wed, 10 Apr 2024 12:58:05 +0100 Message-ID: <20240410-throwing-sandworm-7d03e4e2f4e8@spud> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410-opulently-epic-8654bdac3422@spud> References: <20240410-opulently-epic-8654bdac3422@spud> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1033; i=conor.dooley@microchip.com; h=from:subject:message-id; bh=bV+GMkr+Qxwo4lMIT/B+7/B5KMkZCVAYKLvbSQ6UzsY=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDGlidVesmcN/GW7tkMwrORDPaLzTzH1p8vWTh5Zni3yrb YxN2vu3o5SFQYyDQVZMkSXxdl+L1Po/Ljuce97CzGFlAhnCwMUpABPZIszwv+z3nHNeM45xms/P ifjf1NKtIvw0wGjhOfO0BSdPGqxKsGRkmO7Y8GXVvIqnl019DRTuX808xacV1bN4xZo8zeDmY99 YuAE= X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Conor Dooley If validation fails, both prints are made. Skip the success one in the failure case. Fixes: ec5b0f1193ad ("firmware: microchip: add PolarFire SoC Auto Update su= pport") Signed-off-by: Conor Dooley --- drivers/firmware/microchip/mpfs-auto-update.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/firmware/microchip/mpfs-auto-update.c b/drivers/firmwa= re/microchip/mpfs-auto-update.c index 33343e83373c..298ad21e139b 100644 --- a/drivers/firmware/microchip/mpfs-auto-update.c +++ b/drivers/firmware/microchip/mpfs-auto-update.c @@ -218,10 +218,12 @@ static int mpfs_auto_update_verify_image(struct fw_up= load *fw_uploader) if (ret | response->resp_status) { dev_warn(priv->dev, "Verification of Upgrade Image failed!\n"); ret =3D ret ? ret : -EBADMSG; + goto free_message; } =20 dev_info(priv->dev, "Verification of Upgrade Image passed!\n"); =20 +free_message: devm_kfree(priv->dev, message); free_response: devm_kfree(priv->dev, response); --=20 2.43.0 From nobody Sun Feb 8 05:30:22 2026 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 94B1C15ADB6 for ; Wed, 10 Apr 2024 11:58:46 +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=1712750326; cv=none; b=Mg2ZonSeBr2DObEyeoIf7Io4BcUjEuyJoc9UJ8wBM9LNY6vxQqctEwvuuPt1R+s4EDBdvJwzv8rFSU57Vv9eRdJAGK3e1pmyrI1T1D2e1tm2me1+DAirdIoTeaDDJYIbdwjtJStLuxJO6kEiE0E7IGXSXzZzjVaCCrGXMLuf9Y0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712750326; c=relaxed/simple; bh=I0ucffUjI9S2cz08Ial3I81TqrYvCDbjo9pZBliGHHs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=inI1TpQA9XLWPXg1yRRRNmQ/6ejTF4GjVV2de3ccX3DMH+8S6pvmw7mY3qdUIp4Soc0mlUHA4y/Z/G+tr+k1X1QemYsMjPMozfKk9lbJkG8TnZ/YZhxOQpsAovrYqVPKMk4Ea5tv2DImSAjVsZsHd8mpeE4Is6O5qHwBHTWEjTY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t5pvV5Zz; 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="t5pvV5Zz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 224EEC43390; Wed, 10 Apr 2024 11:58:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712750326; bh=I0ucffUjI9S2cz08Ial3I81TqrYvCDbjo9pZBliGHHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t5pvV5ZzYr/RzporQ5oxS0aMfiV+V0q4Y2GxhgF1z79jFoCE0gBmPkJy7lhMoquBE x5z4w5o7IMU/EeUHyW97iTep8pYcNF6KIh+C6IB1CYcLFVxgjZNCMMTbCIvMFB+BwK Szme+Lh+6kyqU/xCcuo6woWbxG6NduD1jomFGw6DXp9AdBzEZ/tjEm8rGLIakgd0RY npZInp/oD3QhFqLgV5ZO/OlqiFRHKixUjPiQCLE4yCKluiRNE6DxYAHJqYLS8Chb01 R6SpQ+opJhACIPLeF7JZyq61Arnb3jTq/ZCsAu1QCNK1g8CO+Q5qModKWlw/T5WglX 0v98rHwxKfdJA== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Daire McNamara , Cyril Jean , linux-kernel@vger.kernel.org Subject: [PATCH v1 3/5] firmware: microchip: clarify that sizes and addresses are in hex Date: Wed, 10 Apr 2024 12:58:06 +0100 Message-ID: <20240410-elk-staleness-285063ef0433@spud> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410-opulently-epic-8654bdac3422@spud> References: <20240410-opulently-epic-8654bdac3422@spud> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2012; i=conor.dooley@microchip.com; h=from:subject:message-id; bh=BNSIAOq6X1LAhr9L0BQrr3EsDDjmIu+xC/kpYkZfVl4=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDGlidVfOqLZ/vnLjSxXD8h3G/DkLbvKtbNCIX7r23GEmu ZX9mnmSHaUsDGIcDLJiiiyJt/tapNb/cdnh3PMWZg4rE8gQBi5OAZgImxEjw9U517olFpwtyuQL X5PH7H3p4OtWvTtsN/foftl8pObDp7cM/5PmMj+azXDi/pYJrpMub31nvWG+4a3j7w7zqk1h1wz beJQFAA== X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Conor Dooley As it says on the tin. It can be kinda confusing when "22830" is in hex, so prefix the hex numbers with a "0x". Signed-off-by: Conor Dooley --- drivers/firmware/microchip/mpfs-auto-update.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/microchip/mpfs-auto-update.c b/drivers/firmwa= re/microchip/mpfs-auto-update.c index 298ad21e139b..078ff328f261 100644 --- a/drivers/firmware/microchip/mpfs-auto-update.c +++ b/drivers/firmware/microchip/mpfs-auto-update.c @@ -279,7 +279,7 @@ static int mpfs_auto_update_set_image_address(struct mp= fs_auto_update_priv *priv AUTO_UPDATE_DIRECTORY_WIDTH); memset(buffer + AUTO_UPDATE_BLANK_DIRECTORY, 0x0, AUTO_UPDATE_DIRECTORY_W= IDTH); =20 - dev_info(priv->dev, "Writing the image address (%x) to the flash director= y (%llx)\n", + dev_info(priv->dev, "Writing the image address (0x%x) to the flash direct= ory (0x%llx)\n", image_address, directory_address); =20 ret =3D mtd_write(priv->flash, 0x0, erase_size, &bytes_written, (u_char *= )buffer); @@ -342,7 +342,7 @@ static int mpfs_auto_update_write_bitstream(struct fw_u= pload *fw_uploader, const erase.len =3D round_up(size, (size_t)priv->flash->erasesize); erase.addr =3D image_address; =20 - dev_info(priv->dev, "Erasing the flash at address (%x)\n", image_address); + dev_info(priv->dev, "Erasing the flash at address (0x%x)\n", image_addres= s); ret =3D mtd_erase(priv->flash, &erase); if (ret) goto out; @@ -352,7 +352,7 @@ static int mpfs_auto_update_write_bitstream(struct fw_u= pload *fw_uploader, const * will do all of that itself - including verifying that the bitstream * is valid. */ - dev_info(priv->dev, "Writing the image to the flash at address (%x)\n", i= mage_address); + dev_info(priv->dev, "Writing the image to the flash at address (0x%x)\n",= image_address); ret =3D mtd_write(priv->flash, (loff_t)image_address, size, &bytes_writte= n, data); if (ret) goto out; --=20 2.43.0 From nobody Sun Feb 8 05:30:22 2026 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 B84A115CD56 for ; Wed, 10 Apr 2024 11:58:48 +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=1712750328; cv=none; b=Q4/RUb/v8EF9OjUFt8zNKa4v0/ETKP5B8J+/tlbJHExFPtPnp3oxoNqqSwAslhUcsUhNU9yKKCNUaGckb1pO6pSfhqH9ZoPrS8y3A9TmPBnLk1vyyLjEvLylHzZSJqHX9eevf+BX5sX83JEaP7cv+/VYzjvqQCwvsdP1R+Ivlkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712750328; c=relaxed/simple; bh=zozmtpGCyzauq3lW42w4fnyusZzE+3jFnWSCycg+74w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lomaPJYTwAZ+2H68pi/QQLk6wsgu7fdPGNvFKvtIu5n35SnbY6WTRNa4i+CtuFFFp5iGHjQx/bs9POghCbWF3K/JmW1WqbQLu0AmEOmGsT3qURJgoPAhZYTSGeJOcTCs+mWA/n6thkgzsQz4fBUP0wARkCvuRlkblxZvvDcJtqk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ki2sL3Mh; 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="Ki2sL3Mh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEC8FC43390; Wed, 10 Apr 2024 11:58:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712750328; bh=zozmtpGCyzauq3lW42w4fnyusZzE+3jFnWSCycg+74w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ki2sL3MhTeMJTG3avbeH1rzNAe7ciJKLADcUu1fQX6z8ruJDN7zDZ+xQ8xSe28t4h YhkH6vqfVaZHU9te9wWvdi5pPKlKDCnRBeBnjIV+Rc48jKhTKBYFD9oeQnL8J4GVZb HVMEZKtFzlB2SOMIasbDU9Gzk2dtbZAuEFDIbmsoSKiape4vzIXXDm8sijBmwY5Sti iWJMcaxZjcQBA1vjeI1rInOjnB4e6VQaeljR0Y+zBZYvOIb0L+mTukLCuWeoyiufay ojFtgFrSaLueQnp9nfK2cr9h0aQ0arl+iRMn1B6ZC2csTJ49/U9Iqe4gmILb/nxfra gCiQ6tAqghoyw== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Daire McNamara , Cyril Jean , linux-kernel@vger.kernel.org Subject: [PATCH v1 4/5] firmware: microchip: move buffer allocation into mpfs_auto_update_set_image_address() Date: Wed, 10 Apr 2024 12:58:07 +0100 Message-ID: <20240410-manhood-gathering-41ccbfdad649@spud> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410-opulently-epic-8654bdac3422@spud> References: <20240410-opulently-epic-8654bdac3422@spud> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4105; i=conor.dooley@microchip.com; h=from:subject:message-id; bh=wFllIaLoSb4Gw+0g2yEUZWRr6LUeHyCfKeT7QJ6ExZU=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDGlidVd1lBOmeBjKi02Xe3uSP7V/Pf+C1dOcTPVPX1Z9I PRvlXV4RykLgxgHg6yYIkvi7b4WqfV/XHY497yFmcPKBDKEgYtTACbS6srIMPltMsdPBVHxzU9W FgTfqeLbN4m7+g1P2V2hKvkzOg+vpjEyXJ/q3iv1ePUiRh2XM1fvnfeUiNvy4aifBX/iRq4z6fp 57AA= X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Conor Dooley This buffer is used exclusively by mpfs_auto_update_set_image_address(), so move the management of it there, employing the recently added cleanup infrastructure to avoid littering the function with gotos. Signed-off-by: Conor Dooley --- drivers/firmware/microchip/mpfs-auto-update.c | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/drivers/firmware/microchip/mpfs-auto-update.c b/drivers/firmwa= re/microchip/mpfs-auto-update.c index 078ff328f261..d7ce27f4ba1b 100644 --- a/drivers/firmware/microchip/mpfs-auto-update.c +++ b/drivers/firmware/microchip/mpfs-auto-update.c @@ -9,6 +9,7 @@ * * Author: Conor Dooley */ +#include #include #include #include @@ -233,15 +234,17 @@ static int mpfs_auto_update_verify_image(struct fw_up= load *fw_uploader) return ret; } =20 -static int mpfs_auto_update_set_image_address(struct mpfs_auto_update_priv= *priv, char *buffer, +static int mpfs_auto_update_set_image_address(struct mpfs_auto_update_priv= *priv, u32 image_address, loff_t directory_address) { struct erase_info erase; - size_t erase_size =3D AUTO_UPDATE_DIRECTORY_SIZE; + size_t erase_size =3D round_up(AUTO_UPDATE_DIRECTORY_SIZE, (u64)priv->fla= sh->erasesize); size_t bytes_written =3D 0, bytes_read =3D 0; + char *buffer __free(kfree) =3D kzalloc(erase_size, GFP_KERNEL); int ret; =20 - erase_size =3D round_up(erase_size, (u64)priv->flash->erasesize); + if (!buffer) + return -ENOMEM; =20 erase.addr =3D AUTO_UPDATE_DIRECTORY_BASE; erase.len =3D erase_size; @@ -287,7 +290,7 @@ static int mpfs_auto_update_set_image_address(struct mp= fs_auto_update_priv *priv return ret; =20 if (bytes_written !=3D erase_size) - return ret; + return -EIO; =20 return 0; } @@ -297,7 +300,6 @@ static int mpfs_auto_update_write_bitstream(struct fw_u= pload *fw_uploader, const { struct mpfs_auto_update_priv *priv =3D fw_uploader->dd_handle; struct erase_info erase; - char *buffer; loff_t directory_address =3D AUTO_UPDATE_UPGRADE_DIRECTORY; size_t erase_size =3D AUTO_UPDATE_DIRECTORY_SIZE; size_t bytes_written =3D 0; @@ -313,16 +315,12 @@ static int mpfs_auto_update_write_bitstream(struct fw= _upload *fw_uploader, const image_address =3D AUTO_UPDATE_BITSTREAM_BASE + AUTO_UPDATE_UPGRADE_INDEX * priv->size_per_bitstream; =20 - buffer =3D devm_kzalloc(priv->dev, erase_size, GFP_KERNEL); - if (!buffer) - return -ENOMEM; - /* * For bitstream info, the descriptor is written to a fixed offset, * so there is no need to set the image address. */ if (!is_info) { - ret =3D mpfs_auto_update_set_image_address(priv, buffer, image_address, = directory_address); + ret =3D mpfs_auto_update_set_image_address(priv, image_address, director= y_address); if (ret) { dev_err(priv->dev, "failed to set image address in the SPI directory: %= d\n", ret); return ret; @@ -345,7 +343,7 @@ static int mpfs_auto_update_write_bitstream(struct fw_u= pload *fw_uploader, const dev_info(priv->dev, "Erasing the flash at address (0x%x)\n", image_addres= s); ret =3D mtd_erase(priv->flash, &erase); if (ret) - goto out; + return ret; =20 /* * No parsing etc of the bitstream is required. The system controller @@ -355,19 +353,15 @@ static int mpfs_auto_update_write_bitstream(struct fw= _upload *fw_uploader, const dev_info(priv->dev, "Writing the image to the flash at address (0x%x)\n",= image_address); ret =3D mtd_write(priv->flash, (loff_t)image_address, size, &bytes_writte= n, data); if (ret) - goto out; + return ret; =20 - if (bytes_written !=3D size) { - ret =3D -EIO; - goto out; - } + if (bytes_written !=3D size) + return -EIO; =20 *written =3D bytes_written; dev_info(priv->dev, "Wrote 0x%zx bytes to the flash\n", bytes_written); =20 -out: - devm_kfree(priv->dev, buffer); - return ret; + return 0; } =20 static enum fw_upload_err mpfs_auto_update_write(struct fw_upload *fw_uplo= ader, const u8 *data, --=20 2.43.0 From nobody Sun Feb 8 05:30:22 2026 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 8AD7C15D5CE for ; Wed, 10 Apr 2024 11:58:50 +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=1712750330; cv=none; b=RcFWbliOlLvyetuLEOpgKET+kr59BwBfjtaMpQM1PYP64ITqyIuC+FSHRhdo4b842g/xZRvBqKslVS9Rl35rj2YrB75YdY14axwynW8/Wbh+5k2ncSjWhv0v7g1ATMkRDWt6tPBO2qQvreKctRWKnzM0tkDf4LfNRPB8qsdjQQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712750330; c=relaxed/simple; bh=rZ17Zq2r5GglmuwlVZDKvybg4wn7yP4nbMxcY1IRFwM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SjufJ2FgxBURPdB2sr0OqcNO2DOZTOtaWfP/ULrYrFwc/HbEQ33CfW04c/UzAKTF4laHhvOuqoO7jGQLkddDSaPLBdwfP+CYNjKXTF9lyBj92bAn7JjsJOLitrPoKHSYTamfXroR0Ot239VD0oM75Dvca8JAjWOekx1fWjLSRIA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sYY9z9jc; 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="sYY9z9jc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6690C433F1; Wed, 10 Apr 2024 11:58:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712750330; bh=rZ17Zq2r5GglmuwlVZDKvybg4wn7yP4nbMxcY1IRFwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sYY9z9jcmEO9tTdM8vBgKwQv8FfuqM0s1bASlPyB8S1nbwPNs2+QMU+gpzIG9K6HC 2Yoei5a+E1SBFZ78y6zTcN+ITA/9bl3K7XxPYKRIZPiPFLDy5XUdAcsbVC3anuBBXw g+NR7hD89euUY0/BntKr9OWjSxjn+LOXKXrGj4nLuS5k0jwUFfjQgUesO6PDRxxphQ a8d5GUkxpVC3ipWpreiUrRUym9Jy5U+L6vpZe8L1vdrFfWijsvtTsVC8EPlFaC+KZn PYkDjpWxomEjg3pTnTXGrWq+w6PRuP+vBqEBohOHO9X1C0fdWdpNE21WkD0De6eez0 gLWvdA17qTVsA== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Daire McNamara , Cyril Jean , linux-kernel@vger.kernel.org Subject: [PATCH v1 5/5] firmware: microchip: use scope-based cleanup where possible Date: Wed, 10 Apr 2024 12:58:08 +0100 Message-ID: <20240410-glory-patriot-2d7c7876dcfe@spud> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410-opulently-epic-8654bdac3422@spud> References: <20240410-opulently-epic-8654bdac3422@spud> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3938; i=conor.dooley@microchip.com; h=from:subject:message-id; bh=0WayOjS6Zyrbw3ItGJG9W3xsEKlmQEnuZ+2GI5oj4yg=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDGlidVfT0uZ3P5i5Me39ZkGnq/U8rSpnHH9HVxjqTKkLK 7zx2Uq0o5SFQYyDQVZMkSXxdl+L1Po/Ljuce97CzGFlAhnCwMUpABNxWsHw36v1/Jo7G90V2U+6 XHXk051U6pXF8euz5hb5F0tnHBa5uZqRYefGd3/F2VQYhazl7R5/sHtbK/RP70suW5PTuW4JC3F ndgA= X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Conor Dooley There's a bunch of structs created and freed every time the mailbox is used. Move them to use the scope-based cleanup infrastructure to avoid manually tearing them down. mpfs_auto_update_available() didn't free the memory that it used (albeit it allocated exactly once during probe) so that gets moved over too. Signed-off-by: Conor Dooley --- drivers/firmware/microchip/mpfs-auto-update.c | 59 +++++-------------- 1 file changed, 16 insertions(+), 43 deletions(-) diff --git a/drivers/firmware/microchip/mpfs-auto-update.c b/drivers/firmwa= re/microchip/mpfs-auto-update.c index d7ce27f4ba1b..30de47895b1c 100644 --- a/drivers/firmware/microchip/mpfs-auto-update.c +++ b/drivers/firmware/microchip/mpfs-auto-update.c @@ -175,28 +175,17 @@ static enum fw_upload_err mpfs_auto_update_poll_compl= ete(struct fw_upload *fw_up static int mpfs_auto_update_verify_image(struct fw_upload *fw_uploader) { struct mpfs_auto_update_priv *priv =3D fw_uploader->dd_handle; - struct mpfs_mss_response *response; - struct mpfs_mss_msg *message; - u32 *response_msg; + u32 *response_msg __free(kfree) =3D + kzalloc(AUTO_UPDATE_FEATURE_RESP_SIZE * sizeof(*response_msg), GFP_KERNE= L); + struct mpfs_mss_response *response __free(kfree) =3D + kzalloc(sizeof(struct mpfs_mss_response), GFP_KERNEL); + struct mpfs_mss_msg *message __free(kfree) =3D + kzalloc(sizeof(struct mpfs_mss_msg), GFP_KERNEL); int ret; =20 - response_msg =3D devm_kzalloc(priv->dev, AUTO_UPDATE_FEATURE_RESP_SIZE * = sizeof(response_msg), - GFP_KERNEL); - if (!response_msg) + if (!response_msg || !response || !message) return -ENOMEM; =20 - response =3D devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_response), GF= P_KERNEL); - if (!response) { - ret =3D -ENOMEM; - goto free_response_msg; - } - - message =3D devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_msg), GFP_KERN= EL); - if (!message) { - ret =3D -ENOMEM; - goto free_response; - } - /* * The system controller can verify that an image in the flash is valid. * Rather than duplicate the check in this driver, call the relevant @@ -218,20 +207,12 @@ static int mpfs_auto_update_verify_image(struct fw_up= load *fw_uploader) ret =3D mpfs_blocking_transaction(priv->sys_controller, message); if (ret | response->resp_status) { dev_warn(priv->dev, "Verification of Upgrade Image failed!\n"); - ret =3D ret ? ret : -EBADMSG; - goto free_message; + return ret ? ret : -EBADMSG; } =20 dev_info(priv->dev, "Verification of Upgrade Image passed!\n"); =20 -free_message: - devm_kfree(priv->dev, message); -free_response: - devm_kfree(priv->dev, response); -free_response_msg: - devm_kfree(priv->dev, response_msg); - - return ret; + return 0; } =20 static int mpfs_auto_update_set_image_address(struct mpfs_auto_update_priv= *priv, @@ -406,23 +387,15 @@ static const struct fw_upload_ops mpfs_auto_update_op= s =3D { =20 static int mpfs_auto_update_available(struct mpfs_auto_update_priv *priv) { - struct mpfs_mss_response *response; - struct mpfs_mss_msg *message; - u32 *response_msg; + u32 *response_msg __free(kfree) =3D + kzalloc(AUTO_UPDATE_FEATURE_RESP_SIZE * sizeof(*response_msg), GFP_KERNE= L); + struct mpfs_mss_response *response __free(kfree) =3D + kzalloc(sizeof(struct mpfs_mss_response), GFP_KERNEL); + struct mpfs_mss_msg *message __free(kfree) =3D + kzalloc(sizeof(struct mpfs_mss_msg), GFP_KERNEL); int ret; =20 - response_msg =3D devm_kzalloc(priv->dev, - AUTO_UPDATE_FEATURE_RESP_SIZE * sizeof(*response_msg), - GFP_KERNEL); - if (!response_msg) - return -ENOMEM; - - response =3D devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_response), GF= P_KERNEL); - if (!response) - return -ENOMEM; - - message =3D devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_msg), GFP_KERN= EL); - if (!message) + if (!response_msg || !response || !message) return -ENOMEM; =20 /* --=20 2.43.0