* [LTP] [PATCH] device-drivers/acpi/ltp_acpi_cmds: Fix build errors @ 2025-07-11 8:01 Tiezhu Yang 2025-07-15 9:24 ` Andrea Cervesato via ltp 0 siblings, 1 reply; 6+ messages in thread From: Tiezhu Yang @ 2025-07-11 8:01 UTC (permalink / raw) To: ltp There exist the following errors when building LTP: 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]. Since blkdev.h has been included in the C file, just remove unused include genhd.h to fix the build error. For the second and third errors: This is because acpi_bus_get_device() has been droped in the Linux kernel, in order to fix the build errors, just replace acpi_bus_get_device() with acpi_fetch_acpi_dev() like the kernel commit [2]. [1] https://git.kernel.org/torvalds/c/322cbb50de71 [2] https://git.kernel.org/torvalds/c/ac2a3feefad5 Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> --- testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c b/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c index d12dd6b94..b2d46e1a8 100644 --- a/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c +++ b/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c @@ -36,7 +36,6 @@ #include <linux/ioctl.h> #include <linux/pm.h> #include <linux/acpi.h> -#include <linux/genhd.h> #include <linux/dmi.h> #include <linux/nls.h> @@ -123,14 +122,13 @@ 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; - status = acpi_bus_get_device(handle, &device); - if (ACPI_SUCCESS(status)) + device = acpi_fetch_acpi_dev(handle); + if (device) sysfs_path = kobject_get_path(&device->dev.kobj, GFP_KERNEL); } @@ -398,9 +396,9 @@ static int acpi_test_bus(void) if (acpi_failure(status, "acpi_get_handle")) return 1; - prk_alert("TEST -- acpi_bus_get_device"); - status = acpi_bus_get_device(bus_handle, &device); - if (acpi_failure(status, "acpi_bus_get_device")) + prk_alert("TEST -- acpi_fetch_acpi_dev"); + device = acpi_fetch_acpi_dev(bus_handle); + if (!device) return 1; prk_alert("TEST -- acpi_bus_update_power "); -- 2.42.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] device-drivers/acpi/ltp_acpi_cmds: Fix build errors 2025-07-11 8:01 [LTP] [PATCH] device-drivers/acpi/ltp_acpi_cmds: Fix build errors Tiezhu Yang @ 2025-07-15 9:24 ` Andrea Cervesato via ltp 2025-07-15 11:23 ` Tiezhu Yang 0 siblings, 1 reply; 6+ messages in thread From: Andrea Cervesato via ltp @ 2025-07-15 9:24 UTC (permalink / raw) To: Tiezhu Yang, ltp Hi! On 7/11/25 10:01 AM, Tiezhu Yang wrote: > There exist the following errors when building LTP: > > 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]. Since blkdev.h has been included > in the C file, just remove unused include genhd.h to fix the build error. > > For the second and third errors: > > This is because acpi_bus_get_device() has been droped in the Linux kernel, > in order to fix the build errors, just replace acpi_bus_get_device() with > acpi_fetch_acpi_dev() like the kernel commit [2]. > > [1] https://git.kernel.org/torvalds/c/322cbb50de71 > [2] https://git.kernel.org/torvalds/c/ac2a3feefad5 These patches have been introduced in v5.18, but we support kernel until v4.4. If we really want to keep this code, we need to use autoconf in order to recognize acpi functions and to create a fallback file in lapi/genhd.h like we usually do for the older API. https://github.com/linux-test-project/ltp/blob/master/configure.ac https://github.com/linux-test-project/ltp/tree/master/include/lapi - Andrea -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] device-drivers/acpi/ltp_acpi_cmds: Fix build errors 2025-07-15 9:24 ` Andrea Cervesato via ltp @ 2025-07-15 11:23 ` Tiezhu Yang 2025-07-17 14:09 ` Petr Vorel 0 siblings, 1 reply; 6+ messages in thread From: Tiezhu Yang @ 2025-07-15 11:23 UTC (permalink / raw) To: Andrea Cervesato, ltp On 2025/7/15 下午5:24, Andrea Cervesato wrote: > Hi! > > On 7/11/25 10:01 AM, Tiezhu Yang wrote: >> There exist the following errors when building LTP: >> >> 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]. Since blkdev.h has been included >> in the C file, just remove unused include genhd.h to fix the build error. >> >> For the second and third errors: >> >> This is because acpi_bus_get_device() has been droped in the Linux >> kernel, >> in order to fix the build errors, just replace acpi_bus_get_device() with >> acpi_fetch_acpi_dev() like the kernel commit [2]. >> >> [1] https://git.kernel.org/torvalds/c/322cbb50de71 >> [2] https://git.kernel.org/torvalds/c/ac2a3feefad5 > > These patches have been introduced in v5.18, but we support kernel until > v4.4. If we really want to keep this code, There are fatal errors about the following two files: testcases/kernel/device-drivers/tbio/tbio_kernel/ltp_tbio.c testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c I guess they are not used frequently. I am not sure what is the proper way to handle this case. (1) just keep it as is (2) remove them entirely (3) adjust them for different kernel versions Furthermore, I found there are many warnings except the above fatal errors, is it necessary to silence them or keep it as is? > we need to use autoconf in > order to recognize acpi functions and to create a fallback file in > lapi/genhd.h like we usually do for the older API. > > https://github.com/linux-test-project/ltp/blob/master/configure.ac > https://github.com/linux-test-project/ltp/tree/master/include/lapi If necessary, will try. Thanks, Tiezhu -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] device-drivers/acpi/ltp_acpi_cmds: Fix build errors 2025-07-15 11:23 ` Tiezhu Yang @ 2025-07-17 14:09 ` Petr Vorel 2025-07-18 3:59 ` Tiezhu Yang 0 siblings, 1 reply; 6+ messages in thread From: Petr Vorel @ 2025-07-17 14:09 UTC (permalink / raw) To: Tiezhu Yang; +Cc: Ricardo B. Marliere, ltp Hi Tiezhu, all, [ Cc Jan and Ricardo in case I overlook something ] > On 2025/7/15 下午5:24, Andrea Cervesato wrote: > > Hi! > > On 7/11/25 10:01 AM, Tiezhu Yang wrote: > > > There exist the following errors when building LTP: > > > 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]. Since blkdev.h has been included > > > in the C file, just remove unused include genhd.h to fix the build error. > > > For the second and third errors: > > > This is because acpi_bus_get_device() has been droped in the Linux > > > kernel, > > > in order to fix the build errors, just replace acpi_bus_get_device() with > > > acpi_fetch_acpi_dev() like the kernel commit [2]. > > > [1] https://git.kernel.org/torvalds/c/322cbb50de71 > > > [2] https://git.kernel.org/torvalds/c/ac2a3feefad5 > > These patches have been introduced in v5.18, but we support kernel until > > v4.4. If we really want to keep this code, > There are fatal errors about the following two files: > testcases/kernel/device-drivers/tbio/tbio_kernel/ltp_tbio.c > testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c > I guess they are not used frequently. > I am not sure what is the proper way to handle this case. > (1) just keep it as is > (2) remove them entirely > (3) adjust them for different kernel versions First, thanks a lot for looking into LTP test kernel modules. Indeed ltp_acpi_cmds.ko and ltp_tbio.ko source code do not compile on newer kernels and there are more of them using linux/genhd.h (but only ltp_acpi_cmds.ko uses acpi_bus_get_device()). But Andrea is correct we want to care about old kernels up to 4.4 (see [1]). @@ -36,7 +36,6 @@ #include <linux/ioctl.h> #include <linux/pm.h> #include <linux/acpi.h> -#include <linux/genhd.h> Due the above could you please take the approach Ricardo did in 82e38a1f24 ("block_dev: Convert to new API") - wrap with ifndef? #ifndef DISK_NAME_LEN # include <linux/genhd.h> #endif BTW I would personally use #ifndef HAVE_LINUX_BLKDEV_H than checking for DISK_NAME_LEN as we already check for linux/blkdev.h in configure.ac, but that's a minor detail. > Furthermore, I found there are many warnings except the above > fatal errors, is it necessary to silence them or keep it as is? > > we need to use autoconf in order to recognize acpi functions and to > > create a fallback file in lapi/genhd.h like we usually do for the older > > API. > > https://github.com/linux-test-project/ltp/blob/master/configure.ac > > https://github.com/linux-test-project/ltp/tree/master/include/lapi Yes we need to #if #else macros for acpi_bus_get_device() vs. acpi_fetch_acpi_dev(). The timeline of relevant changes in kernel: 5.17-rc1: added acpi_fetch_acpi_dev() 5.18-rc1: removed linux/genhd.h 5.18-rc2: removed all remaining uses of acpi_bus_get_device() 5.19-rc1: removed acpi_bus_get_device() Both functions are in drivers/acpi/scan.c, and prototype is only in kernel only header include/acpi/acpi_bus.h - out of UAPI exported to user space. It looks to me that we can happily expect that acpi_bus_get_device() can be used only with linux/genhd.h. That makes things simple, because if I'm wrong the detection would have to be added as a custom macro in m4 (probably just extend m4/ltp-kernel_devel.m4) because AC_COMPILE_IFELSE() which is in configure.ac is IMHO not possible to use for kernel modules. And yes, you could write macro in newly created include/lapi/module.h to hide ifdef but IMHO not worth just for these 2 functions (used only in ltp_acpi_cmds.ko). FYI info about lapi in old doc [2] FYI LTP autotools kernel related helpers: * include/mk/module.mk (used to compile kernel modules) * m4/ltp-kernel_devel.m4 (detect support for building modules, e.g. whether are kernel-default-devel-* openSUSE or linux-kbuild-* packages installed) Kind regards, Petr [1] https://linux-test-project.readthedocs.io/en/latest/users/supported_systems.html#kernel-version [2] https://github.com/linux-test-project/ltp/blob/master/doc/old/C-Test-API.asciidoc#lapi-headers > If necessary, will try. > Thanks, > Tiezhu -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] device-drivers/acpi/ltp_acpi_cmds: Fix build errors 2025-07-17 14:09 ` Petr Vorel @ 2025-07-18 3:59 ` Tiezhu Yang 2025-07-18 6:30 ` Petr Vorel 0 siblings, 1 reply; 6+ messages in thread From: Tiezhu Yang @ 2025-07-18 3:59 UTC (permalink / raw) To: Petr Vorel; +Cc: Ricardo B. Marliere, ltp On 2025/7/17 下午10:09, Petr Vorel wrote: > Hi Tiezhu, all, ... > Due the above could you please take the approach Ricardo did in 82e38a1f24 > ("block_dev: Convert to new API") - wrap with ifndef? > > #ifndef DISK_NAME_LEN > # include <linux/genhd.h> > #endif > > BTW I would personally use #ifndef HAVE_LINUX_BLKDEV_H than checking for > DISK_NAME_LEN as we already check for linux/blkdev.h in configure.ac, but that's > a minor detail. I think use "#ifndef DISK_NAME_LEN" is proper. Because both genhd.h and blkdev.h are exist before the kernel commit 322cbb50de71 ("block: remove genhd.h"), HAVE_LINUX_BLKDEV_H seems always define as 1 for the new and old kernel versions. But the definition DISK_NAME_LEN was moved from genhd.h into blkdev.h after that commit, because blkdev.h is included first, so we can check DISK_NAME_LEN, it should include genhd.h ifndef DISK_NAME_LEN. > Yes we need to #if #else macros for acpi_bus_get_device() vs. > acpi_fetch_acpi_dev(). Here is a draft change, I will post a formal v2 patch if you are OK. ----->8----- diff --git a/configure.ac b/configure.ac index 11e599a81..1f6e2b1b9 100644 --- a/configure.ac +++ b/configure.ac @@ -100,6 +100,7 @@ AC_SUBST(HAVE_FTS_H, $have_fts) AC_CHECK_HEADERS(linux/vm_sockets.h, [], [], [#include <sys/socket.h>]) AC_CHECK_FUNCS_ONCE([ \ + acpi_bus_get_device \ cachestat \ clone3 \ close_range \ diff --git a/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c b/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c index d12dd6b94..f68014732 100644 --- a/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c +++ b/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c @@ -36,7 +36,9 @@ #include <linux/ioctl.h> #include <linux/pm.h> #include <linux/acpi.h> +#ifndef DISK_NAME_LEN #include <linux/genhd.h> +#endif #include <linux/dmi.h> #include <linux/nls.h> @@ -123,14 +125,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; +#ifdef HAVE_ACPI_BUS_GET_DEVICE + 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,9 +406,15 @@ static int acpi_test_bus(void) if (acpi_failure(status, "acpi_get_handle")) return 1; +#ifdef HAVE_ACPI_BUS_GET_DEVICE 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 "); Thanks, Tiezhu -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] device-drivers/acpi/ltp_acpi_cmds: Fix build errors 2025-07-18 3:59 ` Tiezhu Yang @ 2025-07-18 6:30 ` Petr Vorel 0 siblings, 0 replies; 6+ messages in thread From: Petr Vorel @ 2025-07-18 6:30 UTC (permalink / raw) To: Tiezhu Yang; +Cc: Ricardo B. Marliere, ltp Hi Tiezhu, > On 2025/7/17 下午10:09, Petr Vorel wrote: > > Hi Tiezhu, all, > ... > > Due the above could you please take the approach Ricardo did in 82e38a1f24 > > ("block_dev: Convert to new API") - wrap with ifndef? > > #ifndef DISK_NAME_LEN > > # include <linux/genhd.h> > > #endif > > BTW I would personally use #ifndef HAVE_LINUX_BLKDEV_H than checking for > > DISK_NAME_LEN as we already check for linux/blkdev.h in configure.ac, but that's > > a minor detail. > I think use "#ifndef DISK_NAME_LEN" is proper. I'm sorry, I meant #ifdef HAVE_LINUX_GENHD_H (that is what is being checked in configure.ac). > Because both genhd.h and blkdev.h are exist before the kernel > commit 322cbb50de71 ("block: remove genhd.h"), HAVE_LINUX_BLKDEV_H > seems always define as 1 for the new and old kernel versions. > But the definition DISK_NAME_LEN was moved from genhd.h into blkdev.h > after that commit, because blkdev.h is included first, so we can check > DISK_NAME_LEN, it should include genhd.h ifndef DISK_NAME_LEN. Sure, this works now and it's good enough. The reason I would personally depend on header based check #ifdef HAVE_LINUX_GENHD_H is that if kernel devs are ok to remove whole header they can of course also rename or completely remove DISK_NAME_LEN definition. > > Yes we need to #if #else macros for acpi_bus_get_device() vs. > > acpi_fetch_acpi_dev(). > Here is a draft change, I will post a formal v2 patch if you are OK. > ----->8----- > diff --git a/configure.ac b/configure.ac > index 11e599a81..1f6e2b1b9 100644 > --- a/configure.ac > +++ b/configure.ac > @@ -100,6 +100,7 @@ AC_SUBST(HAVE_FTS_H, $have_fts) > AC_CHECK_HEADERS(linux/vm_sockets.h, [], [], [#include <sys/socket.h>]) > AC_CHECK_FUNCS_ONCE([ \ > + acpi_bus_get_device \ I'm sorry this will not work. AC_CHECK_FUNCS_ONCE() works only for userspace functions (and require AC_CHECK_HEADERS() with the userspace header to be passed before). But as I wrote before acpi_bus_get_device() and acpi_fetch_acpi_dev() is only in kernel source drivers/acpi/scan.c (+ prototype is only in kernel only header include/acpi/acpi_bus.h but it would not help). We have AC_COMPILE_IFELSE(), which can be used for detecting static inline UAPI functions, e.g. AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( [[ #include <linux/dccp.h> #include <stddef.h> ]], [[ struct dccp_hdr *dh; (void)dccp_packet_hdr_len(dh->dccph_type); ]] )], [AC_DEFINE([HAVE_DCCP_PACKET_HDR_LEN], [1], [Define if dccp_packet_hdr_len is available])], [] ) But again, this is not the case of acpi_bus_get_device() nor acpi_fetch_acpi_dev(). Can we get back to 5.18 based check? Given the timeline I wrote above this should be sufficient: #ifdef HAVE_LINUX_GENHD_H => acpi_fetch_acpi_dev() #else => acpi_bus_get_device() #endif But probably the best way would be to check against 5.18: #include <linux/version.h> #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) => acpi_fetch_acpi_dev() #else => acpi_bus_get_device() #endif > cachestat \ > clone3 \ > close_range \ > diff --git a/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c > b/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c > index d12dd6b94..f68014732 100644 > --- a/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c > +++ b/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c > @@ -36,7 +36,9 @@ > #include <linux/ioctl.h> > #include <linux/pm.h> > #include <linux/acpi.h> > +#ifndef DISK_NAME_LEN > #include <linux/genhd.h> > +#endif > #include <linux/dmi.h> > #include <linux/nls.h> > @@ -123,14 +125,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; > +#ifdef HAVE_ACPI_BUS_GET_DEVICE > + 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,9 +406,15 @@ static int acpi_test_bus(void) > if (acpi_failure(status, "acpi_get_handle")) > return 1; > +#ifdef HAVE_ACPI_BUS_GET_DEVICE > 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 "); Please while you're at it remove trailing whitespace: prk_alert("TEST -- acpi_bus_update_power"); The rest LGTM. Kind regards, Petr > Thanks, > Tiezhu -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-07-18 6:30 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-07-11 8:01 [LTP] [PATCH] device-drivers/acpi/ltp_acpi_cmds: Fix build errors Tiezhu Yang 2025-07-15 9:24 ` Andrea Cervesato via ltp 2025-07-15 11:23 ` Tiezhu Yang 2025-07-17 14:09 ` Petr Vorel 2025-07-18 3:59 ` Tiezhu Yang 2025-07-18 6:30 ` Petr Vorel
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.