tools: ftdgrep: correct the find regions loop in do_fdtgrep
PATCH 1/1 tools: ftdgrep: correct the find regions loop in do_fdtgrep
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.
---
tools/fdtgrep.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/fdtgrep.c +3 -1
@@ -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 ; }
Signature · 1 line
2.17.1
PATCH 1/1 tools: ftdgrep: correct the find regions loop in do_fdtgrep
Hi Patrick,
On Fri, 10 Jan 2020 08:50:31 +0100
Patrick Delaunay patrick.delaunay at st.com wrote:
...
tools/fdtgrep.c static int do_fdtgrep(struct display_info *disp, const char *filename) · line 828
Quoted 11 lines
tools/fdtgrep.c +2
-0@@ -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
PATCH 1/1 tools: ftdgrep: correct the find regions loop in do_fdtgrep
Hi,
Quoted 24 lines
From: Anatolij Gustschin <[email protected]>
Sent: dimanche 12 janvier 2020 20:51Hi Patrick,
On Fri, 10 Jan 2020 08:50:31 +0100
Patrick Delaunay patrick.delaunay at st.com wrote:
...tools/fdtgrep.c static int do_fdtgrep(struct display_info *disp, const
Quoted 5 lines
tools/fdtgrep.c index renamed from tools/fdtgrep.c +0
-0
8f44f599c1..bcf06b871d100644tools/fdtgrep.c +0
-0@@ -823,8 +823,10 @@ static int do_fdtgrep(struct display_info *disp, constchar *filename)
tools/fdtgrep.c static int do_fdtgrep(struct display_info *disp, const char *filename) · line 828
Quoted 6 lines
tools/fdtgrep.c +2
-0}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 torealloc():
Quoted 1 line
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
Quoted 2 lines
--
Anatolij
Patrick