Re: [PATCH v3 2/4] dtc: Add data_insert_data function

David Gibson <[email protected]>
Newsgroups org.kernel.vger.devicetree-compiler
Message-ID <aEqyQ1scjqvq1NVF@zatzit>
On Thu, Jun 05, 2025 at 04:18:07PM +0530, Ayush Singh wrote:
> Add helper function to insert a data struct into another.

Applied, thanks.

> 
> Signed-off-by: Ayush Singh <[email protected]>
> ---
>  data.c | 27 +++++++++++++++++++++++++++
>  dtc.h  |  1 +
>  2 files changed, 28 insertions(+)
> 
> diff --git a/data.c b/data.c
> index 913796f2e664d07cdc48e0cbf2ab5d6fe9978072..5b25aa060416134be430aebe33c9cce49515297f 100644
> --- a/data.c
> +++ b/data.c
> @@ -251,6 +251,33 @@ bool data_is_one_string(struct data d)
>  	return true;
>  }
>  
> +struct data data_insert_data(struct data d, struct marker *m, struct data old)
> +{
> +	unsigned int offset = m->offset;
> +	struct marker *next = m->next;
> +	struct marker *marker;
> +	struct data new_data;
> +	char *ref;
> +
> +	new_data = data_insert_at_marker(d, m, old.val, old.len);
> +
> +	/* Copy all markers from old value */
> +	marker = old.markers;
> +	for_each_marker(marker) {
> +		ref = NULL;
> +
> +		if (marker->ref)
> +			ref = xstrdup(marker->ref);
> +
> +		m->next = alloc_marker(marker->offset + offset, marker->type,
> +				       ref);
> +		m = m->next;
> +	}
> +	m->next = next;
> +
> +	return new_data;
> +}
> +
>  struct marker *alloc_marker(unsigned int offset, enum markertype type,
>  			    char *ref)
>  {
> diff --git a/dtc.h b/dtc.h
> index bd803397449a4b71ff89944ea125cefb96c4dd21..3a220b9afc99f92ea57d50d348eb0872bc779818 100644
> --- a/dtc.h
> +++ b/dtc.h
> @@ -182,6 +182,7 @@ struct data data_append_addr(struct data d, uint64_t addr);
>  struct data data_append_byte(struct data d, uint8_t byte);
>  struct data data_append_zeroes(struct data d, int len);
>  struct data data_append_align(struct data d, int align);
> +struct data data_insert_data(struct data d, struct marker *m, struct data old);
>  
>  struct marker *alloc_marker(unsigned int offset, enum markertype type,
>  			    char *ref);
> 

-- 
David Gibson (he or they)	| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you, not the other way
				| around.
http://www.ozlabs.org/~dgibson
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmhKsjwACgkQzQJF27ox
2GcaNg//VwXIZ5iUVfsVvTvbDADYkkoVlFDEKoyA/diD6fXnrc8/77JbaLoKZPwR
lhVPZx9j9PGgvlgingMondw5rtaTY3+x3if/3weBS2t2qu3vpipvi0YoxGsHfFPV
BgNyXAOfM7h2lEJzzBnpdiESSfQA+CT7vEVrjJqT306ymBLJB3j7GpwMJDyqvDcW
s28eD9wNWeIN0zhaThuRAiwRdd33YiNeJeoXobGI4XdARYN91Z0zsnfaGUvDoWhs
CWBjcqMBM8u+z21FUssC59uKTY2xupVfsJs8m0iame2+uzMcyVyGsSCPtGJ2+Q4L
5FYcTV57woRoQ8AlYNE7h5xd/CarLbCcXZf3kyc+YqROcwGglqVK6o8/4bnm0g48
QX5RiR2fEcQ1oAzIvkUjOHSJ/pfABF5CQeyY5q7WyMe0JBmCkG1JRhcIQD6X0ctd
XGSsiPEq6p4qFi+tclGL8KNCtFB59jZpne5RZnDPIMhneYx8zsTJd67SLAyX5qqp
51G3hVxmSoP5FS1Z4U2vtbeouH0bHry297Q/qC04IIa0E41MlYWoQURqLZEGmzx/
yK6iBGaR0Hc6Xd2/YBPpMfSj+Dl8SQpQuLRfTfdHsj7JDA2ZtWx8Xp/NTcz7V5n/
SRWIV/0f8nJKDy1BaI8RDPh4iLkVgAn/ZFjc4Ek4m6t9HRxewUs=
=ou4A
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.