Skip to contentSkip to conversation

mfd syscon and altera-sysmgr cleanup

PATCH Applied Peter Griffin 2 participants 5 messages Feb 20, 2024 – Feb 23, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover 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(-)
Signature · 1 line
2.44.0.rc0.258.g7320e95886-goog
#1 lore raw

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")
---
 drivers/mfd/syscon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mfd/syscon.c +3 -1
index c9550368d9ea..7d0e91164cba 100644
@@ -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;
 }
Signature · 1 line
2.44.0.rc0.258.g7320e95886-goog
#2 lore raw

PATCH 2/3 mfd: syscon: remove extern from function prototypes

In reply to 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.

---
 include/linux/mfd/syscon.h | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
include/linux/mfd/syscon.h +11 -14
index fecc2fa2a364..c315903f6dab 100644
@@ -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)
 {
Signature · 1 line
2.44.0.rc0.258.g7320e95886-goog
#3 lore raw

PATCH 3/3 mfd: altera-sysmgr: call of_node_put() only when of_parse_phandle() takes a ref

In reply to 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")
---
 drivers/mfd/altera-sysmgr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mfd/altera-sysmgr.c +3 -1
index 0e52bd2ebd74..fb5f988e61f3 100644
@@ -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);
 
Signature · 1 line
2.44.0.rc0.258.g7320e95886-goog
maintainer Applied
#4 lore raw
In reply to Peter Griffin
Quoted 10 lines · Peter Griffin

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 [李琼斯]