Re: [PATCH v2 2/4] srcpos: Define srcpos_free

David Gibson <[email protected]>
Newsgroups org.kernel.vger.devicetree-compiler
Message-ID <aDacGNbvxcxI8SrS@zatzit>
On Tue, Mar 11, 2025 at 09:05:38PM +0530, Ayush Singh wrote:
> srcpos can be chained together using srcpos_extend. However, in such
> cases, we need to free all the chained nodes.
> 
> srcpos_free is a helper to recursively free all the linked srcpos.
> 
> Signed-off-by: Ayush Singh <[email protected]>

This should also _use_ the new function in any existing places it make
sense.  On a quick glance I can only see one such place, in
merge_nodes() where we use a plain free() on the srcpos info of an
overwritten property.

> ---
>  srcpos.c | 11 +++++++++++
>  srcpos.h |  1 +
>  2 files changed, 12 insertions(+)
> 
> diff --git a/srcpos.c b/srcpos.c
> index 5e2f7dd299184ff86b00b280dc31498cb9830e28..5bb57bf6856c6ff6b8eb993aff5d216c63bf5ecb 100644
> --- a/srcpos.c
> +++ b/srcpos.c
> @@ -287,6 +287,17 @@ struct srcpos *srcpos_extend(struct srcpos *pos, struct srcpos *newtail)
>  	return pos;
>  }
>  
> +void srcpos_free(struct srcpos *pos)
> +{
> +	struct srcpos *p_next;
> +
> +	while (pos) {
> +		p_next = pos->next;
> +		free(pos);
> +		pos = p_next;
> +	}
> +}
> +
>  char *
>  srcpos_string(struct srcpos *pos)
>  {
> diff --git a/srcpos.h b/srcpos.h
> index 4318d7ad34d91d2ada1a5d7f92d2c84148fec366..4d60b50e31197c2da6a7fa8851c5e5a6717d78a6 100644
> --- a/srcpos.h
> +++ b/srcpos.h
> @@ -88,6 +88,7 @@ extern void srcpos_update(struct srcpos *pos, const char *text, int len);
>  extern struct srcpos *srcpos_copy(struct srcpos *pos);
>  extern struct srcpos *srcpos_extend(struct srcpos *new_srcpos,
>  				    struct srcpos *old_srcpos);
> +extern void srcpos_free(struct srcpos *pos);
>  extern char *srcpos_string(struct srcpos *pos);
>  extern char *srcpos_string_first(struct srcpos *pos, int level);
>  extern char *srcpos_string_last(struct srcpos *pos, int level);
> 

-- 
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+dNsU4E3yXUXRK2zQJF27ox2GcFAmg2nBgACgkQzQJF27ox
2Gclww//Xm3O8mO3IlPlbn+tpWEDMM9z2UWFiAcl7gIxJvShHJUTyY91nxQ13KR6
xXI/UJPwf1uKeJPCNNFQWozVn9yp7PbGr4SpJNN46abG0fby8aAQzCjmnS+uQeZo
X+/UbKs0y7yg5M3f/wlxhlvMVN3VkghHrD2sPWA34XCVfJBBzSx1+fDlp2Mzo/kt
6EXO1Y8x2nS4+McYhyuYXh4EFrEMaysOn7tjrD0fsrOvEa2kOpY0ZjQ9NoGjzo6Q
RbYAdi4QZ8rWjv3HXP3YoL9V9R7EwSYLlyJpAZi1hMOZh97WlpSoqCtpXMBj1uwT
YsL6kvHAcTCXDWNWv/pmwrCUlGa689bdZPsXLLo7DQ9G1YpB5zvrze3/8yq/R/iY
FTEvllJ0M6z2VWwvUB7FAF3zcoeeEXrpWhiZnl2AHXumMftccR4StdgySSrVrje2
o3qtLAEPGejhq64iSU3XlrjrXporciKkqTcV7Olb+hizSz6WjFPM9Zkgyo30JLPX
dfas0vWw+bpD/msWrdKzCT8g5u2Eg2UFP/a+lJeq+EMu+qigk0perdWs8ElzZUo3
CvAk3fhLXIH998TaxlyrwvSAl/gczNjuVkOPW2A1Wn/U2EVJt135igjOMLMmFpl0
2afMdI2TAUH8ivCtEvxVTXpCEG5yUfnbsq4YUYIiPPjBapUme78=
=sUiU
-----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.