* [PATCH 1/3] mfd: syscon: call of_node_put() only when of_parse_phandle() takes a ref
2024-02-20 11:50 [PATCH 0/3] mfd syscon and altera-sysmgr cleanup Peter Griffin
@ 2024-02-20 11:50 ` Peter Griffin
2024-02-20 11:50 ` [PATCH 2/3] mfd: syscon: remove extern from function prototypes Peter Griffin
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Peter Griffin @ 2024-02-20 11:50 UTC (permalink / raw)
To: arnd, lee, thor.thayer
Cc: kernel-team, krzysztof.kozlowski, linux-kernel, linux-arm-kernel,
pankaj.dubey, tudor.ambarus, andre.draszik, saravanak,
willmcvicker, Peter Griffin
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 <peter.griffin@linaro.org>
---
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
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 2/3] mfd: syscon: remove extern from function prototypes
2024-02-20 11:50 [PATCH 0/3] mfd syscon and altera-sysmgr cleanup Peter Griffin
2024-02-20 11:50 ` [PATCH 1/3] mfd: syscon: call of_node_put() only when of_parse_phandle() takes a ref Peter Griffin
@ 2024-02-20 11:50 ` Peter Griffin
2024-02-20 11:50 ` [PATCH 3/3] mfd: altera-sysmgr: call of_node_put() only when of_parse_phandle() takes a ref Peter Griffin
2024-02-23 16:02 ` [PATCH 0/3] mfd syscon and altera-sysmgr cleanup Lee Jones
3 siblings, 0 replies; 5+ messages in thread
From: Peter Griffin @ 2024-02-20 11:50 UTC (permalink / raw)
To: arnd, lee, thor.thayer
Cc: kernel-team, krzysztof.kozlowski, linux-kernel, linux-arm-kernel,
pankaj.dubey, tudor.ambarus, andre.draszik, saravanak,
willmcvicker, Peter Griffin
The kernel coding style does not require 'extern' in function prototypes
in .h files, so remove them as they are not needed.
To avoid checkpatch warnings such as
CHECK: Lines should not end with a '('
+struct regmap *syscon_regmap_lookup_by_phandle(
The indentation is also updated. No functional changes in this patch.
Signed-off-by: Peter Griffin <peter.griffin@linaro.org>
---
include/linux/mfd/syscon.h | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/include/linux/mfd/syscon.h b/include/linux/mfd/syscon.h
index fecc2fa2a364..c315903f6dab 100644
--- a/include/linux/mfd/syscon.h
+++ b/include/linux/mfd/syscon.h
@@ -17,20 +17,17 @@
struct device_node;
#ifdef CONFIG_MFD_SYSCON
-extern struct regmap *device_node_to_regmap(struct device_node *np);
-extern struct regmap *syscon_node_to_regmap(struct device_node *np);
-extern struct regmap *syscon_regmap_lookup_by_compatible(const char *s);
-extern struct regmap *syscon_regmap_lookup_by_phandle(
- struct device_node *np,
- const char *property);
-extern struct regmap *syscon_regmap_lookup_by_phandle_args(
- struct device_node *np,
- const char *property,
- int arg_count,
- unsigned int *out_args);
-extern struct regmap *syscon_regmap_lookup_by_phandle_optional(
- struct device_node *np,
- const char *property);
+struct regmap *device_node_to_regmap(struct device_node *np);
+struct regmap *syscon_node_to_regmap(struct device_node *np);
+struct regmap *syscon_regmap_lookup_by_compatible(const char *s);
+struct regmap *syscon_regmap_lookup_by_phandle(struct device_node *np,
+ const char *property);
+struct regmap *syscon_regmap_lookup_by_phandle_args(struct device_node *np,
+ const char *property,
+ int arg_count,
+ unsigned int *out_args);
+struct regmap *syscon_regmap_lookup_by_phandle_optional(struct device_node *np,
+ const char *property);
#else
static inline struct regmap *device_node_to_regmap(struct device_node *np)
{
--
2.44.0.rc0.258.g7320e95886-goog
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 3/3] mfd: altera-sysmgr: call of_node_put() only when of_parse_phandle() takes a ref
2024-02-20 11:50 [PATCH 0/3] mfd syscon and altera-sysmgr cleanup Peter Griffin
2024-02-20 11:50 ` [PATCH 1/3] mfd: syscon: call of_node_put() only when of_parse_phandle() takes a ref Peter Griffin
2024-02-20 11:50 ` [PATCH 2/3] mfd: syscon: remove extern from function prototypes Peter Griffin
@ 2024-02-20 11:50 ` Peter Griffin
2024-02-23 16:02 ` [PATCH 0/3] mfd syscon and altera-sysmgr cleanup Lee Jones
3 siblings, 0 replies; 5+ messages in thread
From: Peter Griffin @ 2024-02-20 11:50 UTC (permalink / raw)
To: arnd, lee, thor.thayer
Cc: kernel-team, krzysztof.kozlowski, linux-kernel, linux-arm-kernel,
pankaj.dubey, tudor.ambarus, andre.draszik, saravanak,
willmcvicker, Peter Griffin
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 <peter.griffin@linaro.org>
---
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
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH 0/3] mfd syscon and altera-sysmgr cleanup
2024-02-20 11:50 [PATCH 0/3] mfd syscon and altera-sysmgr cleanup Peter Griffin
` (2 preceding siblings ...)
2024-02-20 11:50 ` [PATCH 3/3] mfd: altera-sysmgr: call of_node_put() only when of_parse_phandle() takes a ref Peter Griffin
@ 2024-02-23 16:02 ` Lee Jones
3 siblings, 0 replies; 5+ messages in thread
From: Lee Jones @ 2024-02-23 16:02 UTC (permalink / raw)
To: arnd, lee, thor.thayer, Peter Griffin
Cc: kernel-team, krzysztof.kozlowski, linux-kernel, linux-arm-kernel,
pankaj.dubey, tudor.ambarus, andre.draszik, saravanak,
willmcvicker
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 [李琼斯]
^ permalink raw reply [flat|nested] 5+ messages in thread