Skip to content

Commit 1d58996

Browse files
author
Paul Gortmaker
committed
bluetooth: macroize two small inlines to avoid module.h
These two small inlines make calls to try_module_get() and module_put() which would force us to keep module.h present within yet another common include header. We can avoid this by turning them into macros. The hci_dev_hold construct is patterned off of raw_spin_trylock_irqsave() in spinlock.h Signed-off-by: Paul Gortmaker <[email protected]>
1 parent 69e7dae commit 1d58996

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -513,24 +513,26 @@ static inline void __hci_dev_put(struct hci_dev *d)
513513
d->destruct(d);
514514
}
515515

516-
static inline void hci_dev_put(struct hci_dev *d)
517-
{
518-
__hci_dev_put(d);
519-
module_put(d->owner);
520-
}
516+
/*
517+
* hci_dev_put and hci_dev_hold are macros to avoid dragging all the
518+
* overhead of all the modular infrastructure into this header.
519+
*/
520+
#define hci_dev_put(d) \
521+
do { \
522+
__hci_dev_put(d); \
523+
module_put(d->owner); \
524+
} while (0)
521525

522526
static inline struct hci_dev *__hci_dev_hold(struct hci_dev *d)
523527
{
524528
atomic_inc(&d->refcnt);
525529
return d;
526530
}
527531

528-
static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
529-
{
530-
if (try_module_get(d->owner))
531-
return __hci_dev_hold(d);
532-
return NULL;
533-
}
532+
#define hci_dev_hold(d) \
533+
({ \
534+
try_module_get(d->owner) ? __hci_dev_hold(d) : NULL; \
535+
})
534536

535537
#define hci_dev_lock(d) spin_lock(&d->lock)
536538
#define hci_dev_unlock(d) spin_unlock(&d->lock)

0 commit comments

Comments
 (0)