* [PATCH] tools: ftdgrep: correct the find regions loop in do_fdtgrep
@ 2020-01-10 7:50 Patrick Delaunay
2020-01-12 19:51 ` Anatolij Gustschin
0 siblings, 1 reply; 3+ messages in thread
From: Patrick Delaunay @ 2020-01-10 7:50 UTC (permalink / raw)
To: u-boot
Update the loop executed in do_fdtgrep to find all the regions
and add a test for count > max_region only when the second passes
is executed.
This patch solve an issue if the number of region found (count)
is greater then the default value (max_region = count = 100):
the second pass is never executed, because the loop stops after
the first pass (i = 0, count > 100, max_regions = 100)
with error -1 and the error message
"Internal error with fdtgrep_find_region".
I also update the error message.
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
---
tools/fdtgrep.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c
index 8f44f599c1..bcf06b871d 100644
--- a/tools/fdtgrep.c
+++ b/tools/fdtgrep.c
@@ -823,8 +823,10 @@ static int do_fdtgrep(struct display_info *disp, const char *filename)
}
if (count <= max_regions)
break;
+ }
+ if (count > max_regions) {
free(region);
- fprintf(stderr, "Internal error with fdtgrep_find_region)(\n");
+ fprintf(stderr, "Internal error with fdtgrep_find_region()\n");
return -1;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH] tools: ftdgrep: correct the find regions loop in do_fdtgrep
2020-01-10 7:50 [PATCH] tools: ftdgrep: correct the find regions loop in do_fdtgrep Patrick Delaunay
@ 2020-01-12 19:51 ` Anatolij Gustschin
2020-01-13 8:24 ` Patrick DELAUNAY
0 siblings, 1 reply; 3+ messages in thread
From: Anatolij Gustschin @ 2020-01-12 19:51 UTC (permalink / raw)
To: u-boot
Hi Patrick,
On Fri, 10 Jan 2020 08:50:31 +0100
Patrick Delaunay patrick.delaunay at st.com wrote:
...
> diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c
> index 8f44f599c1..bcf06b871d 100644
> --- a/tools/fdtgrep.c
> +++ b/tools/fdtgrep.c
> @@ -823,8 +823,10 @@ static int do_fdtgrep(struct display_info *disp, const char *filename)
> }
> if (count <= max_regions)
> break;
> + }
> + if (count > max_regions) {
> free(region);
This change moved free(region) out of the loop. If you do so, then
please also change malloc() in the loop to realloc():
region = realloc(region, count * sizeof(struct fdt_region));
--
Anatolij
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH] tools: ftdgrep: correct the find regions loop in do_fdtgrep
2020-01-12 19:51 ` Anatolij Gustschin
@ 2020-01-13 8:24 ` Patrick DELAUNAY
0 siblings, 0 replies; 3+ messages in thread
From: Patrick DELAUNAY @ 2020-01-13 8:24 UTC (permalink / raw)
To: u-boot
Hi,
> From: Anatolij Gustschin <agust@denx.de>
> Sent: dimanche 12 janvier 2020 20:51
>
> Hi Patrick,
>
> On Fri, 10 Jan 2020 08:50:31 +0100
> Patrick Delaunay patrick.delaunay at st.com wrote:
> ...
> > diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index
> > 8f44f599c1..bcf06b871d 100644
> > --- a/tools/fdtgrep.c
> > +++ b/tools/fdtgrep.c
> > @@ -823,8 +823,10 @@ static int do_fdtgrep(struct display_info *disp, const
> char *filename)
> > }
> > if (count <= max_regions)
> > break;
> > + }
> > + if (count > max_regions) {
> > free(region);
>
> This change moved free(region) out of the loop. If you do so, then please also
> change malloc() in the loop to realloc():
>
> region = realloc(region, count * sizeof(struct fdt_region));
Yes, I will push V2 with realloc to avoid the memory leak that I introduced..
Thanks for review
> --
> Anatolij
Patrick
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-01-13 8:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-10 7:50 [PATCH] tools: ftdgrep: correct the find regions loop in do_fdtgrep Patrick Delaunay
2020-01-12 19:51 ` Anatolij Gustschin
2020-01-13 8:24 ` Patrick DELAUNAY
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox