of: overlay: Miscellaneous improvements
cover of: overlay: Miscellaneous improvements
Hi,
While performing the long-overdue rebase of my topic/overlays branch[1] on top of the overlay rework in v5.19-rc1, I identified a few areas for improvement in the upstream code.
Thanks for your comments!
[1] https://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git/log/?h=topic/overlays
Geert Uytterhoeven (2):
of: overlay: Move devicetree_corrupt() check up
of: overlay: Simplify of_overlay_fdt_apply() tail
drivers/of/overlay.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
Signature · 12 lines
2.25.1
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus TorvaldsPATCH 1/2 of: overlay: Move devicetree_corrupt() check up
There is no point in doing several preparatory steps in of_overlay_fdt_apply(), only to see of_overlay_apply() return early because of a corrupt device tree.
Move the check for a corrupt device tree from of_overlay_apply() to of_overlay_fdt_apply(), to check for this as early as possible.
--- drivers/of/overlay.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/of/overlay.c +5 -6
@@ -903,12 +903,6 @@ static int of_overlay_apply(struct overlay_changeset *ovcs) {int ret =0 , ret_revert, ret_tmp; -if (devicetree_corrupt ()) { -pr_err ("devicetree state suspect, refuse to apply overlay\n" ); - ret = -EBUSY ; - goto out; - } - ret =of_resolve_phandles (ovcs->overlay_root);if (ret) goto out;
@@ -983,6 +977,11 @@ int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, *ret_ovcs_id =0 ; +if (devicetree_corrupt ()) { +pr_err ("devicetree state suspect, refuse to apply overlay\n" ); +return -EBUSY ; + } +if (overlay_fdt_size <sizeof (struct fdt_header ) ||fdt_check_header (overlay_fdt)) {pr_err ("Invalid overlay_fdt header\n" );
Signature · 1 line
2.25.1
Re: [PATCH 1/2] of: overlay: Move devicetree_corrupt() check up
Quoted 4 lines · Geert Uytterhoeven
There is no point in doing several preparatory steps in
of_overlay_fdt_apply(), only to seeof_overlay_apply()return early because of a corrupt device tree.
Quoted 8 lines
Move the check for a corrupt device tree from
of_overlay_apply()toof_overlay_fdt_apply(), to check for this as early as possible.Signed-off-by Geert Uytterhoeven <[email protected]>--- drivers/of/overlay.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
Applied, thanks!
PATCH 2/2 of: overlay: Simplify of_overlay_fdt_apply() tail
In reply to Geert UytterhoevenIt does not hurt to fill in the changeset id while the mutex is still held. After doing so, the function tails for the success and failure cases become identical, so they can be unified.
--- drivers/of/overlay.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/of/overlay.c +2 -7
@@ -1043,20 +1043,15 @@ int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size,* goto err_free_ovcs. Instead, the caller of of_overlay_fdt_apply() * can call of_overlay_remove(); */ - -mutex_unlock (&of_mutex); -of_overlay_mutex_unlock (); - *ret_ovcs_id = ovcs->id; - -return ret; + goto out_unlock; err_free_ovcs:free_overlay_changeset (ovcs); +out_unlock:mutex_unlock (&of_mutex);of_overlay_mutex_unlock (); -return ret; }EXPORT_SYMBOL_GPL (of_overlay_fdt_apply);
Signature · 1 line
2.25.1
Re: [PATCH 2/2] of: overlay: Simplify of_overlay_fdt_apply() tail
Quoted 9 lines · Geert Uytterhoeven
It does not hurt to fill in the changeset id while the mutex is still held. After doing so, the function tails for the success and failure cases become identical, so they can be unified.
Signed-off-by Geert Uytterhoeven <[email protected]>--- drivers/of/overlay.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
Applied, thanks!
Quoted 8 lines · Geert Uytterhoeven
Hi,While performing the long-overdue rebase of my topic/overlays branch[1] on top of the overlay rework in v5.19-rc1, I identified a few areas for improvement in the upstream code.
Thanks for your comments!
Quoted 9 lines
[1] https://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git/log/?h=topic/overlays
Geert Uytterhoeven (2):
of: overlay: Movedevicetree_corrupt()check up
of: overlay: Simplifyof_overlay_fdt_apply()taildrivers/of/overlay.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
The patches look good, based on a visual inspection. I'll build the kernel and test the patches tomorrow morning.
-Frank
Quoted 8 lines · Geert Uytterhoeven
Hi,While performing the long-overdue rebase of my topic/overlays branch[1] on top of the overlay rework in v5.19-rc1, I identified a few areas for improvement in the upstream code.
Thanks for your comments!
Quoted 9 lines
[1] https://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git/log/?h=topic/overlays
Geert Uytterhoeven (2):
of: overlay: Movedevicetree_corrupt()check up
of: overlay: Simplifyof_overlay_fdt_apply()taildrivers/of/overlay.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
For the entire series: