[v4,5/5] misc: fw_loader: implement request_firmware_size() OP
Simon Glass
sjg at chromium.org
Thu Apr 2 01:27:24 CEST 2026
Hi Christian,
On 2026-03-31T07:53:19, Christian Marangi <ansuelsmth at gmail.com> wrote:
> misc: fw_loader: implement request_firmware_size() OP
> misc: fw_loader: implement request_firmware_size() OP
>
> It might be useful to get the firmware size before reading it to allocate
> the correct size. This is needed for case where the firmware size change
> across different firmware version and is not always the same. In such case
> the only way to handle this scenario is to allocate a big-enough buffer to
> read the firmware.
>
> To better handle this, introduce the request_firmware_size() OP to get the
> firmware size before reading it. This way proper buffer can be allocated
> and dynamic firmware size can be better supported.
>
> Both FS and FIP lodaer are updated to handle the new .get_size() handler.
>
> Signed-off-by: Christian Marangi <ansuelsmth at gmail.com>
> diff --git a/drivers/misc/fw_loader/fs_loader.c b/drivers/misc/fw_loader/fs_loader.c
> @@ -92,15 +92,8 @@ static int select_fs_dev(struct device_plat *plat)
> +static int fw_get_filesystem_firmware_size(struct udevice *dev)
> +{
> + loff_t size = 0;
> + int ret;
> +
> + ret = __fw_get_filesystem_firmware_prepare(dev);
> + if (ret)
> + goto out;
> +
> + struct firmware *firmwarep = dev_get_priv(dev);
> +
> + if (!firmwarep)
> + return -ENOMEM;
This returns -ENOMEM directly without calling
__fw_get_filesystem_firmware_release(), leaking the UBIFS mount. The
existing fw_get_filesystem_firmware() does this correctly by using
'goto out'. Please can you fix this to go to out instead?
> diff --git a/drivers/misc/fw_loader/fip_loader.c b/drivers/misc/fw_loader/fip_loader.c
> @@ -495,6 +495,34 @@ static int fw_get_fip_firmware(struct udevice *dev)
> +static int fw_get_fip_firmware_size(struct udevice *dev)
> +{
> + struct fip_toc_entry ent;
> + struct fip_storage_info info = { };
> + int ret;
> +
> + ret = fw_parse_storage_info(dev, &info);
> + if (ret)
> + return ret;
> +
> + struct firmware *firmwarep = dev_get_priv(dev);
Please move the declaration of firmwarep to the top with the other declarations.
> diff --git a/drivers/misc/fw_loader/fs_loader.c b/drivers/misc/fw_loader/fs_loader.c
> + struct firmware *firmwarep = dev_get_priv(dev);
> +
> + if (!firmwarep)
> + return -ENOMEM;
Same here - please move the declaration to the top of the function.
> misc: fw_loader: implement request_firmware_size() OP
>
> Both FS and FIP lodaer are updated to handle the new .get_size() handler.
Typo "lodaer"
Regards,
Simon
More information about the U-Boot
mailing list