From nobody Mon Feb 9 10:27:55 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