0

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!

artless noise
  • 21,212
  • 6
  • 68
  • 105
Adam Lee
  • 2,983
  • 7
  • 35
  • 47
  • 2
    If you were paying attention to the kernel conventions, you would know that Kconfig variables should be prefixed with "CONFIG_" prefix in C code (thus, `CONFIG_RTC_DRV_TWL4030_RATE_25UA`, etc). – oakad Jun 04 '14 at 01:43
  • Will that solve my problem? Genuinely curious. – Adam Lee Jun 04 '14 at 16:24
  • ah, CONFIG_ prefix was part of my solution. Thanks. – Adam Lee Jun 04 '14 at 19:18

1 Answers1

0

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
Adam Lee
  • 2,983
  • 7
  • 35
  • 47