Skip to content

Commit 0f70a49

Browse files
committed
genirq: Provide conditional lock guards
The interrupt core code has an ever repeating pattern: unsigned long flags; struct irq_desc *desc = irq_get_desc_[bus]lock(irq, &flags, mode); if (!desc) return -EINVAL; .... irq_put_desc_[bus]unlock(desc, flags); That requires gotos in failure paths and just creates visual clutter. Provide lock guards, which allow to simplify the code. Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent e5032ea commit 0f70a49

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

kernel/irq/internals.h

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ extern int irq_setup_affinity(struct irq_desc *desc);
141141
static inline int irq_setup_affinity(struct irq_desc *desc) { return 0; }
142142
#endif
143143

144+
145+
#define for_each_action_of_desc(desc, act) \
146+
for (act = desc->action; act; act = act->next)
147+
144148
/* Inline functions for support of irq chips on slow busses */
145149
static inline void chip_bus_lock(struct irq_desc *desc)
146150
{
@@ -160,14 +164,33 @@ static inline void chip_bus_sync_unlock(struct irq_desc *desc)
160164
#define IRQ_GET_DESC_CHECK_GLOBAL (_IRQ_DESC_CHECK)
161165
#define IRQ_GET_DESC_CHECK_PERCPU (_IRQ_DESC_CHECK | _IRQ_DESC_PERCPU)
162166

163-
#define for_each_action_of_desc(desc, act) \
164-
for (act = desc->action; act; act = act->next)
165-
166-
struct irq_desc *
167-
__irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus,
168-
unsigned int check);
167+
struct irq_desc *__irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus,
168+
unsigned int check);
169169
void __irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags, bool bus);
170170

171+
__DEFINE_CLASS_IS_CONDITIONAL(irqdesc_lock, true);
172+
__DEFINE_UNLOCK_GUARD(irqdesc_lock, struct irq_desc,
173+
__irq_put_desc_unlock(_T->lock, _T->flags, _T->bus),
174+
unsigned long flags; bool bus);
175+
176+
static inline class_irqdesc_lock_t class_irqdesc_lock_constructor(unsigned int irq, bool bus,
177+
unsigned int check)
178+
{
179+
class_irqdesc_lock_t _t = {
180+
.bus = bus,
181+
.lock = __irq_get_desc_lock(irq, &_t.flags, bus, check),
182+
};
183+
return _t;
184+
}
185+
186+
#define scoped_irqdesc_get_and_lock(_irq, _check) \
187+
scoped_guard(irqdesc_lock, _irq, false, _check)
188+
189+
#define scoped_irqdesc_get_and_buslock(_irq, _check) \
190+
scoped_guard(irqdesc_lock, _irq, true, _check)
191+
192+
#define scoped_irqdesc ((struct irq_desc *)(__guard_ptr(irqdesc_lock)(&scope)))
193+
171194
static inline struct irq_desc *
172195
irq_get_desc_buslock(unsigned int irq, unsigned long *flags, unsigned int check)
173196
{

0 commit comments

Comments
 (0)