ACPI: Replace acpi_get_first_physical_node() with acpi_bus_get_primary_device()
Subsystems (17)
Rafael J. Wysocki
maintainercover 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!
Rafael J. Wysocki
maintainerPATCH 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
@@ -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
@@ -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
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.his included inlinux/acpi.honly ifCONFIG_ACPIis set, but it contains declarations that are useful otherwise too.
Quoted 8 lines
For consistency, modify
linux/acpi.hto always includeacpi/acpi_bus.hand update the latter to avoid exposing too much whenCONFIG_ACPIis not set.Since
acpi_has_method()is called from some code build whenCONFIG_ACPIis unset, add a stub for it to the !CONFIG_ACPI block inacpi/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]
Rafael J. Wysocki (Intel)
maintainerRe: [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.his included inlinux/acpi.honly ifCONFIG_ACPIis set, but it contains declarations that are useful otherwise too.Quoted 8 lines
For consistency, modify
linux/acpi.hto always includeacpi/acpi_bus.hand update the latter to avoid exposing too much whenCONFIG_ACPIis not set.Since
acpi_has_method()is called from some code build whenCONFIG_ACPIis unset, add a stub for it to the !CONFIG_ACPI block inacpi/acpi_bus.h.
Quoted 4 lines
Reviewed-by Sudeep Holla <[email protected]>I was planning to just pull
acpi_device_hid()out so that I can get rid ofCONFIG_ACPIin [1]. This looks much more elegant. Thanks for doing it.
Anytime, and thank you!
Quoted 3 lines
Rafael J. Wysocki
maintainerPATCH 2/17 ACPI: amba: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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
@@ -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
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 withacpi_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'sphysical_node_lockin that function.
Quoted 5 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/acpi/arm64/amba.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Thanks
Hanjun
Re: [PATCH v1 02/17] ACPI: amba: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiQuoted 11 lines · Rafael J. Wysocki
From: "Rafael J. Wysocki" <[email protected]>
Replace
acpi_get_first_physical_node()that is slated for removal withacpi_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'sphysical_node_lockin that function.
Signature · 2 lines
Regards, Sudeep
Rafael J. Wysocki
maintainerPATCH 3/17 efi/dev-path-parser: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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
@@ -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
Rafael J. Wysocki
maintainerPATCH 4/17 iommu/arm-smmu-v3: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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
@@ -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
Rafael J. Wysocki
maintainerPATCH 5/17 platform/x86: yogabook: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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
@@ -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
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 withacpi_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'sphysical_node_lockin that function.Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/platform/x86/lenovo/yogabook.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/platform/x86/lenovo/yogabook.c +1
-1@@ -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
-1if (!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.
Re: [PATCH v1 05/17] platform/x86: yogabook: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiHi,
Quoted 6 lines · Rafael J. Wysocki
From: "Rafael J. Wysocki" <[email protected]>
Replace
acpi_get_first_physical_node()that is slated for removal withacpi_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'sphysical_node_lockin that function.Signed-off-by Rafael J. Wysocki <[email protected]>
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@@ -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;
Re: [PATCH v1 05/17] platform/x86: yogabook: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiQuoted 37 lines · Rafael J. Wysocki
From: "Rafael J. Wysocki" <[email protected]>
Replace
acpi_get_first_physical_node()that is slated for removal withacpi_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'sphysical_node_lockin that function.Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/platform/x86/lenovo/yogabook.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/platform/x86/lenovo/yogabook.c +2
-2@@ -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
Rafael J. Wysocki
maintainerPATCH 6/17 platform/x86: serdev_helpers: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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
@@ -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
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 withacpi_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'sphysical_node_lockin that function.Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/platform/x86/serdev_helpers.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/platform/x86/serdev_helpers.h +0
-0
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.
Re: [PATCH v1 06/17] platform/x86: serdev_helpers: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiHi,
Quoted 6 lines · Rafael J. Wysocki
From: "Rafael J. Wysocki" <[email protected]>
Replace
acpi_get_first_physical_node()that is slated for removal withacpi_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'sphysical_node_lockin that function.Signed-off-by Rafael J. Wysocki <[email protected]>
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@@ -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",
Rafael J. Wysocki
maintainerPATCH 7/17 platform/x86: apple-gmux: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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
@@ -109,7 +109,7 @@ static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, enum apple_gmux_tyif (!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
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 withacpi_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'sphysical_node_lockin that function.Signed-off-by Rafael J. Wysocki <[email protected]>
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@@ -109,7 +109,7 @@ static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, enum apple_gmux_tyif (!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;
Rafael J. Wysocki
maintainerPATCH 8/17 platform/x86: x86-android-tablets: Use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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
@@ -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
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 withacpi_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'sphysical_node_lockin that function.Signed-off-by Rafael J. Wysocki <[email protected]>--- 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@@ -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.
Re: [PATCH v1 08/17] platform/x86: x86-android-tablets: Use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiHi,
Quoted 6 lines · Rafael J. Wysocki
From: "Rafael J. Wysocki" <[email protected]>
Replace
acpi_get_first_physical_node()that is slated for removal withacpi_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'sphysical_node_lockin that function.Signed-off-by Rafael J. Wysocki <[email protected]>
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@@ -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",
Rafael J. Wysocki
maintainerPATCH 9/17 thunderbolt: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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
@@ -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
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 withacpi_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'sphysical_node_lockin that function.Signed-off-by Rafael J. Wysocki <[email protected]>
Rafael J. Wysocki
maintainerPATCH 10/17 ALSA: hda: cs35l41: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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
@@ -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
Rafael J. Wysocki
maintainerPATCH 11/17 ALSA: hda: aw88399: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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
@@ -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
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 withacpi_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'sphysical_node_lockin that function.
Rafael J. Wysocki
maintainerPATCH 12/17 ALSA: hda: tas2781: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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
@@ -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
@@ -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
Rafael J. Wysocki
maintainerPATCH 13/17 ASoC: amd: acp-es8336: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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().
--- sound/soc/amd/acp-es8336.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/amd/acp-es8336.c +1 -1
@@ -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
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 withacpi_bus_get_primary_device()that takes a reference to the device it is about to return.
Rafael J. Wysocki
maintainerPATCH 14/17 ASoC: amd: acp3x-es83xx: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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().
--- 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
@@ -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
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 withacpi_bus_get_primary_device()that takes a reference to the device it is about to return.
Rafael J. Wysocki
maintainerPATCH 15/17 ASoC: intel: boards: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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 withacpi_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'sphysical_node_lockin that function.Signed-off-by Rafael J. Wysocki <[email protected]>
Re: [PATCH v1 15/17] ASoC: intel: boards: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
From: "Rafael J. Wysocki" <[email protected]>
Replace
acpi_get_first_physical_node()that is slated for removal withacpi_bus_get_primary_device()that takes a reference to the device it is about to return.
Rafael J. Wysocki
maintainerPATCH 16/17 ASoC: loongson: Switch to use acpi_bus_get_primary_device()
In reply to Rafael J. WysockiFrom: "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
@@ -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
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 withacpi_bus_get_primary_device()that takes a reference to the device it is about to return.
Rafael J. Wysocki
maintainerPATCH 17/17 ACPI: bus: Drop acpi_get_first_physical_node()
In reply to Rafael J. WysockiFrom: "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
@@ -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
@@ -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
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()intoacpi_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