diff mbox series

spl: fit: Skip attempting to load 0 length image

Message ID 20211019173229.16200-1-nm@ti.com
State Accepted
Commit 6d99f866952bb5df7fe699b3db29a97d75e5c445
Delegated to: Tom Rini
Headers show
Series spl: fit: Skip attempting to load 0 length image | expand

Commit Message

Nishanth Menon Oct. 19, 2021, 5:32 p.m. UTC
When, for various reasons, a bad FIT image is used where a loadable
image is marked as 0 length, attempt is made for a 0 length allocation and
read of 0 byte read operation.

Instead provide warning in log and skip attempting to do such a load.

Signed-off-by: Nishanth Menon <nm@ti.com>
---
 common/spl/spl_fit.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Aswath Govindraju Oct. 20, 2021, 5:12 a.m. UTC | #1
On 19/10/21 11:02 pm, Nishanth Menon wrote:
> When, for various reasons, a bad FIT image is used where a loadable
> image is marked as 0 length, attempt is made for a 0 length allocation and
> read of 0 byte read operation.
> 
> Instead provide warning in log and skip attempting to do such a load.
> 
> Signed-off-by: Nishanth Menon <nm@ti.com>
> ---

Reviewed-by: Aswath Govindraju <a-govindraju@ti.com>

Thanks,
Aswath

>  common/spl/spl_fit.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
> index f41abca0ccb5..e9540dc2167a 100644
> --- a/common/spl/spl_fit.c
> +++ b/common/spl/spl_fit.c
> @@ -286,6 +286,13 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
>  		if (fit_image_get_data_size(fit, node, &len))
>  			return -ENOENT;
>  
> +		/* Dont bother to copy 0 byte data, but warn, though */
> +		if (!len) {
> +			log_warning("%s: Skip load '%s': image size is 0!\n",
> +				    __func__, fit_get_name(fit, node, NULL));
> +			return 0;
> +		}
> +
>  		src_ptr = map_sysmem(ALIGN(load_addr, ARCH_DMA_MINALIGN), len);
>  		length = len;
>  
>
Tom Rini Dec. 2, 2021, 12:14 p.m. UTC | #2
On Tue, Oct 19, 2021 at 12:32:29PM -0500, Nishanth Menon wrote:

> When, for various reasons, a bad FIT image is used where a loadable
> image is marked as 0 length, attempt is made for a 0 length allocation and
> read of 0 byte read operation.
> 
> Instead provide warning in log and skip attempting to do such a load.
> 
> Signed-off-by: Nishanth Menon <nm@ti.com>
> Reviewed-by: Aswath Govindraju <a-govindraju@ti.com>

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index f41abca0ccb5..e9540dc2167a 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -286,6 +286,13 @@  static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
 		if (fit_image_get_data_size(fit, node, &len))
 			return -ENOENT;
 
+		/* Dont bother to copy 0 byte data, but warn, though */
+		if (!len) {
+			log_warning("%s: Skip load '%s': image size is 0!\n",
+				    __func__, fit_get_name(fit, node, NULL));
+			return 0;
+		}
+
 		src_ptr = map_sysmem(ALIGN(load_addr, ARCH_DMA_MINALIGN), len);
 		length = len;