Kconfig, macro and undefined macro warnings

1k Views Asked by At

I am adding a multiple choice style configuration to a Kconfig in Linux kernel. Depending on the user's choice, it defines a macro. Once it is configured, the kernel driver source code has #ifdef block where it checks and uses the macro to compile.

It looks like this in Kconfig:

choice RTC_DRV_TWL4030_CHARGE_RATE
   prompt "RTC Backup Battery Charge Rate"
   depends on RTC_DRV_TWL4030
   default RTC_DRV_TWL4030_RATE_25UA
   config RTC_DRV_TWL4030_RATE_25UA
           bool "25uA"
   config RTC_DRV_TWL4030_RATE_150UA
           bool "150uA"
   config RTC_DRV_TWL4030_RATE_500UA
           bool "500uA"
   config RTC_DRV_TWL4030_RATE_1MA
           bool "1MA"
endchoice

And in the driver source code:

#ifdef RTC_DRV_TWL4030_RATE_25UA
                BIT_PM_RECEIVER_BB_CFG_BBISEL_25UA,
#elif RTC_DRV_TWL4030_RATE_150UA
               BIT_PM_RECEIVER_BB_CFG_BBISEL_150UA,
#elif RTC_DRV_TWL4030_RATE_500UA
               BIT_PM_RECEIVER_BB_CFG_BBISEL_500UA,
#elif RTC_DRV_TWL4030_RATE_1MA
               BIT_PM_RECEIVER_BB_CFG_BBISEL_1MA,
#else
               BIT_PM_RECEIVER_BB_CFG_BBISEL_25UA,
#endif

This feels ok. However, the problem is at compile time I am getting warnings:

drivers/rtc/rtc-twl.c:549:7: warning: "RTC_DRV_TWL4030_RATE_150UA" is not defined [-Wundef]
    drivers/rtc/rtc-twl.c:551:7: warning: "RTC_DRV_TWL4030_RATE_500UA" is not defined [-Wundef]
    drivers/rtc/rtc-twl.c:553:7: warning: "RTC_DRV_TWL4030_RATE_1MA" is not defined [-Wundef]

And these are the only warnings I see during the kernel compilation. So it must mean I am doing it wrong. Any pointers will be appreciated!

1

There are 1 best solutions below

0
On

I wasn't using the preprocessor correctly. I get no warnings like this:

#if defined(CONFIG_RTC_DRV_TWL4030_RATE_0A)
                BIT_PM_RECEIVER_BB_CFG_BBISEL,
#elif defined(CONFIG_RTC_DRV_TWL4030_RATE_25UA)
                BIT_PM_RECEIVER_BB_CFG_BBISEL_25UA,
#elif defined(CONFIG_RTC_DRV_TWL4030_RATE_150UA)
                BIT_PM_RECEIVER_BB_CFG_BBISEL_150UA,
#elif defined(CONFIG_RTC_DRV_TWL4030_RATE_500UA)
                BIT_PM_RECEIVER_BB_CFG_BBISEL_500UA,
#elif defined(CONFIG_RTC_DRV_TWL4030_RATE_1MA)
                BIT_PM_RECEIVER_BB_CFG_BBISEL_1MA,
#else
                BIT_PM_RECEIVER_BB_CFG_BBISEL_25UA,
#endif