:p
atchew
Login
Setting the devices' numa_node needs to be done in platform_device_register_full(), because that's where the platform device object is allocated. Fixes: 4a60406d3592 ("driver core: platform: expose numa_node to users in sysfs") Cc: stable@vger.kernel.org Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202309122309.mbxAnAIe-lkp@intel.com/ Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Rafael J. Wysocki <rafael@kernel.org> Signed-off-by: Jinhui Guo <guojinhui.liam@bytedance.com> --- V5 -> V6: 1. Update subject to correct function name platform_device_add(). 2. Provide a more clear and accurate description of the changes made in commit (suggested by Rafael J. Wysocki). 3. Add reviewer name. V4 -> V5: Add Cc: stable line and changes from the previous submited patches. V3 -> V4: Refactor code to be an ACPI function call. V2 -> V3: Fix Signed-off name. V1 -> V2: Fix compile error without enabling CONFIG_ACPI. --- drivers/acpi/acpi_platform.c | 4 +--- drivers/base/platform.c | 1 + include/linux/acpi.h | 5 +++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c index XXXXXXX..XXXXXXX 100644 --- a/drivers/acpi/acpi_platform.c +++ b/drivers/acpi/acpi_platform.c @@ -XXX,XX +XXX,XX @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev, if (IS_ERR(pdev)) dev_err(&adev->dev, "platform device creation failed: %ld\n", PTR_ERR(pdev)); - else { - set_dev_node(&pdev->dev, acpi_get_node(adev->handle)); + else dev_dbg(&adev->dev, "created platform device %s\n", dev_name(&pdev->dev)); - } kfree(resources); diff --git a/drivers/base/platform.c b/drivers/base/platform.c index XXXXXXX..XXXXXXX 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -XXX,XX +XXX,XX @@ struct platform_device *platform_device_register_full( goto err; } + set_dev_node(&pdev->dev, ACPI_NODE_GET(ACPI_COMPANION(&pdev->dev))); ret = platform_device_add(pdev); if (ret) { err: diff --git a/include/linux/acpi.h b/include/linux/acpi.h index XXXXXXX..XXXXXXX 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -XXX,XX +XXX,XX @@ static inline int acpi_get_node(acpi_handle handle) return 0; } #endif + +#define ACPI_NODE_GET(adev) ((adev) && (adev)->handle ? \ + acpi_get_node((adev)->handle) : NUMA_NO_NODE) + extern int pnpacpi_disabled; #define PXM_INVAL (-1) @@ -XXX,XX +XXX,XX @@ const char *acpi_get_subsystem_id(acpi_handle handle); #define ACPI_COMPANION_SET(dev, adev) do { } while (0) #define ACPI_HANDLE(dev) (NULL) #define ACPI_HANDLE_FWNODE(fwnode) (NULL) +#define ACPI_NODE_GET(adev) NUMA_NO_NODE #include <acpi/acpi_numa.h> -- 2.20.1
Setting the devices' numa_node needs to be done in platform_device_register_full(), because that's where the platform device object is allocated. Fixes: 4a60406d3592 ("driver core: platform: expose numa_node to users in sysfs") Cc: stable@vger.kernel.org Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202309122309.mbxAnAIe-lkp@intel.com/ Signed-off-by: Jinhui Guo <guojinhui.liam@bytedance.com> --- V6 -> V7 1. Fix bug directly by adding numa_node to struct platform_device_info (suggested by Rafael J. Wysocki). 2. Remove reviewer name. V5 -> V6: 1. Update subject to correct function name platform_device_add(). 2. Provide a more clear and accurate description of the changes made in commit (suggested by Rafael J. Wysocki). 3. Add reviewer name. V4 -> V5: Add Cc: stable line and changes from the previous submited patches. V3 -> V4: Refactor code to be an ACPI function call (suggested by Greg Kroah-Hartman). V2 -> V3: Fix Signed-off name. V1 -> V2: Fix compile error without enabling CONFIG_ACPI. --- drivers/acpi/acpi_platform.c | 5 ++--- drivers/base/platform.c | 4 ++++ include/linux/platform_device.h | 26 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c index XXXXXXX..XXXXXXX 100644 --- a/drivers/acpi/acpi_platform.c +++ b/drivers/acpi/acpi_platform.c @@ -XXX,XX +XXX,XX @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev, pdevinfo.num_res = count; pdevinfo.fwnode = acpi_fwnode_handle(adev); pdevinfo.properties = properties; + platform_devinfo_set_node(&pdevinfo, acpi_get_node(adev->handle)); if (acpi_dma_supported(adev)) pdevinfo.dma_mask = DMA_BIT_MASK(32); @@ -XXX,XX +XXX,XX @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev, if (IS_ERR(pdev)) dev_err(&adev->dev, "platform device creation failed: %ld\n", PTR_ERR(pdev)); - else { - set_dev_node(&pdev->dev, acpi_get_node(adev->handle)); + else dev_dbg(&adev->dev, "created platform device %s\n", dev_name(&pdev->dev)); - } kfree(resources); diff --git a/drivers/base/platform.c b/drivers/base/platform.c index XXXXXXX..XXXXXXX 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -XXX,XX +XXX,XX @@ struct platform_device *platform_device_register_full( { int ret; struct platform_device *pdev; + int numa_node = platform_devinfo_get_node(pdevinfo); pdev = platform_device_alloc(pdevinfo->name, pdevinfo->id); if (!pdev) @@ -XXX,XX +XXX,XX @@ struct platform_device *platform_device_register_full( goto err; } + if (numa_node >= 0) + set_dev_node(&pdev->dev, numa_node); + ret = platform_device_add(pdev); if (ret) { err: diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index XXXXXXX..XXXXXXX 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -XXX,XX +XXX,XX @@ struct platform_device_info { u64 dma_mask; const struct property_entry *properties; + +#ifdef CONFIG_NUMA + int numa_node; /* NUMA node this platform device is close to plus 1 */ +#endif }; extern struct platform_device *platform_device_register_full( const struct platform_device_info *pdevinfo); +#ifdef CONFIG_NUMA +static inline int platform_devinfo_get_node(const struct platform_device_info *pdevinfo) +{ + return pdevinfo ? pdevinfo->numa_node - 1 : NUMA_NO_NODE; +} + +static inline void platform_devinfo_set_node(struct platform_device_info *pdevinfo, + int node) +{ + pdevinfo->numa_node = node + 1; +} +#else +static inline int platform_devinfo_get_node(const struct platform_device_info *pdevinfo) +{ + return NUMA_NO_NODE; +} + +static inline void platform_devinfo_set_node(struct platform_device_info *pdevinfo, + int node) +{} +#endif + /** * platform_device_register_resndata - add a platform-level device with * resources and platform-specific data -- 2.20.1