Skip to content

Commit

Permalink
bluetooth: macroize two small inlines to avoid module.h
Browse files Browse the repository at this point in the history
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 <paul.gortmaker@windriver.com>
  • Loading branch information
Paul Gortmaker committed Oct 31, 2011
1 parent 69e7dae commit 1d58996
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions include/net/bluetooth/hci_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,24 +513,26 @@ static inline void __hci_dev_put(struct hci_dev *d)
d->destruct(d);
}

static inline void hci_dev_put(struct hci_dev *d)
{
__hci_dev_put(d);
module_put(d->owner);
}
/*
* hci_dev_put and hci_dev_hold are macros to avoid dragging all the
* overhead of all the modular infrastructure into this header.
*/
#define hci_dev_put(d) \
do { \
__hci_dev_put(d); \
module_put(d->owner); \
} while (0)

static inline struct hci_dev *__hci_dev_hold(struct hci_dev *d)
{
atomic_inc(&d->refcnt);
return d;
}

static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
{
if (try_module_get(d->owner))
return __hci_dev_hold(d);
return NULL;
}
#define hci_dev_hold(d) \
({ \
try_module_get(d->owner) ? __hci_dev_hold(d) : NULL; \
})

#define hci_dev_lock(d) spin_lock(&d->lock)
#define hci_dev_unlock(d) spin_unlock(&d->lock)
Expand Down

0 comments on commit 1d58996

Please sign in to comment.