[Pdbg] [PATCH v3 4/4] libpdbg: Improve the logic to check if fdt is writable

Alistair Popple alistair at popple.id.au
Wed Mar 4 14:35:40 AEDT 2020


Reviewed-by: Alistair Popple <alistair at popple.id.au>

On Wednesday, 4 March 2020 2:19:13 PM AEDT Amitay Isaacs wrote:
> Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
> ---
>  libpdbg/device.c |  2 +-
>  libpdbg/dtb.c    | 24 +++++++++---------------
>  libpdbg/target.h |  3 ++-
>  3 files changed, 12 insertions(+), 17 deletions(-)
> 
> diff --git a/libpdbg/device.c b/libpdbg/device.c
> index cd8a459..604cddb 100644
> --- a/libpdbg/device.c
> +++ b/libpdbg/device.c
> @@ -355,7 +355,7 @@ bool pdbg_target_set_property(struct pdbg_target
> *target, const char *name, cons if (!p)
>  		return false;
> 
> -	if (!target->fdt || !pdbg_fdt_is_writeable(target->fdt))
> +	if (!target->fdt || pdbg_fdt_is_readonly(target->fdt))
>  		return false;
> 
>  	if (len != size)
> diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c
> index 57502c1..35923b0 100644
> --- a/libpdbg/dtb.c
> +++ b/libpdbg/dtb.c
> @@ -63,10 +63,12 @@ static struct pdbg_dtb pdbg_dtb = {
>  	.backend = {
>  		.fd = -1,
>  		.len = -1,
> +		.readonly = true,
>  	},
>  	.system = {
>  		.fd = -1,
>  		.len = -1,
> +		.readonly = true,
>  	},
>  };
> 
> @@ -270,6 +272,7 @@ static void mmap_dtb(char *file, bool readonly, struct
> pdbg_mfile *mfile) .fd = fd,
>  		.len = statbuf.st_size,
>  		.fdt = dtb,
> +		.readonly = readonly,
>  	};
>  	return;
> 
> @@ -408,24 +411,15 @@ done:
>  	return dtb;
>  }
> 
> -static bool is_fdt_mapped(void *fdt, struct pdbg_mfile *mfile)
> +bool pdbg_fdt_is_readonly(void *fdt)
>  {
> -	if (mfile->fdt == fdt && mfile->fd != -1 && mfile->len != -1) {
> -		return true;
> -	}
> -
> -	return false;
> -}
> +	if (pdbg_dtb.system.fdt == fdt)
> +		return pdbg_dtb.system.readonly;
> 
> -bool pdbg_fdt_is_writeable(void *fdt)
> -{
> -	bool ok;
> -
> -	ok = is_fdt_mapped(fdt, &pdbg_dtb.system);
> -	if (!ok)
> -		ok = is_fdt_mapped(fdt, &pdbg_dtb.backend);
> +	if (pdbg_dtb.backend.fdt == fdt)
> +		return pdbg_dtb.backend.readonly;
> 
> -	return ok;
> +	return true;
>  }
> 
>  static void close_dtb(struct pdbg_mfile *mfile)
> diff --git a/libpdbg/target.h b/libpdbg/target.h
> index fffdc49..3b74844 100644
> --- a/libpdbg/target.h
> +++ b/libpdbg/target.h
> @@ -60,6 +60,7 @@ struct pdbg_mfile {
>  	int fd;
>  	ssize_t len;
>  	void *fdt;
> +	bool readonly;
>  };
> 
>  struct pdbg_dtb {
> @@ -80,7 +81,7 @@ extern struct list_head target_classes;
> 
>  struct pdbg_dtb *pdbg_default_dtb(void *system_fdt);
>  const char *pdbg_get_backend_option(void);
> -bool pdbg_fdt_is_writeable(void *fdt);
> +bool pdbg_fdt_is_readonly(void *fdt);
> 
>  struct chipop *pib_to_chipop(struct pdbg_target *target);
>  bool target_is_virtual(struct pdbg_target *target);






More information about the Pdbg mailing list