2024-02-20 11:51:07

by Peter Griffin

[permalink] [raw]
Subject: [PATCH 0/3] mfd syscon and altera-sysmgr cleanup

Hi,

Whilst implementing a driver similar to altera-sysmgr for exynos
it was noticed during the review feedback that we should only call
of_node_put() if the property is provided otherwise nothing has
taken a reference on the node. Both syscon and altera-sysmgr also
have the same issue which this series fixes.

Another piece of review feedback was not to use extern keyword in
the header file, so I also cleaned that up whilst being here.

regards,

Peter.

Peter Griffin (3):
mfd: syscon: call of_node_put() only when of_parse_phandle() takes a
ref
mfd: syscon: remove extern from function prototypes
mfd: altera-sysmgr: call of_node_put() only when of_parse_phandle()
takes a ref

drivers/mfd/altera-sysmgr.c | 4 +++-
drivers/mfd/syscon.c | 4 +++-
include/linux/mfd/syscon.h | 25 +++++++++++--------------
3 files changed, 17 insertions(+), 16 deletions(-)

--
2.44.0.rc0.258.g7320e95886-goog



2024-02-20 11:57:01

by Peter Griffin

[permalink] [raw]
Subject: [PATCH 3/3] mfd: altera-sysmgr: call of_node_put() only when of_parse_phandle() takes a ref

of_parse_phandle() returns a device_node with refcount incremented, which
the callee needs to call of_node_put() on when done. We should only call
of_node_put() when the property argument is provided though as otherwise
nothing has taken a reference on the node.

Fixes: f36e789a1f8d ("mfd: altera-sysmgr: Add SOCFPGA System Manager")
Signed-off-by: Peter Griffin <[email protected]>
---
drivers/mfd/altera-sysmgr.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/altera-sysmgr.c b/drivers/mfd/altera-sysmgr.c
index 0e52bd2ebd74..fb5f988e61f3 100644
--- a/drivers/mfd/altera-sysmgr.c
+++ b/drivers/mfd/altera-sysmgr.c
@@ -109,7 +109,9 @@ struct regmap *altr_sysmgr_regmap_lookup_by_phandle(struct device_node *np,

dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver,
(void *)sysmgr_np);
- of_node_put(sysmgr_np);
+ if (property)
+ of_node_put(sysmgr_np);
+
if (!dev)
return ERR_PTR(-EPROBE_DEFER);

--
2.44.0.rc0.258.g7320e95886-goog


2024-02-20 11:57:20

by Peter Griffin

[permalink] [raw]
Subject: [PATCH 1/3] mfd: syscon: call of_node_put() only when of_parse_phandle() takes a ref

of_parse_phandle() returns a device_node with refcount incremented, which
the callee needs to call of_node_put() on when done. We should only call
of_node_put() when the property argument is provided though as otherwise
nothing has taken a reference on the node.

Fixes: 45330bb43421 ("mfd: syscon: Allow property as NULL in syscon_regmap_lookup_by_phandle")
Signed-off-by: Peter Griffin <[email protected]>
---
drivers/mfd/syscon.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index c9550368d9ea..7d0e91164cba 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -238,7 +238,9 @@ struct regmap *syscon_regmap_lookup_by_phandle(struct device_node *np,
return ERR_PTR(-ENODEV);

regmap = syscon_node_to_regmap(syscon_np);
- of_node_put(syscon_np);
+
+ if (property)
+ of_node_put(syscon_np);

return regmap;
}
--
2.44.0.rc0.258.g7320e95886-goog


2024-02-23 16:13:54

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 0/3] mfd syscon and altera-sysmgr cleanup

On Tue, 20 Feb 2024 11:50:09 +0000, Peter Griffin wrote:
> Whilst implementing a driver similar to altera-sysmgr for exynos
> it was noticed during the review feedback that we should only call
> of_node_put() if the property is provided otherwise nothing has
> taken a reference on the node. Both syscon and altera-sysmgr also
> have the same issue which this series fixes.
>
> Another piece of review feedback was not to use extern keyword in
> the header file, so I also cleaned that up whilst being here.
>
> [...]

Applied, thanks!

[1/3] mfd: syscon: call of_node_put() only when of_parse_phandle() takes a ref
commit: d2b0680cf3b05490b579e71b0df6e07451977745
[2/3] mfd: syscon: remove extern from function prototypes
commit: 0db017f8edd9b9af818bc1d68ba578df1b4c4628
[3/3] mfd: altera-sysmgr: call of_node_put() only when of_parse_phandle() takes a ref
commit: e28c28a34ee9fa2ea671a20e5e7064e6220d55e7

--
Lee Jones [李琼斯]