linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] of: overlay: Miscellaneous improvements
@ 2022-07-15 14:03 Geert Uytterhoeven
  2022-07-15 14:03 ` [PATCH 1/2] of: overlay: Move devicetree_corrupt() check up Geert Uytterhoeven
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2022-07-15 14:03 UTC (permalink / raw)
  To: Pantelis Antoniou, Frank Rowand, Rob Herring
  Cc: devicetree, linux-kernel, 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!

[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(-)

-- 
2.25.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

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 Torvalds

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] of: overlay: Move devicetree_corrupt() check up
  2022-07-15 14:03 [PATCH 0/2] of: overlay: Miscellaneous improvements Geert Uytterhoeven
@ 2022-07-15 14:03 ` Geert Uytterhoeven
  2022-07-19 21:55   ` Rob Herring
  2022-07-15 14:03 ` [PATCH 2/2] of: overlay: Simplify of_overlay_fdt_apply() tail Geert Uytterhoeven
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2022-07-15 14:03 UTC (permalink / raw)
  To: Pantelis Antoniou, Frank Rowand, Rob Herring
  Cc: devicetree, linux-kernel, Geert Uytterhoeven

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.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/of/overlay.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 4044ddcb02c60a58..84a8d402009cb3b2 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -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");
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] of: overlay: Simplify of_overlay_fdt_apply() tail
  2022-07-15 14:03 [PATCH 0/2] of: overlay: Miscellaneous improvements Geert Uytterhoeven
  2022-07-15 14:03 ` [PATCH 1/2] of: overlay: Move devicetree_corrupt() check up Geert Uytterhoeven
@ 2022-07-15 14:03 ` Geert Uytterhoeven
  2022-07-19 21:55   ` Rob Herring
  2022-07-18 23:42 ` [PATCH 0/2] of: overlay: Miscellaneous improvements Frank Rowand
  2022-07-19 18:37 ` Frank Rowand
  3 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2022-07-15 14:03 UTC (permalink / raw)
  To: Pantelis Antoniou, Frank Rowand, Rob Herring
  Cc: devicetree, linux-kernel, 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 <geert+renesas@glider.be>
---
 drivers/of/overlay.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 84a8d402009cb3b2..bd8ff4df723da217 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] of: overlay: Miscellaneous improvements
  2022-07-15 14:03 [PATCH 0/2] of: overlay: Miscellaneous improvements Geert Uytterhoeven
  2022-07-15 14:03 ` [PATCH 1/2] of: overlay: Move devicetree_corrupt() check up Geert Uytterhoeven
  2022-07-15 14:03 ` [PATCH 2/2] of: overlay: Simplify of_overlay_fdt_apply() tail Geert Uytterhoeven
@ 2022-07-18 23:42 ` Frank Rowand
  2022-07-19 18:37 ` Frank Rowand
  3 siblings, 0 replies; 7+ messages in thread
From: Frank Rowand @ 2022-07-18 23:42 UTC (permalink / raw)
  To: Geert Uytterhoeven, Pantelis Antoniou, Rob Herring
  Cc: devicetree, linux-kernel

On 7/15/22 09:03, Geert Uytterhoeven wrote:
> 	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(-)
> 

The patches look good, based on a visual inspection.  I'll build the kernel
and test the patches tomorrow morning.

-Frank

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] of: overlay: Miscellaneous improvements
  2022-07-15 14:03 [PATCH 0/2] of: overlay: Miscellaneous improvements Geert Uytterhoeven
                   ` (2 preceding siblings ...)
  2022-07-18 23:42 ` [PATCH 0/2] of: overlay: Miscellaneous improvements Frank Rowand
@ 2022-07-19 18:37 ` Frank Rowand
  3 siblings, 0 replies; 7+ messages in thread
From: Frank Rowand @ 2022-07-19 18:37 UTC (permalink / raw)
  To: Geert Uytterhoeven, Pantelis Antoniou, Rob Herring
  Cc: devicetree, linux-kernel

On 7/15/22 09:03, Geert Uytterhoeven wrote:
> 	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(-)
> 

For the entire series:

Reviewed-by: Frank Rowand <frank.rowand@sony.com>
Tested-by: Frank Rowand <frank.rowand@sony.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] of: overlay: Move devicetree_corrupt() check up
  2022-07-15 14:03 ` [PATCH 1/2] of: overlay: Move devicetree_corrupt() check up Geert Uytterhoeven
@ 2022-07-19 21:55   ` Rob Herring
  0 siblings, 0 replies; 7+ messages in thread
From: Rob Herring @ 2022-07-19 21:55 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Rob Herring, devicetree, Frank Rowand, Pantelis Antoniou, linux-kernel

On Fri, 15 Jul 2022 16:03:14 +0200, Geert Uytterhoeven wrote:
> 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.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
>  drivers/of/overlay.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 

Applied, thanks!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] of: overlay: Simplify of_overlay_fdt_apply() tail
  2022-07-15 14:03 ` [PATCH 2/2] of: overlay: Simplify of_overlay_fdt_apply() tail Geert Uytterhoeven
@ 2022-07-19 21:55   ` Rob Herring
  0 siblings, 0 replies; 7+ messages in thread
From: Rob Herring @ 2022-07-19 21:55 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: devicetree, Rob Herring, Pantelis Antoniou, Frank Rowand, linux-kernel

On Fri, 15 Jul 2022 16:03:15 +0200, Geert Uytterhoeven wrote:
> 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 <geert+renesas@glider.be>
> ---
>  drivers/of/overlay.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 

Applied, thanks!

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-07-19 21:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-15 14:03 [PATCH 0/2] of: overlay: Miscellaneous improvements Geert Uytterhoeven
2022-07-15 14:03 ` [PATCH 1/2] of: overlay: Move devicetree_corrupt() check up Geert Uytterhoeven
2022-07-19 21:55   ` Rob Herring
2022-07-15 14:03 ` [PATCH 2/2] of: overlay: Simplify of_overlay_fdt_apply() tail Geert Uytterhoeven
2022-07-19 21:55   ` Rob Herring
2022-07-18 23:42 ` [PATCH 0/2] of: overlay: Miscellaneous improvements Frank Rowand
2022-07-19 18:37 ` Frank Rowand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).