Skip to content

Commit 4af307f

Browse files
amboarstorulf
authored andcommitted
mmc: sdhci-of-aspeed: Fix kunit-related build error
Randy found that with the following Kconfig settings we have duplicate definitions (e.g. __inittest()) in sdhci-of-aspeed due to competing module_init()/module_exit() calls from kunit and driver the itself. ``` CONFIG_MMC_SDHCI_OF_ASPEED=m CONFIG_MMC_SDHCI_OF_ASPEED_TEST=y ``` Conditionally open-code the kunit initialisation to avoid the error. Fixes: 7efa02a ("mmc: sdhci-of-aspeed: Add KUnit tests for phase calculations") Reported-by: Randy Dunlap <[email protected]> Signed-off-by: Andrew Jeffery <[email protected]> Acked-by: Randy Dunlap <[email protected]> # build-tested Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent c7b9f01 commit 4af307f

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

drivers/mmc/host/sdhci-of-aspeed-test.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,11 @@ static struct kunit_suite aspeed_sdhci_test_suite = {
9595
.name = "sdhci-of-aspeed",
9696
.test_cases = aspeed_sdhci_test_cases,
9797
};
98-
kunit_test_suite(aspeed_sdhci_test_suite);
98+
99+
static struct kunit_suite *aspeed_sdc_test_suite_array[] = {
100+
&aspeed_sdhci_test_suite,
101+
NULL,
102+
};
103+
104+
static struct kunit_suite **aspeed_sdc_test_suites
105+
__used __section(".kunit_test_suites") = aspeed_sdc_test_suite_array;

drivers/mmc/host/sdhci-of-aspeed.c

+37-5
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,29 @@ static struct platform_driver aspeed_sdc_driver = {
556556
.remove = aspeed_sdc_remove,
557557
};
558558

559+
#if defined(CONFIG_MMC_SDHCI_OF_ASPEED_TEST)
560+
#include "sdhci-of-aspeed-test.c"
561+
562+
static inline int aspeed_sdc_tests_init(void)
563+
{
564+
return __kunit_test_suites_init(aspeed_sdc_test_suites);
565+
}
566+
567+
static inline void aspeed_sdc_tests_exit(void)
568+
{
569+
__kunit_test_suites_exit(aspeed_sdc_test_suites);
570+
}
571+
#else
572+
static inline int aspeed_sdc_tests_init(void)
573+
{
574+
return 0;
575+
}
576+
577+
static inline void aspeed_sdc_tests_exit(void)
578+
{
579+
}
580+
#endif
581+
559582
static int __init aspeed_sdc_init(void)
560583
{
561584
int rc;
@@ -566,23 +589,32 @@ static int __init aspeed_sdc_init(void)
566589

567590
rc = platform_driver_register(&aspeed_sdc_driver);
568591
if (rc < 0)
569-
platform_driver_unregister(&aspeed_sdhci_driver);
592+
goto cleanup_sdhci;
593+
594+
rc = aspeed_sdc_tests_init();
595+
if (rc < 0) {
596+
platform_driver_unregister(&aspeed_sdc_driver);
597+
goto cleanup_sdhci;
598+
}
599+
600+
return 0;
601+
602+
cleanup_sdhci:
603+
platform_driver_unregister(&aspeed_sdhci_driver);
570604

571605
return rc;
572606
}
573607
module_init(aspeed_sdc_init);
574608

575609
static void __exit aspeed_sdc_exit(void)
576610
{
611+
aspeed_sdc_tests_exit();
612+
577613
platform_driver_unregister(&aspeed_sdc_driver);
578614
platform_driver_unregister(&aspeed_sdhci_driver);
579615
}
580616
module_exit(aspeed_sdc_exit);
581617

582-
#if defined(CONFIG_MMC_SDHCI_OF_ASPEED_TEST)
583-
#include "sdhci-of-aspeed-test.c"
584-
#endif
585-
586618
MODULE_DESCRIPTION("Driver for the ASPEED SD/SDIO/SDHCI Controllers");
587619
MODULE_AUTHOR("Ryan Chen <[email protected]>");
588620
MODULE_AUTHOR("Andrew Jeffery <[email protected]>");

0 commit comments

Comments
 (0)