[LTP] [PATCH v2] device-drivers/acpi/ltp_acpi_cmds: Fix build errors
Tiezhu Yang
yangtiezhu@loongson.cn
Fri Jul 18 10:29:35 CEST 2025
There exist the following errors when building LTP on the
latest Linux kernel v6.16-rc6:
ltp_acpi_cmds.c:39:10: fatal error: linux/genhd.h: No such file or directory
ltp_acpi_cmds.c:131:18: error: implicit declaration of function 'acpi_bus_get_device'
ltp_acpi_cmds.c:400:18: error: implicit declaration of function 'acpi_bus_get_device'
For the first error:
This is because genhd.h has been removed in the Linux kernel,
the contents of genhd.h was folded into blkdev.h [1].
Add linux/genhd.h into AC_CHECK_HEADERS_ONCE of configure.ac,
define HAVE_LINUX_GENHD_H to 1 if you have the <linux/genhd.h>
header file, then use #ifdef HAVE_LINUX_GENHD_H to include it.
For the second and third errors:
This is because acpi_bus_get_device() has been removed in the
Linux kernel [2] since v5.18-rc2 [3], the best way is to use
acpi_bus_get_device() if the kernel version < 5.18 and use
acpi_fetch_acpi_dev() if the kernel version >= 5.18.
While at it, remove the trailing whitespace in the following
code: prk_alert("TEST -- acpi_bus_update_power ").
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=322cbb50de71 [1]
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ac2a3feefad5 [2]
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/?h=v5.18-rc2 [3]
Suggested-by: Andrea Cervesato <andrea.cervesato@suse.com>
Suggested-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
Thanks Andrea and Petr very much for your suggestions, I appreciate it.
configure.ac | 1 +
.../device-drivers/acpi/ltp_acpi_cmds.c | 19 +++++++++++++++++--
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index 11e599a81..cf37c58be 100644
--- a/configure.ac
+++ b/configure.ac
@@ -62,6 +62,7 @@ AC_CHECK_HEADERS_ONCE([ \
linux/dccp.h \
linux/futex.h \
linux/genetlink.h \
+ linux/genhd.h \
linux/if_alg.h \
linux/if_ether.h \
linux/if_packet.h \
diff --git a/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c b/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c
index d12dd6b94..02c1567b4 100644
--- a/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c
+++ b/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c
@@ -36,9 +36,12 @@
#include <linux/ioctl.h>
#include <linux/pm.h>
#include <linux/acpi.h>
+#ifdef HAVE_LINUX_GENHD_H
#include <linux/genhd.h>
+#endif
#include <linux/dmi.h>
#include <linux/nls.h>
+#include <linux/version.h>
#include "ltp_acpi.h"
@@ -123,14 +126,20 @@ static void get_crs_object(acpi_handle handle)
static void get_sysfs_path(acpi_handle handle)
{
- acpi_status status;
struct acpi_device *device;
kfree(sysfs_path);
sysfs_path = NULL;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0)
+ acpi_status status;
+
status = acpi_bus_get_device(handle, &device);
if (ACPI_SUCCESS(status))
+#else
+ device = acpi_fetch_acpi_dev(handle);
+ if (device)
+#endif
sysfs_path = kobject_get_path(&device->dev.kobj, GFP_KERNEL);
}
@@ -398,12 +407,18 @@ static int acpi_test_bus(void)
if (acpi_failure(status, "acpi_get_handle"))
return 1;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0)
prk_alert("TEST -- acpi_bus_get_device");
status = acpi_bus_get_device(bus_handle, &device);
if (acpi_failure(status, "acpi_bus_get_device"))
+#else
+ prk_alert("TEST -- acpi_fetch_acpi_dev");
+ device = acpi_fetch_acpi_dev(bus_handle);
+ if (!device)
+#endif
return 1;
- prk_alert("TEST -- acpi_bus_update_power ");
+ prk_alert("TEST -- acpi_bus_update_power");
status = acpi_bus_update_power(device->handle, &state);
if (acpi_failure(status, "error reading power state"))
return 1;
--
2.42.0
More information about the ltp
mailing list