Skip to content

Commit 39f7e08

Browse files
Kim, Milocooloney
authored andcommitted
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>
1 parent fbd9df2 commit 39f7e08

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

‎include/linux/leds.h‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ extern void led_set_brightness(struct led_classdev *led_cdev,
142142
/*
143143
* LED Triggers
144144
*/
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+
145149
#ifdef CONFIG_LEDS_TRIGGERS
146150

147151
#define TRIG_NAME_MAX 50
@@ -164,9 +168,6 @@ struct led_trigger {
164168
extern int led_trigger_register(struct led_trigger *trigger);
165169
extern void led_trigger_unregister(struct led_trigger *trigger);
166170

167-
/* Registration functions for simple triggers */
168-
#define DEFINE_LED_TRIGGER(x) static struct led_trigger *x;
169-
#define DEFINE_LED_TRIGGER_GLOBAL(x) struct led_trigger *x;
170171
extern void led_trigger_register_simple(const char *name,
171172
struct led_trigger **trigger);
172173
extern void led_trigger_unregister_simple(struct led_trigger *trigger);
@@ -199,20 +200,22 @@ extern void led_trigger_rename_static(const char *name,
199200

200201
#else
201202

202-
/* Triggers aren't active - null macros */
203-
#define DEFINE_LED_TRIGGER(x)
204-
#define DEFINE_LED_TRIGGER_GLOBAL(x)
205-
#define led_trigger_register_simple(x, y) do {} while(0)
206-
#define led_trigger_unregister_simple(x) do {} while(0)
207-
#define led_trigger_event(x, y) do {} while(0)
203+
/* Trigger has no members */
204+
struct led_trigger {};
208205

209-
#endif
206+
/* Trigger inline empty functions */
207+
static inline void led_trigger_register_simple(const char *name,
208+
struct led_trigger **trigger) {}
209+
static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {}
210+
static inline void led_trigger_event(struct led_trigger *trigger,
211+
enum led_brightness event) {}
212+
#endif /* CONFIG_LEDS_TRIGGERS */
210213

211214
/* Trigger specific functions */
212215
#ifdef CONFIG_LEDS_TRIGGER_IDE_DISK
213216
extern void ledtrig_ide_activity(void);
214217
#else
215-
#define ledtrig_ide_activity() do {} while(0)
218+
static inline void ledtrig_ide_activity(void) {}
216219
#endif
217220

218221
/*

‎include/linux/mmc/host.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,7 @@ struct mmc_host {
341341

342342
mmc_pm_flag_t pm_flags; /* requested pm features */
343343

344-
#ifdef CONFIG_LEDS_TRIGGERS
345344
struct led_trigger *led; /* activity led */
346-
#endif
347345

348346
#ifdef CONFIG_REGULATOR
349347
bool regulator_enabled; /* regulator state */

0 commit comments

Comments
 (0)