[PATCH v2 19/39] read: Use map_sysmem() with buffers in the read command
Ilias Apalodimas
ilias.apalodimas at linaro.org
Thu Aug 8 12:20:47 CEST 2024
On Tue, 6 Aug 2024 at 15:59, Simon Glass <sjg at chromium.org> wrote:
>
> The current implementation casts an address to a pointer. Make it more
> sandbox-friendly by using map_sysmem().
Isn't the code already using map_sysmem? All I see is some fixes for
unmapping it and a rename
>
> Rename the variable to 'ptr' since it is a pointer, not an address.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> (no changes since v1)
>
> cmd/read.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/cmd/read.c b/cmd/read.c
> index af54bd17654..8e21f004423 100644
> --- a/cmd/read.c
> +++ b/cmd/read.c
> @@ -20,7 +20,7 @@ do_rw(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> struct disk_partition part_info;
> ulong offset, limit;
> uint blk, cnt, res;
> - void *addr;
> + void *ptr;
> int part;
>
> if (argc != 6) {
> @@ -33,7 +33,7 @@ do_rw(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> if (part < 0)
> return 1;
>
> - addr = map_sysmem(hextoul(argv[3], NULL), 0);
> + ptr = map_sysmem(hextoul(argv[3], NULL), 0);
> blk = hextoul(argv[4], NULL);
> cnt = hextoul(argv[5], NULL);
>
> @@ -48,13 +48,15 @@ do_rw(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
>
> if (cnt + blk > limit) {
> printf("%s out of range\n", cmdtp->name);
> + unmap_sysmem(ptr);
> return 1;
> }
>
> if (IS_ENABLED(CONFIG_CMD_WRITE) && !strcmp(cmdtp->name, "write"))
> - res = blk_dwrite(dev_desc, offset + blk, cnt, addr);
> + res = blk_dwrite(dev_desc, offset + blk, cnt, ptr);
> else
> - res = blk_dread(dev_desc, offset + blk, cnt, addr);
> + res = blk_dread(dev_desc, offset + blk, cnt, ptr);
> + unmap_sysmem(ptr);
>
> if (res != cnt) {
> printf("%s error\n", cmdtp->name);
> --
> 2.34.1
>
More information about the U-Boot
mailing list