Skip to contentSkip to conversation

serdev: Update a few places to use new APIs

PATCH New Andy Shevchenko 1 participant 4 messages Oct 24, 2023

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

cover serdev: Update a few places to use new APIs

Inspired by the reviwing the patch by Tony Lindgren.

The first one makes a behavioural change on ACPI platforms where sysfs entry will get firmware_node link in addition to what it has now.

Andy Shevchenko (3):
serdev: Make use of device_set_node()
serdev: Simplify devm_serdev_device_open() function
serdev: Replace custom code with device_match_acpi_handle()

 drivers/tty/serdev/core.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
Signature · 1 line
2.40.0.1.gaa8946217a0b
#1 lore raw

PATCH 1/3 serdev: Make use of device_set_node()

Use device_set_node() instead of assigning ctrl->dev.of_node directly because it also sets the firmware node.

---
 drivers/tty/serdev/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/tty/serdev/core.c +3 -1
index e7d663901c07..e46448efc48d 100644
@@ -15,9 +15,11 @@
 #include <linux/of_device.h>
 #include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
+#include <linux/property.h>
 #include <linux/sched.h>
 #include <linux/serdev.h>
 #include <linux/slab.h>
+
 #include <linux/platform_data/x86/apple.h>
 
 static bool is_registered;
@@ -510,7 +512,7 @@ struct serdev_controller *serdev_controller_alloc(struct device *parent,
 	ctrl->dev.type = &serdev_ctrl_type;
 	ctrl->dev.bus = &serdev_bus_type;
 	ctrl->dev.parent = parent;
-	ctrl->dev.of_node = parent->of_node;
+	device_set_node(&ctrl->dev, dev_fwnode(parent));
 	serdev_controller_set_drvdata(ctrl, &ctrl[1]);
 
 	dev_set_name(&ctrl->dev, "serial%d", id);
Signature · 1 line
2.40.0.1.gaa8946217a0b
#2 lore raw

PATCH 2/3 serdev: Simplify devm_serdev_device_open() function

In reply to Andy Shevchenko

Use devm_add_action_or_reset() instead of devres_alloc() and devres_add(), which works the same. This will simplify the code. There is no functional changes.

---
 drivers/tty/serdev/core.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/tty/serdev/core.c +4 -14
index e46448efc48d..6a1e75f98f16 100644
@@ -187,30 +187,20 @@ void serdev_device_close(struct serdev_device *serdev)
 }
 EXPORT_SYMBOL_GPL(serdev_device_close);
 
-static void devm_serdev_device_release(struct device *dev, void *dr)
+static void devm_serdev_device_close(void *serdev)
 {
-	serdev_device_close(*(struct serdev_device **)dr);
+	serdev_device_close(serdev);
 }
 
 int devm_serdev_device_open(struct device *dev, struct serdev_device *serdev)
 {
-	struct serdev_device **dr;
 	int ret;
 
-	dr = devres_alloc(devm_serdev_device_release, sizeof(*dr), GFP_KERNEL);
-	if (!dr)
-		return -ENOMEM;
-
 	ret = serdev_device_open(serdev);
-	if (ret) {
-		devres_free(dr);
+	if (ret)
 		return ret;
-	}
 
-	*dr = serdev;
-	devres_add(dev, dr);
-
-	return 0;
+	return devm_add_action_or_reset(dev, devm_serdev_device_close, serdev);
 }
 EXPORT_SYMBOL_GPL(devm_serdev_device_open);
 
Signature · 1 line
2.40.0.1.gaa8946217a0b
#3 lore raw

PATCH 3/3 serdev: Replace custom code with device_match_acpi_handle()

In reply to Andy Shevchenko

Since driver core provides a generic device_match_acpi_handle() we may replace the custom code with it.

---
 drivers/tty/serdev/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serdev/core.c +1 -1
index 6a1e75f98f16..a5fdaf5e148e 100644
@@ -665,7 +665,7 @@ static int acpi_serdev_check_resources(struct serdev_controller *ctrl,
 		acpi_get_parent(adev->handle, &lookup.controller_handle);
 
 	/* Make sure controller and ResourceSource handle match */
-	if (ACPI_HANDLE(ctrl->dev.parent) != lookup.controller_handle)
+	if (!device_match_acpi_handle(ctrl->dev.parent, lookup.controller_handle))
 		return -ENODEV;
 
 	return 0;
Signature · 1 line
2.40.0.1.gaa8946217a0b