[Pdbg] [PATCH v3 2/4] libpdbg: Handle properties defined on virtual targets correctly

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


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

On Wednesday, 4 March 2020 2:19:11 PM AEDT Amitay Isaacs wrote:
> Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
> ---
>  libpdbg/device.c | 49 +++++++++++++++++++++++++++++++-----------------
>  1 file changed, 32 insertions(+), 17 deletions(-)
> 
> diff --git a/libpdbg/device.c b/libpdbg/device.c
> index 48f2c58..cd8a459 100644
> --- a/libpdbg/device.c
> +++ b/libpdbg/device.c
> @@ -321,17 +321,41 @@ static void dt_add_phandle(struct pdbg_target *node,
> const char *name, }
>  }
> 
> +static const void *_target_property(struct pdbg_target *target, const char
> *name, size_t *size) +{
> +	const void *buf;
> +	int buflen;
> +
> +	if (target->fdt_offset == -1) {
> +		size ? *size = 0 : 0;
> +		return NULL;
> +	}
> +
> +	buf = fdt_getprop(target->fdt, target->fdt_offset, name, &buflen);
> +	if (!buf) {
> +		size ? *size = 0 : 0;
> +		return NULL;
> +	}
> +
> +	size ? *size = buflen : 0;
> +	return buf;
> +}
> +
>  bool pdbg_target_set_property(struct pdbg_target *target, const char *name,
> const void *val, size_t size) {
>  	const void *p;
>  	size_t len;
>  	int ret;
> 
> -	if (!target->fdt || !pdbg_fdt_is_writeable(target->fdt))
> +	p = _target_property(target, name, &len);
> +	if (!p && target->vnode) {
> +		target = target->vnode;
> +		p = _target_property(target, name, &len);
> +	}
> +	if (!p)
>  		return false;
> 
> -	p = pdbg_target_property(target, name, &len);
> -	if (!p)
> +	if (!target->fdt || !pdbg_fdt_is_writeable(target->fdt))
>  		return false;
> 
>  	if (len != size)
> @@ -346,22 +370,13 @@ bool pdbg_target_set_property(struct pdbg_target
> *target, const char *name, cons
> 
>  const void *pdbg_target_property(struct pdbg_target *target, const char
> *name, size_t *size) {
> -	const void *buf;
> -	int buflen;
> -
> -	if (target->fdt_offset == -1) {
> -		size ? *size = 0 : 0;
> -		return NULL;
> -	}
> +	const void *p;
> 
> -	buf = fdt_getprop(target->fdt, target->fdt_offset, name, &buflen);
> -	if (!buf) {
> -		size ? *size = 0 : 0;
> -		return NULL;
> -	}
> +	p = _target_property(target, name, size);
> +	if (!p && target->vnode)
> +		p = _target_property(target->vnode, name, size);
> 
> -	size ? *size = buflen : 0;
> -	return buf;
> +	return p;
>  }
> 
>  static u32 dt_property_get_cell(const void *prop, size_t len, u32 index)






More information about the Pdbg mailing list