[PATCH] Fix the problem that kunit cannot run

From: bajing

Date: Mon Oct 27 2025 - 05:20:09 EST


When running ./tools/testing/kunit/kunit.py run,the error for mm/swap.h
is as follows:
ERROR:root:In file included from ../mm/shmem.c:43:
../mm/swap.h: In function ‘non_swapcache_batch’:
../mm/swap.h:66:19: error: implicit declaration of function ‘swp_offset’;
did you mean ‘pud_offset’? [-Werror=implicit-function-declaration]
66 | pgoff_t offset = swp_offset(entry);
| ^~~~~~~~~~
| pud_offset
In file included from ../mm/shmem.c:68:
../include/linux/swapops.h: At top level:
../include/linux/swapops.h:107:23: error: conflicting types for ‘swp_offset’
107 | static inline pgoff_t swp_offset(swp_entry_t entry)
| ^~~~~~~~~~
In file included from ../mm/shmem.c:43:
../mm/swap.h:66:19: note: previous implicit declaration of ‘swp_offset’ was here
66 | pgoff_t offset = swp_offset(entry);
| ^~~~~~~~~~
cc1: some warnings being treated as errors
make[4]: *** [../scripts/Makefile.build:243: mm/shmem.o] Error 1
make[3]: *** [../scripts/Makefile.build:480: mm] Error 2
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [/home/openeuler/kernel/Makefile:1924: .] Error 2
make[1]: *** [/home/openeuler/kernel/Makefile:234: __sub-make] Error 2
make: *** [Makefile:234: __sub-make] Error 2

Signed-off-by: bajing <bajing@xxxxxxxxxxxxxxxxxxxx>
---
mm/swap.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/mm/swap.h b/mm/swap.h
index 26fa536a8947..04695e1af068 100644
--- a/mm/swap.h
+++ b/mm/swap.h
@@ -4,6 +4,7 @@

#ifdef CONFIG_SWAP
#include <linux/blk_types.h> /* for bio_end_io_t */
+#include <linux/swapops.h>

/* linux/mm/page_io.c */
int sio_pool_init(void);
--
2.50.1.windows.1