Skip to contentSkip to conversation

power: reset: vexpress: Use device_get_match_data()

PATCH Applied Rob Herring 4 participants 4 messages Oct 9, 2023 – Oct 21, 2023

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

PATCH 1/1 power: reset: vexpress: Use device_get_match_data()

Use preferred device_get_match_data() instead of of_match_device() to get the driver match data. With this, adjust the includes to explicitly include the correct headers.

---
 drivers/power/reset/vexpress-poweroff.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/power/reset/vexpress-poweroff.c +4 -7
index 17064d7b19f6..bb22b2db5907 100644
@@ -7,8 +7,8 @@
 #include <linux/delay.h>
 #include <linux/notifier.h>
 #include <linux/of.h>
-#include <linux/of_device.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/reboot.h>
 #include <linux/stat.h>
 #include <linux/vexpress.h>
@@ -108,20 +108,17 @@ static int _vexpress_register_restart_handler(struct device *dev)
 
 static int vexpress_reset_probe(struct platform_device *pdev)
 {
-	const struct of_device_id *match =
-			of_match_device(vexpress_reset_of_match, &pdev->dev);
+	enum vexpress_reset_func func;
 	struct regmap *regmap;
 	int ret = 0;
 
-	if (!match)
-		return -EINVAL;
-
 	regmap = devm_regmap_init_vexpress_config(&pdev->dev);
 	if (IS_ERR(regmap))
 		return PTR_ERR(regmap);
 	dev_set_drvdata(&pdev->dev, regmap);
 
-	switch ((uintptr_t)match->data) {
+	func = (uintptr_t)device_get_match_data(&pdev->dev);
+	switch (func) {
 	case FUNC_SHUTDOWN:
 		vexpress_power_off_device = &pdev->dev;
 		pm_power_off = vexpress_power_off;
Signature · 1 line
2.42.0
maintainer
#1 lore raw

Hi Rob,

Quoted 37 lines · Rob Herring

Use preferred device_get_match_data() instead of of_match_device() to get the driver match data. With this, adjust the includes to explicitly include the correct headers.

---
 drivers/power/reset/vexpress-poweroff.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/power/reset/vexpress-poweroff.c +2 -6
index 17064d7b19f6..bb22b2db5907 100644
@@ -7,8 +7,8 @@
 #include <linux/delay.h>
 #include <linux/notifier.h>
 #include <linux/of.h>
-#include <linux/of_device.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/reboot.h>
 #include <linux/stat.h>
 #include <linux/vexpress.h>
@@ -108,20 +108,17 @@ static int _vexpress_register_restart_handler(struct device *dev)
 
 static int vexpress_reset_probe(struct platform_device *pdev)
 {
-	const struct of_device_id *match =
-			of_match_device(vexpress_reset_of_match, &pdev->dev);
+	enum vexpress_reset_func func;
 	struct regmap *regmap;
 	int ret = 0;
 
-	if (!match)
-		return -EINVAL;
-
 	regmap = devm_regmap_init_vexpress_config(&pdev->dev);

drivers/power/reset/vexpress-poweroff.c static int _vexpress_register_restart_handler(struct device *dev) · line 124

Quoted 10 lines
drivers/power/reset/vexpress-poweroff.c +2 -1
 	if (IS_ERR(regmap))
 		return PTR_ERR(regmap);
 	dev_set_drvdata(&pdev->dev, regmap);
 
-	switch ((uintptr_t)match->data) {
+	func = (uintptr_t)device_get_match_data(&pdev->dev);
+	switch (func) {
 	case FUNC_SHUTDOWN:
 		vexpress_power_off_device = &pdev->dev;
 		pm_power_off = vexpress_power_off;

device_get_match_data() is badly un-documented but I think it can still return NULL if no match. At the moment we're checking for a match earlier and avoid calling devm_regmap_init_vexpress_config() needlessly, with your patch not so. Can you not replace each line with the equivalent code and keep the NULL check?

Best regards,
Liviu

Quoted 3 lines
Signature · 1 line
2.42.0
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
Acked-by
#2 lore raw
Quoted 44 lines · Liviu Dudau

Hi Rob,

Quoted 41 lines · Rob Herring

Use preferred device_get_match_data() instead of of_match_device() to get the driver match data. With this, adjust the includes to explicitly include the correct headers.

---
 drivers/power/reset/vexpress-poweroff.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/power/reset/vexpress-poweroff.c +2 -6
index 17064d7b19f6..bb22b2db5907 100644
@@ -7,8 +7,8 @@
 #include <linux/delay.h>
 #include <linux/notifier.h>
 #include <linux/of.h>
-#include <linux/of_device.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/reboot.h>
 #include <linux/stat.h>
 #include <linux/vexpress.h>
@@ -108,20 +108,17 @@ static int _vexpress_register_restart_handler(struct device *dev)
 
 static int vexpress_reset_probe(struct platform_device *pdev)
 {
-	const struct of_device_id *match =
-			of_match_device(vexpress_reset_of_match, &pdev->dev);
+	enum vexpress_reset_func func;
 	struct regmap *regmap;
 	int ret = 0;
 
-	if (!match)
-		return -EINVAL;
-
 	regmap = devm_regmap_init_vexpress_config(&pdev->dev);
 	if (IS_ERR(regmap))
 		return PTR_ERR(regmap);
 	dev_set_drvdata(&pdev->dev, regmap);
 
Quoted 12 lines

drivers/power/reset/vexpress-poweroff.c static int _vexpress_register_restart_handler(struct device *dev) · line 124

Quoted 6 lines
drivers/power/reset/vexpress-poweroff.c +2 -1
-	switch ((uintptr_t)match->data) {
+	func = (uintptr_t)device_get_match_data(&pdev->dev);
+	switch (func) {
 	case FUNC_SHUTDOWN:
 		vexpress_power_off_device = &pdev->dev;
 		pm_power_off = vexpress_power_off;

device_get_match_data() is badly un-documented but I think it can still return NULL if no match. At the moment we're checking for a match earlier and avoid calling devm_regmap_init_vexpress_config() needlessly, with your patch not so. Can you not replace each line with the equivalent code and keep the NULL check?

In contrast, I always questioned/wondered why we needed the NULL check for the match above as probe would have not got called if there was no match. While I agree with the less clear documentation of device_get_match_data(), I am fine with the change as such

Also check similar response from Rob here[1]

Sebastian,

I assume you will pick this up.

--
Regards,
Sudeep

[1] https://lore.kernel.org/all/CAL_JsqKi8PXVqHgVxqMN+mbX8U-ZGsCMUFqbxmjeFmj1xKTrjw@mail.gmail.com/

#3 lore raw
In reply to Rob Herring
Quoted 5 lines · Rob Herring

Use preferred device_get_match_data() instead of of_match_device() to get the driver match data. With this, adjust the includes to explicitly include the correct headers.

Applied, thanks!

[1/1] power: reset: vexpress: Use device_get_match_data()

      commit: 469d31745b9fb3a87424b311abb7cb530611404f

Best regards,

Signature · 1 line
Sebastian Reichel <[email protected]>