Skip to contentSkip to conversation

ACPI: Replace acpi_get_first_physical_node() with acpi_bus_get_primary_device()

PATCH Superseded Rafael J. Wysocki 10 participants 38 messages Sep 21 – Sep 22

Subsystems (17)
Sound ACPI ASoC x86 platform drivers +13 more subsystems

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

cover ACPI: Replace acpi_get_first_physical_node() with acpi_bus_get_primary_device()

Hi All,

This series replaces acpi_get_first_physical_node(), which is inherently racy and therefore generally unsafe to use, with acpi_bus_get_primary_device(), that doesn't have this problem, everywhere in the code.

The first preparatory patch is needed because acpi_bus_get_primary_device() is defined in acpi/acpi_bus.h and the subsequent patches depend on it. For this reason, I will appreciate ACKs from maintainers of the code updated by the patches.

Thanks!

author maintainer
#1 lore raw

PATCH 1/17 ACPI: bus: Use acpi/acpi_bus.h without CONFIG_ACPI

From: "Rafael J. Wysocki" <[email protected]>

Corrently acpi/acpi_bus.h is included in linux/acpi.h only if CONFIG_ACPI is set, but it contains declarations that are useful otherwise too.

For consistency, modify linux/acpi.h to always include acpi/acpi_bus.h and update the latter to avoid exposing too much when CONFIG_ACPI is not set.

Since acpi_has_method() is called from some code build when CONFIG_ACPI is unset, add a stub for it to the !CONFIG_ACPI block in acpi/acpi_bus.h.

---
 include/acpi/acpi_bus.h | 12 ++++++++----
 include/linux/acpi.h    |  2 +-
 2 files changed, 9 insertions(+), 5 deletions(-)
include/acpi/acpi_bus.h +8 -4
index a10a591c18b2..32837f507f40 100644
@@ -9,6 +9,8 @@
 #ifndef __ACPI_BUS_H__
 #define __ACPI_BUS_H__
 
+#ifdef CONFIG_ACPI
+
 #include <linux/completion.h>
 #include <linux/container_of.h>
 #include <linux/device.h>
@@ -58,7 +60,6 @@ bool acpi_dock_match(acpi_handle handle);
 bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs);
 union acpi_object *acpi_evaluate_dsm(acpi_handle handle, const guid_t *guid,
 			u64 rev, u64 func, union acpi_object *argv4);
-#ifdef CONFIG_ACPI
 bool
 acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld);
 
@@ -77,7 +78,6 @@ acpi_evaluate_dsm_typed(acpi_handle handle, const guid_t *guid, u64 rev,
 
 	return obj;
 }
-#endif
 
 #define	ACPI_INIT_DSM_ARGV4(cnt, eles)			\
 	{						\
@@ -90,8 +90,6 @@ bool acpi_dev_found(const char *hid);
 bool acpi_dev_present(const char *hid, const char *uid, s64 hrv);
 bool acpi_reduced_hardware(void);
 
-#ifdef CONFIG_ACPI
-
 struct proc_dir_entry;
 
 #define ACPI_BUS_FILE_ROOT	"acpi"
@@ -942,8 +940,14 @@ int acpi_wait_for_acpi_ipmi(void);
 
 int acpi_scan_add_dep(acpi_handle handle, struct acpi_handle_list *dep_devices);
 u32 arch_acpi_add_auto_dep(acpi_handle handle);
+
 #else	/* CONFIG_ACPI */
 
+static inline bool acpi_has_method(acpi_handle handle, char *name)
+{
+	return false;
+}
+
 static inline struct device *acpi_bus_get_primary_device(struct acpi_device *adev)
 {
 	return NULL;
include/linux/acpi.h +1 -1
index ddacac812094..ba5234bd93a2 100644
@@ -25,6 +25,7 @@ struct irq_domain_ops;
 #define _LINUX
 #endif
 #include <acpi/acpi.h>
+#include <acpi/acpi_bus.h>
 #include <acpi/acpi_numa.h>
 
 #ifdef	CONFIG_ACPI
@@ -35,7 +36,6 @@ struct irq_domain_ops;
 #include <linux/mutex.h>
 #include <linux/fw_table.h>
 
-#include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
 #include <acpi/acpi_io.h>
 #include <asm/acpi.h>
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 1/17
#2 lore raw

Re: [PATCH v1 01/17] ACPI: bus: Use acpi/acpi_bus.h without CONFIG_ACPI

Quoted 6 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Corrently acpi/acpi_bus.h is included in linux/acpi.h only if CONFIG_ACPI is set, but it contains declarations that are useful otherwise too.

Quoted 8 lines

For consistency, modify linux/acpi.h to always include acpi/acpi_bus.h and update the latter to avoid exposing too much when CONFIG_ACPI is not set.

Since acpi_has_method() is called from some code build when CONFIG_ACPI is unset, add a stub for it to the !CONFIG_ACPI block in acpi/acpi_bus.h.

I was planning to just pull acpi_device_hid() out so that I can get rid of CONFIG_ACPI in [1]. This looks much more elegant. Thanks for doing it.

Signature · 5 lines
Regards,
Sudeep


[1] https://lore.kernel.org/all/[email protected]
author maintainer
#3 lore raw

Re: [PATCH v1 01/17] ACPI: bus: Use acpi/acpi_bus.h without CONFIG_ACPI

Quoted 17 lines · Sudeep Holla
Quoted 6 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Corrently acpi/acpi_bus.h is included in linux/acpi.h only if CONFIG_ACPI is set, but it contains declarations that are useful otherwise too.

Quoted 8 lines

For consistency, modify linux/acpi.h to always include acpi/acpi_bus.h and update the latter to avoid exposing too much when CONFIG_ACPI is not set.

Since acpi_has_method() is called from some code build when CONFIG_ACPI is unset, add a stub for it to the !CONFIG_ACPI block in acpi/acpi_bus.h.

Quoted 4 lines

I was planning to just pull acpi_device_hid() out so that I can get rid of CONFIG_ACPI in [1]. This looks much more elegant. Thanks for doing it.

Anytime, and thank you!

Quoted 3 lines

[1] https://lore.kernel.org/all/[email protected]

author maintainer
#4 lore raw

PATCH 2/17 ACPI: amba: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 drivers/acpi/arm64/amba.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/acpi/arm64/amba.c +2 -1
index 1350083bce5f..7ee431d9464a 100644
@@ -87,11 +87,12 @@ static int amba_handler_attach(struct acpi_device *adev,
 	 * the amba device we are about to create.
 	 */
 	if (parent)
-		dev->dev.parent = acpi_get_first_physical_node(parent);
+		dev->dev.parent = acpi_bus_get_primary_device(parent);
 
 	device_set_node(&dev->dev, acpi_fwnode_handle(adev));
 
 	ret = amba_device_add(dev, &iomem_resource);
+	put_device(dev->dev.parent);
 	if (ret) {
 		dev_err(&adev->dev, "%s(): amba_device_add() failed (%d)\n",
 		       __func__, ret);
Signature · 1 line
2.51.0
maintainer Acked-by on v1 2/17
#5 lore raw

Re: [PATCH v1 02/17] ACPI: amba: Switch to use acpi_bus_get_primary_device()

Quoted 11 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

Quoted 5 lines
---
  drivers/acpi/arm64/amba.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

Thanks
Hanjun

maintainer Reviewed-by on v1 2/17
#6 lore raw

Re: [PATCH v1 02/17] ACPI: amba: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki
Quoted 11 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

Signature · 2 lines
Regards,
Sudeep
author maintainer
#7 lore raw

PATCH 3/17 efi/dev-path-parser: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 drivers/firmware/efi/dev-path-parser.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firmware/efi/dev-path-parser.c +2 -2
index 13ea141c0def..e0f864cbaa8c 100644
@@ -37,9 +37,9 @@ static long __init parse_acpi_path(const struct efi_dev_path *node,
 	if (!adev)
 		return -ENODEV;
 
-	phys_dev = acpi_get_first_physical_node(adev);
+	phys_dev = acpi_bus_get_primary_device(adev);
 	if (phys_dev) {
-		*child = get_device(phys_dev);
+		*child = phys_dev;
 		acpi_dev_put(adev);
 	} else
 		*child = &adev->dev;
Signature · 1 line
2.51.0
author maintainer
#8 lore raw

PATCH 4/17 iommu/arm-smmu-v3: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1 -1
index 5732f3ba0122..98f105798b89 100644
@@ -5307,7 +5307,7 @@ static void acpi_smmu_dsdt_probe_tegra241_cmdqv(struct acpi_iort_node *node,
 	adev = acpi_dev_get_first_match_dev("NVDA200C", uid, -1);
 	if (adev) {
 		/* Tegra241 CMDQV driver is responsible for put_device() */
-		smmu->impl_dev = get_device(acpi_get_first_physical_node(adev));
+		smmu->impl_dev = acpi_bus_get_primary_device(adev);
 		smmu->options |= ARM_SMMU_OPT_TEGRA241_CMDQV;
 		dev_info(smmu->dev, "found companion CMDQV device: %s\n",
 			 dev_name(smmu->impl_dev));
Signature · 1 line
2.51.0
author maintainer
#9 lore raw

PATCH 5/17 platform/x86: yogabook: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 drivers/platform/x86/lenovo/yogabook.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/lenovo/yogabook.c +2 -2
index 1a4b2ab1f35d..8a91d440724b 100644
@@ -353,13 +353,13 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 		goto error_put_devs;
 	}
 
-	data->kbd_dev = get_device(acpi_get_first_physical_node(data->kbd_adev));
+	data->kbd_dev = acpi_bus_get_primary_device(data->kbd_adev);
 	if (!data->kbd_dev || !data->kbd_dev->driver) {
 		r = -EPROBE_DEFER;
 		goto error_put_devs;
 	}
 
-	data->dig_dev = get_device(acpi_get_first_physical_node(data->dig_adev));
+	data->dig_dev = acpi_bus_get_primary_device(data->dig_adev);
 	if (!data->dig_dev || !data->dig_dev->driver) {
 		r = -EPROBE_DEFER;
 		goto error_put_devs;
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 5/17
#10 lore raw

Re: [PATCH v1 05/17] platform/x86: yogabook: Switch to use acpi_bus_get_primary_device()

Quoted 26 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 drivers/platform/x86/lenovo/yogabook.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/lenovo/yogabook.c +1 -1
index 1a4b2ab1f35d..8a91d440724b 100644
@@ -353,13 +353,13 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 		goto error_put_devs;
 	}
 
-	data->kbd_dev = get_device(acpi_get_first_physical_node(data->kbd_adev));
+	data->kbd_dev = acpi_bus_get_primary_device(data->kbd_adev);

drivers/platform/x86/lenovo/yogabook.c static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) · line 365

Quoted 10 lines
drivers/platform/x86/lenovo/yogabook.c +1 -1
 	if (!data->kbd_dev || !data->kbd_dev->driver) {
 		r = -EPROBE_DEFER;
 		goto error_put_devs;
 	}
 
-	data->dig_dev = get_device(acpi_get_first_physical_node(data->dig_adev));
+	data->dig_dev = acpi_bus_get_primary_device(data->dig_adev);
 	if (!data->dig_dev || !data->dig_dev->driver) {
 		r = -EPROBE_DEFER;
 		goto error_put_devs;
Signature · 1 line
 i.
maintainer Reviewed-by on v1 5/17
#11 lore raw

Re: [PATCH v1 05/17] platform/x86: yogabook: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

Hi,

Quoted 6 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

Quoted 6 lines

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

Thanks, patch looks good to me:

Regards,

Hans

Quoted 24 lines
---
 drivers/platform/x86/lenovo/yogabook.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/lenovo/yogabook.c +2 -2
index 1a4b2ab1f35d..8a91d440724b 100644
@@ -353,13 +353,13 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 		goto error_put_devs;
 	}
 
-	data->kbd_dev = get_device(acpi_get_first_physical_node(data->kbd_adev));
+	data->kbd_dev = acpi_bus_get_primary_device(data->kbd_adev);
 	if (!data->kbd_dev || !data->kbd_dev->driver) {
 		r = -EPROBE_DEFER;
 		goto error_put_devs;
 	}
 
-	data->dig_dev = get_device(acpi_get_first_physical_node(data->dig_adev));
+	data->dig_dev = acpi_bus_get_primary_device(data->dig_adev);
 	if (!data->dig_dev || !data->dig_dev->driver) {
 		r = -EPROBE_DEFER;
 		goto error_put_devs;
maintainer Reviewed-by on v1 5/17
#12 lore raw

Re: [PATCH v1 05/17] platform/x86: yogabook: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki
Quoted 37 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 drivers/platform/x86/lenovo/yogabook.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/lenovo/yogabook.c +2 -2
index 1a4b2ab1f35d..8a91d440724b 100644
@@ -353,13 +353,13 @@ static int yogabook_wmi_probe(struct wmi_device 
 *wdev, const void *context)
 		goto error_put_devs;
 	}
 
-	data->kbd_dev = get_device(acpi_get_first_physical_node(data->kbd_adev));
+	data->kbd_dev = acpi_bus_get_primary_device(data->kbd_adev);
 	if (!data->kbd_dev || !data->kbd_dev->driver) {
 		r = -EPROBE_DEFER;
 		goto error_put_devs;
 	}
 
-	data->dig_dev = get_device(acpi_get_first_physical_node(data->dig_adev));
+	data->dig_dev = acpi_bus_get_primary_device(data->dig_adev);
 	if (!data->dig_dev || !data->dig_dev->driver) {
 		r = -EPROBE_DEFER;
Quoted 3 lines

goto error_put_devs;

Signature · 1 line
2.51.0

Mark

author maintainer
#13 lore raw

PATCH 6/17 platform/x86: serdev_helpers: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 drivers/platform/x86/serdev_helpers.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/platform/x86/serdev_helpers.h +1 -2
index 57eac75805e2..20267e1941f1 100644
@@ -74,8 +74,7 @@ get_serdev_controller(const char *serial_ctrl_hid,
 		return ERR_PTR(-ENODEV);
 	}
 
-	/* get_first_physical_node() returns a weak ref */
-	parent = get_device(acpi_get_first_physical_node(adev));
+	parent = acpi_bus_get_primary_device(adev);
 	acpi_dev_put(adev);
 	if (!parent) {
 		pr_err("error could not get %s/%s serial-ctrl physical node\n",
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 6/17
#14 lore raw

Re: [PATCH v1 06/17] platform/x86: serdev_helpers: Switch to use acpi_bus_get_primary_device()

Quoted 22 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 drivers/platform/x86/serdev_helpers.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/platform/x86/serdev_helpers.h +0 -0
index 57eac75805e2..20267e1941f1 100644

drivers/platform/x86/serdev_helpers.h get_serdev_controller(const char *serial_ctrl_hid, · line 80

Quoted 9 lines
drivers/platform/x86/serdev_helpers.h +1 -2
@@ -74,8 +74,7 @@ get_serdev_controller(const char *serial_ctrl_hid,
 		return ERR_PTR(-ENODEV);
 	}
 
-	/* get_first_physical_node() returns a weak ref */
-	parent = get_device(acpi_get_first_physical_node(adev));
+	parent = acpi_bus_get_primary_device(adev);
 	acpi_dev_put(adev);
 	if (!parent) {
 		pr_err("error could not get %s/%s serial-ctrl physical node\n",
Signature · 1 line
 i.
maintainer Reviewed-by on v1 6/17
#15 lore raw

Re: [PATCH v1 06/17] platform/x86: serdev_helpers: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

Hi,

Quoted 6 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

Quoted 6 lines

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

Thanks, patch looks good to me:

Regards,

Hans

Quoted 18 lines
---
 drivers/platform/x86/serdev_helpers.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/platform/x86/serdev_helpers.h +1 -2
index 57eac75805e2..20267e1941f1 100644
@@ -74,8 +74,7 @@ get_serdev_controller(const char *serial_ctrl_hid,
 		return ERR_PTR(-ENODEV);
 	}
 
-	/* get_first_physical_node() returns a weak ref */
-	parent = get_device(acpi_get_first_physical_node(adev));
+	parent = acpi_bus_get_primary_device(adev);
 	acpi_dev_put(adev);
 	if (!parent) {
 		pr_err("error could not get %s/%s serial-ctrl physical node\n",
author maintainer
#16 lore raw

PATCH 7/17 platform/x86: apple-gmux: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 include/linux/apple-gmux.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/apple-gmux.h +1 -1
index 206d97ffda79..d7939c3a08fd 100644
@@ -109,7 +109,7 @@ static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, enum apple_gmux_ty
 		if (!adev)
 			return false;
 
-		dev = get_device(acpi_get_first_physical_node(adev));
+		dev = acpi_bus_get_primary_device(adev);
 		acpi_dev_put(adev);
 		if (!dev)
 			return false;
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 7/17
#17 lore raw

Re: [PATCH v1 07/17] platform/x86: apple-gmux: Switch to use acpi_bus_get_primary_device()

Hi,

Quoted 6 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

Quoted 6 lines

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

Thanks, patch looks good to me:

Regards,

Hans

Quoted 17 lines
---
 include/linux/apple-gmux.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/apple-gmux.h +1 -1
index 206d97ffda79..d7939c3a08fd 100644
@@ -109,7 +109,7 @@ static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, enum apple_gmux_ty
 		if (!adev)
 			return false;
 
-		dev = get_device(acpi_get_first_physical_node(adev));
+		dev = acpi_bus_get_primary_device(adev);
 		acpi_dev_put(adev);
 		if (!dev)
 			return false;
author maintainer
#18 lore raw

PATCH 8/17 platform/x86: x86-android-tablets: Use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 drivers/platform/x86/x86-android-tablets/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/x86-android-tablets/core.c +2 -2
index cfff7f5eac5d..2c262f117235 100644
@@ -390,7 +390,6 @@ static int gpio_secondary_fwnode_init(struct device *parent,
 {
 	const struct software_node *const *swnode;
 	struct fwnode_handle *fwnode;
-	struct device *phys_dev;
 	int ret;
 
 	if (!node_group)
@@ -418,7 +417,8 @@ static int gpio_secondary_fwnode_init(struct device *parent,
 		if (WARN_ON(!fwnode))
 			return -ENOENT;
 
-		phys_dev = acpi_get_first_physical_node(to_acpi_device(dev));
+		struct device *phys_dev __free(put_device) =
+				acpi_bus_get_primary_device(to_acpi_device(dev));
 		if (!phys_dev)
 			return dev_err_probe(parent, -ENODEV,
 					     "No physical device for ACPI GPIO dev: %pfwP\n",
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 8/17
#19 lore raw

Re: [PATCH v1 08/17] platform/x86: x86-android-tablets: Use acpi_bus_get_primary_device()

Quoted 30 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 drivers/platform/x86/x86-android-tablets/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/x86-android-tablets/core.c +0 -1
index cfff7f5eac5d..2c262f117235 100644
@@ -390,7 +390,6 @@ static int gpio_secondary_fwnode_init(struct device *parent,
 {
 	const struct software_node *const *swnode;
 	struct fwnode_handle *fwnode;
-	struct device *phys_dev;
 	int ret;
 
 	if (!node_group)

drivers/platform/x86/x86-android-tablets/core.c static int gpio_secondary_fwnode_init(struct device *parent, · line 424

Quoted 9 lines
drivers/platform/x86/x86-android-tablets/core.c +2 -1
@@ -418,7 +417,8 @@ static int gpio_secondary_fwnode_init(struct device *parent,
 		if (WARN_ON(!fwnode))
 			return -ENOENT;
 
-		phys_dev = acpi_get_first_physical_node(to_acpi_device(dev));
+		struct device *phys_dev __free(put_device) =
+				acpi_bus_get_primary_device(to_acpi_device(dev));
 		if (!phys_dev)
 			return dev_err_probe(parent, -ENODEV,
 					     "No physical device for ACPI GPIO dev: %pfwP\n",

Seems to be based on the latest code,

Signature · 1 line
 i.
maintainer Reviewed-by on v1 8/17
#20 lore raw

Re: [PATCH v1 08/17] platform/x86: x86-android-tablets: Use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

Hi,

Quoted 6 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

Quoted 6 lines

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

Thanks, patch looks good to me:

Regards,

Hans

Quoted 26 lines
---
 drivers/platform/x86/x86-android-tablets/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/x86-android-tablets/core.c +2 -2
index cfff7f5eac5d..2c262f117235 100644
@@ -390,7 +390,6 @@ static int gpio_secondary_fwnode_init(struct device *parent,
 {
 	const struct software_node *const *swnode;
 	struct fwnode_handle *fwnode;
-	struct device *phys_dev;
 	int ret;
 
 	if (!node_group)
@@ -418,7 +417,8 @@ static int gpio_secondary_fwnode_init(struct device *parent,
 		if (WARN_ON(!fwnode))
 			return -ENOENT;
 
-		phys_dev = acpi_get_first_physical_node(to_acpi_device(dev));
+		struct device *phys_dev __free(put_device) =
+				acpi_bus_get_primary_device(to_acpi_device(dev));
 		if (!phys_dev)
 			return dev_err_probe(parent, -ENODEV,
 					     "No physical device for ACPI GPIO dev: %pfwP\n",
author maintainer
#21 lore raw

PATCH 9/17 thunderbolt: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 drivers/thunderbolt/acpi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/thunderbolt/acpi.c +3 -2
index 53546bc477a5..be91bc604900 100644
@@ -17,8 +17,8 @@ static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data,
 	struct acpi_device *adev = acpi_fetch_acpi_dev(handle);
 	struct fwnode_handle *fwnode;
 	struct tb_nhi *nhi = data;
+	struct device *dev = NULL;
 	struct pci_dev *pdev;
-	struct device *dev;
 
 	if (!adev)
 		return AE_OK;
@@ -37,7 +37,7 @@ static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data,
 	 * USB3 ports might not even have a physical device yet if xHCI driver
 	 * isn't bound yet.
 	 */
-	dev = acpi_get_first_physical_node(adev);
+	dev = acpi_bus_get_primary_device(adev);
 	if (!dev || !dev_is_pci(dev))
 		goto out_put;
 
@@ -74,6 +74,7 @@ static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data,
 	}
 
 out_put:
+	put_device(dev);
 	fwnode_handle_put(fwnode);
 	return AE_OK;
 }
Signature · 1 line
2.51.0
Acked-by on v1 9/17
#22 lore raw

Re: [PATCH v1 09/17] thunderbolt: Switch to use acpi_bus_get_primary_device()

Quoted 6 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

Quoted 6 lines

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

author maintainer
#23 lore raw

PATCH 10/17 ALSA: hda: cs35l41: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 sound/hda/codecs/side-codecs/cs35l41_hda.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/hda/codecs/side-codecs/cs35l41_hda.c +1 -2
index 62296be45c55..32abb71dd401 100644
@@ -1926,8 +1926,7 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i
 	}
 
 	cs35l41->dacpi = adev;
-	struct device *physdev __free(put_device) =
-		get_device(acpi_get_first_physical_node(adev));
+	struct device *physdev __free(put_device) = acpi_bus_get_primary_device(adev);
 	if (!physdev) {
 		acpi_dev_put(adev);
 		return -ENODEV;
Signature · 1 line
2.51.0
author maintainer
#24 lore raw

PATCH 11/17 ALSA: hda: aw88399: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 sound/hda/codecs/side-codecs/aw88399_hda.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/hda/codecs/side-codecs/aw88399_hda.c +1 -2
index 11cef4923024..439ad45557a4 100644
@@ -209,8 +209,7 @@ static int aw88399_hda_acpi_probe(struct aw88399_hda *aw88399)
 		return -ENODEV;
 	}
 
-	struct device *physdev __free(put_device) =
-		get_device(acpi_get_first_physical_node(adev));
+	struct device *physdev __free(put_device) = acpi_bus_get_primary_device(adev);
 	acpi_dev_put(adev);
 	if (!physdev)
 		return -ENODEV;
Signature · 1 line
2.51.0
Acked-by on v1 11/17
#25 lore raw

Re: [PATCH v1 11/17] ALSA: hda: aw88399: Switch to use acpi_bus_get_primary_device()

Quoted 10 lines

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

author maintainer
#26 lore raw

PATCH 12/17 ALSA: hda: tas2781: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 sound/hda/codecs/side-codecs/tas2781_hda_i2c.c | 3 +--
 sound/hda/codecs/side-codecs/tas2781_hda_spi.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
sound/hda/codecs/side-codecs/tas2781_hda_i2c.c +1 -2
index 5e5f46c9fb6b..161ca965c63e 100644
@@ -100,8 +100,7 @@ static int tas2781_read_acpi(struct tasdevice_priv *p, const char *hid)
 		return -ENODEV;
 	}
 
-	struct device *physdev __free(put_device) =
-		get_device(acpi_get_first_physical_node(adev));
+	struct device *physdev __free(put_device) = acpi_bus_get_primary_device(adev);
 	ret = acpi_dev_get_resources(adev, &resources, tas2781_get_i2c_res, p);
 	if (ret < 0) {
 		dev_err(p->dev, "Failed to get ACPI resource.\n");
sound/hda/codecs/side-codecs/tas2781_hda_spi.c +1 -2
index da71b57a26ee..f3ba7132d2b8 100644
@@ -341,8 +341,7 @@ static int tas2781_read_acpi(struct tas2781_hda *tas_hda,
 
 	strscpy(p->dev_name, hid, sizeof(p->dev_name));
 
-	struct device *physdev __free(put_device) =
-		get_device(acpi_get_first_physical_node(adev));
+	struct device *physdev __free(put_device) = acpi_bus_get_primary_device(adev);
 	acpi_dev_put(adev);
 	if (!physdev)
 		return -ENODEV;
Signature · 1 line
2.51.0
author maintainer
#27 lore raw

PATCH 13/17 ASoC: amd: acp-es8336: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

It also fixes a device reference counting issue that may lead to a premature device release if gpiod_get_optional() fails in st_es8336_late_probe().

Fixes 02527c3f2300 ("ASoC: amd: add Machine driver for Jadeite platform")
---
 sound/soc/amd/acp-es8336.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/amd/acp-es8336.c +1 -1
index 9f3f11256788..34e953d1a3a7 100644
@@ -198,7 +198,7 @@ static int st_es8336_late_probe(struct snd_soc_card *card)
 	if (!adev)
 		return -ENODEV;
 
-	codec_dev = acpi_get_first_physical_node(adev);
+	codec_dev = acpi_bus_get_primary_device(adev);
 	acpi_dev_put(adev);
 	if (!codec_dev) {
 		dev_err(card->dev, "can not find codec dev\n");
Signature · 1 line
2.51.0
maintainer Acked-by on v1 13/17
#28 lore raw

Re: [PATCH v1 13/17] ASoC: amd: acp-es8336: Switch to use acpi_bus_get_primary_device()

Quoted 5 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

author maintainer
#29 lore raw

PATCH 14/17 ASoC: amd: acp3x-es83xx: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

It also fixes a device reference counting issue that may lead to a premature device release if devm_kzalloc() fails in acp3x_es83xx_probe().

Fixes 54fcd9dd44b2 ("ASoC: amd: acp: Add machine driver that enables sound for systems with a ES8336 codec")
---
 sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c +1 -1
index 3a640e652314..c522b421e1ec 100644
@@ -428,7 +428,7 @@ static int acp3x_es83xx_probe(struct snd_soc_card *card)
 			return -ENXIO;
 		}
 
-		codec_dev = acpi_get_first_physical_node(adev);
+		codec_dev = acpi_bus_get_primary_device(adev);
 		acpi_dev_put(adev);
 		if (!codec_dev) {
 			dev_warn(dev, "Error cannot find codec device, will defer probe\n");
Signature · 1 line
2.51.0
maintainer Acked-by on v1 14/17
#30 lore raw

Re: [PATCH v1 14/17] ASoC: amd: acp3x-es83xx: Switch to use acpi_bus_get_primary_device()

Quoted 5 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

author maintainer
#31 lore raw

PATCH 15/17 ASoC: intel: boards: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 sound/soc/intel/boards/bytcht_es8316.c     | 4 ++--
 sound/soc/intel/boards/bytcr_rt5640.c      | 4 ++--
 sound/soc/intel/boards/bytcr_rt5651.c      | 4 ++--
 sound/soc/intel/boards/cht_bsw_rt5645.c    | 5 ++---
 sound/soc/intel/boards/sof_cirrus_common.c | 2 +-
 sound/soc/intel/boards/sof_es8336.c        | 4 ++--
 6 files changed, 11 insertions(+), 12 deletions(-)
sound/soc/intel/boards/bytcht_es8316.c +2 -2
index ea387dc74273..4d8d1d176a49 100644
@@ -601,11 +601,11 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
 		return -ENOENT;
 	}
 
-	codec_dev = acpi_get_first_physical_node(adev);
+	codec_dev = acpi_bus_get_primary_device(adev);
 	acpi_dev_put(adev);
 	if (!codec_dev)
 		return -EPROBE_DEFER;
-	priv->codec_dev = get_device(codec_dev);
+	priv->codec_dev = codec_dev;
 
 	/* override platform name, if required */
 	byt_cht_es8316_card.dev = dev;
sound/soc/intel/boards/bytcr_rt5640.c +2 -2
index 40da3eea5fa7..c84b9a0fe65a 100644
@@ -1744,11 +1744,11 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
 		return -ENOENT;
 	}
 
-	codec_dev = acpi_get_first_physical_node(adev);
+	codec_dev = acpi_bus_get_primary_device(adev);
 	acpi_dev_put(adev);
 
 	if (codec_dev) {
-		priv->codec_dev = get_device(codec_dev);
+		priv->codec_dev = codec_dev;
 	} else {
 		/*
 		 * Special case for Android tablets where the codec i2c_client
sound/soc/intel/boards/bytcr_rt5651.c +2 -2
index 62cb4856c797..a0ed56d285bc 100644
@@ -943,11 +943,11 @@ static int snd_byt_rt5651_mc_probe(struct platform_device *pdev)
 		return -ENOENT;
 	}
 
-	codec_dev = acpi_get_first_physical_node(adev);
+	codec_dev = acpi_bus_get_primary_device(adev);
 	acpi_dev_put(adev);
 	if (!codec_dev)
 		return -EPROBE_DEFER;
-	priv->codec_dev = get_device(codec_dev);
+	priv->codec_dev = codec_dev;
 
 	/*
 	 * swap SSP0 if bytcr is detected
sound/soc/intel/boards/cht_bsw_rt5645.c +2 -3
index 249be121be15..4f20928a3604 100644
@@ -529,7 +529,6 @@ static int snd_cht_mc_probe(struct platform_device *pdev)
 	const char *platform_name;
 	struct cht_mc_private *drv;
 	struct acpi_device *adev;
-	struct device *codec_dev;
 	bool sof_parent;
 	bool found = false;
 	bool is_bytcr = false;
@@ -583,8 +582,8 @@ static int snd_cht_mc_probe(struct platform_device *pdev)
 		return -ENOENT;
 	}
 
-	/* acpi_get_first_physical_node() returns a borrowed ref, no need to deref */
-	codec_dev = acpi_get_first_physical_node(adev);
+	struct device *codec_dev __free(put_device) = acpi_bus_get_primary_device(adev);
+
 	acpi_dev_put(adev);
 	if (!codec_dev)
 		return -EPROBE_DEFER;
sound/soc/intel/boards/sof_cirrus_common.c +1 -1
index 88fc6cb2bfd4..a4ecb1f9a615 100644
@@ -168,7 +168,7 @@ static int cs35l41_compute_codec_conf(void)
 				 cs35l41_name_prefixes[uid]);
 			continue;
 		}
-		physdev = get_device(acpi_get_first_physical_node(adev));
+		physdev = acpi_bus_get_primary_device(adev);
 		acpi_dev_put(adev);
 		if (!physdev) {
 			pr_devel("Cannot find physical node for HID %s UID %u (%s)\n", CS35L41_HID,
sound/soc/intel/boards/sof_es8336.c +2 -2
index 9b016136c639..3c0d7155f059 100644
@@ -693,11 +693,11 @@ static int sof_es8336_probe(struct platform_device *pdev)
 		return -ENOENT;
 	}
 
-	codec_dev = acpi_get_first_physical_node(adev);
+	codec_dev = acpi_bus_get_primary_device(adev);
 	acpi_dev_put(adev);
 	if (!codec_dev)
 		return -EPROBE_DEFER;
-	priv->codec_dev = get_device(codec_dev);
+	priv->codec_dev = codec_dev;
 
 	ret = snd_soc_fixup_dai_links_platform_name(&sof_es8336_card,
 						    mach->mach_params.platform);
Signature · 1 line
2.51.0
maintainer Acked-by on v1 15/17
#32 lore raw

Re: [PATCH v1 15/17] ASoC: intel: boards: Switch to use acpi_bus_get_primary_device()

Quoted 6 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

Quoted 6 lines

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

author maintainer
#34 lore raw

PATCH 16/17 ASoC: loongson: Switch to use acpi_bus_get_primary_device()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

This addresses a potential use-after-free that may occur if the device returned by acpi_get_first_physical_node() is removed right after dropping its ACPI companion's physical_node_lock in that function.

---
 sound/soc/loongson/loongson_card.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/loongson/loongson_card.c +1 -2
index 6422cc1703b6..9f3907278462 100644
@@ -196,7 +196,6 @@ static int loongson_card_parse_acpi(struct loongson_card_data *data)
 	struct snd_soc_card *card = &data->snd_card;
 	const char *codec_dai_name;
 	struct acpi_device *adev;
-	struct device *phy_dev;
 	int i, ret;
 
 	/* fixup platform name based on reference node */
@@ -204,7 +203,7 @@ static int loongson_card_parse_acpi(struct loongson_card_data *data)
 	if (!adev)
 		return -ENOENT;
 
-	phy_dev = acpi_get_first_physical_node(adev);
+	struct device *phy_dev __free(put_device) = acpi_bus_get_primary_device(adev);
 	if (!phy_dev)
 		return -EPROBE_DEFER;
 
Signature · 1 line
2.51.0
maintainer Acked-by on v1 16/17
#35 lore raw

Re: [PATCH v1 16/17] ASoC: loongson: Switch to use acpi_bus_get_primary_device()

Quoted 5 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Replace acpi_get_first_physical_node() that is slated for removal with acpi_bus_get_primary_device() that takes a reference to the device it is about to return.

author maintainer
#36 lore raw

PATCH 17/17 ACPI: bus: Drop acpi_get_first_physical_node()

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Fold acpi_get_first_physical_node() into acpi_primary_dev_companion() that is its only remaining caller and drop its signature from the header file.

No intentional functional impact.

---
 drivers/acpi/bus.c   | 20 +++++---------------
 include/linux/acpi.h |  7 -------
 2 files changed, 5 insertions(+), 22 deletions(-)
drivers/acpi/bus.c +5 -15
index 808c6746be14..cc6989d88645 100644
@@ -809,24 +809,14 @@ struct device *acpi_bus_get_primary_device(struct acpi_device *adev)
 }
 EXPORT_SYMBOL_GPL(acpi_bus_get_primary_device);
 
-/**
- * acpi_get_first_physical_node - Find first physical node of an ACPI device
- * @adev:	ACPI device in question
- *
- * Return: First physical node of ACPI device @adev
- */
-struct device *acpi_get_first_physical_node(struct acpi_device *adev)
-{
-	guard(mutex)(&adev->physical_node_lock);
-
-	return primary_physical_device(adev);
-}
-EXPORT_SYMBOL_GPL(acpi_get_first_physical_node);
-
 static struct acpi_device *acpi_primary_dev_companion(struct acpi_device *adev,
 						      const struct device *dev)
 {
-	const struct device *phys_dev = acpi_get_first_physical_node(adev);
+	const struct device *phys_dev;
+
+	guard(mutex)(&adev->physical_node_lock);
+
+	phys_dev = primary_physical_device(adev);
 
 	return phys_dev && phys_dev == dev ? adev : NULL;
 }
include/linux/acpi.h +0 -7
index ba5234bd93a2..6f69819f9c9a 100644
@@ -105,8 +105,6 @@ static inline const char *acpi_dev_name(struct acpi_device *adev)
 	return dev_name(&adev->dev);
 }
 
-struct device *acpi_get_first_physical_node(struct acpi_device *adev);
-
 enum acpi_irq_model_id {
 	ACPI_IRQ_MODEL_PIC = 0,
 	ACPI_IRQ_MODEL_IOAPIC,
@@ -938,11 +936,6 @@ static inline const char *acpi_dev_name(struct acpi_device *adev)
 	return NULL;
 }
 
-static inline struct device *acpi_get_first_physical_node(struct acpi_device *adev)
-{
-	return NULL;
-}
-
 static inline void acpi_early_init(void) { }
 static inline void acpi_subsystem_init(void) { }
 
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 17/17
#37 lore raw

Re: [PATCH v1 17/17] ACPI: bus: Drop acpi_get_first_physical_node()

Quoted 8 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Fold acpi_get_first_physical_node() into acpi_primary_dev_companion() that is its only remaining caller and drop its signature from the header file.

No intentional functional impact.

Signature · 2 lines
Regards,
Sudeep