Skip to contentSkip to conversation

drm: bridge: anx7625: Use of_property_read_variable_u8_array()

PATCH Applied Rob Herring (Arm) 2 participants 2 messages Jul 31, 2024 – Aug 19, 2024

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

PATCH 1/1 drm: bridge: anx7625: Use of_property_read_variable_u8_array()

There's no need to get the length of an DT array property before parsing the array. of_property_read_variable_u8_array() takes a minimum and maximum length and returns the actual length (or error code).

This is part of a larger effort to remove callers of of_get_property() and similar functions. of_get_property() leaks the DT property data pointer which is a problem for dynamically allocated nodes which may be freed.

---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)
drivers/gpu/drm/bridge/analogix/anx7625.c +6 -16
index 88e4aa5830f3..a2e9bb485c36 100644
@@ -1647,25 +1647,15 @@ static int anx7625_get_swing_setting(struct device *dev,
 {
 	int num_regs;
 
-	if (of_get_property(dev->of_node,
-			    "analogix,lane0-swing", &num_regs)) {
-		if (num_regs > DP_TX_SWING_REG_CNT)
-			num_regs = DP_TX_SWING_REG_CNT;
-
+	num_regs = of_property_read_variable_u8_array(dev->of_node, "analogix,lane0-swing",
+						      pdata->lane0_reg_data, 1, DP_TX_SWING_REG_CNT);
+	if (num_regs > 0)
 		pdata->dp_lane0_swing_reg_cnt = num_regs;
-		of_property_read_u8_array(dev->of_node, "analogix,lane0-swing",
-					  pdata->lane0_reg_data, num_regs);
-	}
-
-	if (of_get_property(dev->of_node,
-			    "analogix,lane1-swing", &num_regs)) {
-		if (num_regs > DP_TX_SWING_REG_CNT)
-			num_regs = DP_TX_SWING_REG_CNT;
 
+	num_regs = of_property_read_variable_u8_array(dev->of_node, "analogix,lane1-swing",
+						      pdata->lane1_reg_data, 1, DP_TX_SWING_REG_CNT);
+	if (num_regs > 0)
 		pdata->dp_lane1_swing_reg_cnt = num_regs;
-		of_property_read_u8_array(dev->of_node, "analogix,lane1-swing",
-					  pdata->lane1_reg_data, num_regs);
-	}
 
 	return 0;
 }
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 10 lines · Rob Herring (Arm)

There's no need to get the length of an DT array property before parsing the array. of_property_read_variable_u8_array() takes a minimum and maximum length and returns the actual length (or error code).

This is part of a larger effort to remove callers of of_get_property() and similar functions. of_get_property() leaks the DT property data pointer which is a problem for dynamically allocated nodes which may be freed.

[...]

Applied, thanks!

[1/1] drm: bridge: anx7625: Use of_property_read_variable_u8_array()

      https://gitlab.freedesktop.org/drm/misc/kernel/-/commit/11c742bb5a26

Rob