diff options
| author | Anton Ivanov <[email protected]> | 2026-09-02 22:23:23 +0100 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-09-04 12:22:06 -0600 |
| commit | c4d81d062790c76ef0db4ead2ac69cab7245c2fc (patch) | |
| tree | 16684132acefea01d8f825e0e3b3fad1c2dc4a9d /boot | |
| parent | 94b349bd902d9e38e1846c157fadd9054c34680a (diff) | |
image-fit: Use unsigned types for external data properties
The data-offset, data-position and data-size FIT properties are
stored as 32-bit unsigned values (fdt32_t), but the accessors
fit_image_get_data_offset(), fit_image_get_data_position() and
fit_image_get_data_size() return them through a signed int.
Switch the accessors and their callers to u32. This removes the
special processing of "negative" values in fit_image_get_data().
Signed-off-by: Anton Ivanov <[email protected]>
Reviewed-by: Simon Glass <[email protected]>
Diffstat (limited to 'boot')
| -rw-r--r-- | boot/image-fit.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/boot/image-fit.c b/boot/image-fit.c index ef90c5abd18..26e9323da06 100644 --- a/boot/image-fit.c +++ b/boot/image-fit.c @@ -963,7 +963,7 @@ int fit_image_get_emb_data(const void *fit, int noffset, const void **data, * 0, on success * -ENOENT if the property could not be found */ -int fit_image_get_data_offset(const void *fit, int noffset, int *data_offset) +int fit_image_get_data_offset(const void *fit, int noffset, u32 *data_offset) { const fdt32_t *val; @@ -988,7 +988,7 @@ int fit_image_get_data_offset(const void *fit, int noffset, int *data_offset) * -ENOENT if the property could not be found */ int fit_image_get_data_position(const void *fit, int noffset, - int *data_position) + u32 *data_position) { const fdt32_t *val; @@ -1012,7 +1012,7 @@ int fit_image_get_data_position(const void *fit, int noffset, * 0, on success * -ENOENT if the property could not be found */ -int fit_image_get_data_size(const void *fit, int noffset, int *data_size) +int fit_image_get_data_size(const void *fit, int noffset, u32 *data_size) { const fdt32_t *val; @@ -1070,18 +1070,13 @@ int fit_image_get_data(const void *fit, int noffset, const void **data, size_t *size) { bool external_data = false; - int offset; - int len; int ret; size_t fdt_total_size_aligned; + u32 offset; + u32 len; uintptr_t max_offset; if (!fit_image_get_data_position(fit, noffset, &offset)) { - if (offset < 0) { - printf("Invalid external data position: %d\n", offset); - return -EINVAL; - } - external_data = true; } else if (!fit_image_get_data_offset(fit, noffset, &offset)) { /* @@ -1090,9 +1085,9 @@ int fit_image_get_data(const void *fit, int noffset, const void **data, * for the data-offset properties in each image. */ fdt_total_size_aligned = ((fdt_totalsize(fit) + 3) & ~3); - /* The resulting offset cannot exceed INT_MAX */ - if (offset < 0 || fdt_total_size_aligned > INT_MAX - offset) { - printf("Invalid external data offset: %d\n", offset); + /* The resulting offset cannot exceed UINT32_MAX */ + if (fdt_total_size_aligned > UINT32_MAX - offset) { + printf("Invalid external data offset: %u\n", offset); return -EINVAL; } offset += fdt_total_size_aligned; @@ -1106,16 +1101,12 @@ int fit_image_get_data(const void *fit, int noffset, const void **data, max_offset = UINTPTR_MAX - (uintptr_t)fit; /* Check that external data offset is within the addressable range */ if (offset > max_offset) { - printf("Invalid external data offset: %d\n", offset); + printf("Invalid external data offset: %u\n", offset); return -EINVAL; } ret = fit_image_get_data_size(fit, noffset, &len); if (!ret) { - if (len < 0) { - printf("Invalid external data size: %d\n", len); - return -EINVAL; - } /* * For non-signed FIT images, we can only check that * (offset + len) doesn't exceed the addressable range. @@ -1135,7 +1126,7 @@ int fit_image_get_data(const void *fit, int noffset, const void **data, len > CONFIG_VAL(FIT_SIGNATURE_MAX_SIZE) - offset #endif ) { - printf("FIT external data is out of bounds (offset=%d, size=%d)\n", + printf("FIT external data is out of bounds (offset=%u, size=%u)\n", offset, len); return -EINVAL; } |
