Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: trigger: use inline functions instead of macros

Macros are used in case that an inline function doesn't work.
Otherwise, use an empty inline function.

(a) Case of !CONFIG_LEDS_TRIGGERS
Following macros are replaced with inline functions.
led_trigger_register_simple()
led_trigger_unregister_simple()
led_trigger_event()
To make inline types, the structure, 'led_trigger' should be defined.
This structure has no member at all.

(b) Case of !CONFIG_LEDS_TRIGGER_IDE_DISK
ledtrig_ide_activity() macro is replaced with an inline function as well.

(c) DEFINE_LED_TRIGGER() and DEFINE_LED_TRIGGER_GLOBAL()
Struct 'led_trigger' is defined both cases, with CONFIG_LEDS_TRIGGERS and
without CONFIG_LEDS_TRIGGERS.
Those macros are moved out of CONFIG_LED_TRIGGERS because of no-dependency
on CONFIG_LEDS_TRIGGERS.

(d) Fix build errors in mmc-core driver
After replacing macros with inline functions, following build errors occur.
(condition: CONFIG_LEDS_TRIGGERS is not set)

drivers/mmc/core/core.c: In function 'mmc_request_done':
drivers/mmc/core/core.c:164:25: error: 'struct mmc_host' has no member named 'led'
drivers/mmc/core/core.c: In function 'mmc_start_request':
drivers/mmc/core/core.c:254:24: error: 'struct mmc_host' has no member named 'led'
make[3]: *** [drivers/mmc/core/core.o] Error 1

The reason of these errors is non-existent member variable, 'led'.
It is only valid when CONFIG_LEDS_TRIGGERS is set.
But now, it can be used without this dependency.
To fix build errors, member 'led' is always used without its config option in
'include/linux/mmc/host.h'.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>

authored by

Kim, Milo and committed by
Bryan Wu
39f7e08a fbd9df28

+14 -13
+14 -11
include/linux/leds.h
··· 142 142 /* 143 143 * LED Triggers 144 144 */ 145 + /* Registration functions for simple triggers */ 146 + #define DEFINE_LED_TRIGGER(x) static struct led_trigger *x; 147 + #define DEFINE_LED_TRIGGER_GLOBAL(x) struct led_trigger *x; 148 + 145 149 #ifdef CONFIG_LEDS_TRIGGERS 146 150 147 151 #define TRIG_NAME_MAX 50 ··· 168 164 extern int led_trigger_register(struct led_trigger *trigger); 169 165 extern void led_trigger_unregister(struct led_trigger *trigger); 170 166 171 - /* Registration functions for simple triggers */ 172 - #define DEFINE_LED_TRIGGER(x) static struct led_trigger *x; 173 - #define DEFINE_LED_TRIGGER_GLOBAL(x) struct led_trigger *x; 174 167 extern void led_trigger_register_simple(const char *name, 175 168 struct led_trigger **trigger); 176 169 extern void led_trigger_unregister_simple(struct led_trigger *trigger); ··· 200 199 201 200 #else 202 201 203 - /* Triggers aren't active - null macros */ 204 - #define DEFINE_LED_TRIGGER(x) 205 - #define DEFINE_LED_TRIGGER_GLOBAL(x) 206 - #define led_trigger_register_simple(x, y) do {} while(0) 207 - #define led_trigger_unregister_simple(x) do {} while(0) 208 - #define led_trigger_event(x, y) do {} while(0) 202 + /* Trigger has no members */ 203 + struct led_trigger {}; 209 204 210 - #endif 205 + /* Trigger inline empty functions */ 206 + static inline void led_trigger_register_simple(const char *name, 207 + struct led_trigger **trigger) {} 208 + static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {} 209 + static inline void led_trigger_event(struct led_trigger *trigger, 210 + enum led_brightness event) {} 211 + #endif /* CONFIG_LEDS_TRIGGERS */ 211 212 212 213 /* Trigger specific functions */ 213 214 #ifdef CONFIG_LEDS_TRIGGER_IDE_DISK 214 215 extern void ledtrig_ide_activity(void); 215 216 #else 216 - #define ledtrig_ide_activity() do {} while(0) 217 + static inline void ledtrig_ide_activity(void) {} 217 218 #endif 218 219 219 220 /*
-2
include/linux/mmc/host.h
··· 341 341 342 342 mmc_pm_flag_t pm_flags; /* requested pm features */ 343 343 344 - #ifdef CONFIG_LEDS_TRIGGERS 345 344 struct led_trigger *led; /* activity led */ 346 - #endif 347 345 348 346 #ifdef CONFIG_REGULATOR 349 347 bool regulator_enabled; /* regulator state */