Commit 68b38741 authored by Herbert Pötzl's avatar Herbert Pötzl Committed by Linus Torvalds

[PATCH] assert_spin_locked()

Consolidate the various private implementations of this into a kernel-wide
implementation.
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent d15f98e5
......@@ -117,7 +117,7 @@ segment_by_name (char *name)
struct list_head *l;
struct dcss_segment *tmp, *retval = NULL;
BUG_ON (!spin_is_locked(&dcss_lock));
assert_spin_locked(&dcss_lock);
dcss_mkname (name, dcss_name);
list_for_each (l, &dcss_list) {
tmp = list_entry (l, struct dcss_segment, list);
......@@ -271,7 +271,7 @@ segment_overlaps_others (struct dcss_segment *seg)
struct list_head *l;
struct dcss_segment *tmp;
BUG_ON (!spin_is_locked(&dcss_lock));
assert_spin_locked(&dcss_lock);
list_for_each(l, &dcss_list) {
tmp = list_entry(l, struct dcss_segment, list);
if ((tmp->start_addr >> 20) > (seg->end >> 20))
......
......@@ -56,7 +56,7 @@
#define RAID5_DEBUG 0
#define RAID5_PARANOIA 1
#if RAID5_PARANOIA && defined(CONFIG_SMP)
# define CHECK_DEVLOCK() if (!spin_is_locked(&conf->device_lock)) BUG()
# define CHECK_DEVLOCK() assert_spin_locked(&conf->device_lock)
#else
# define CHECK_DEVLOCK()
#endif
......
......@@ -62,7 +62,7 @@
#define RAID6_PARANOIA 1 /* Check spinlocks */
#define RAID6_DUMPSTATE 0 /* Include stripe cache state in /proc/mdstat */
#if RAID6_PARANOIA && defined(CONFIG_SMP)
# define CHECK_DEVLOCK() if (!spin_is_locked(&conf->device_lock)) BUG()
# define CHECK_DEVLOCK() assert_spin_locked(&conf->device_lock)
#else
# define CHECK_DEVLOCK()
#endif
......
......@@ -73,9 +73,7 @@ int saa7146_buffer_queue(struct saa7146_dev *dev,
struct saa7146_dmaqueue *q,
struct saa7146_buf *buf)
{
#ifdef DEBUG_SPINLOCKS
BUG_ON(!spin_is_locked(&dev->slock));
#endif
assert_spin_locked(&dev->slock);
DEB_EE(("dev:%p, dmaq:%p, buf:%p\n", dev, q, buf));
BUG_ON(!q);
......@@ -96,9 +94,7 @@ void saa7146_buffer_finish(struct saa7146_dev *dev,
struct saa7146_dmaqueue *q,
int state)
{
#ifdef DEBUG_SPINLOCKS
BUG_ON(!spin_is_locked(&dev->slock));
#endif
assert_spin_locked(&dev->slock);
DEB_EE(("dev:%p, dmaq:%p, state:%d\n", dev, q, state));
DEB_EE(("q->curr:%p\n",q->curr));
......@@ -126,9 +122,7 @@ void saa7146_buffer_next(struct saa7146_dev *dev,
DEB_INT(("dev:%p, dmaq:%p, vbi:%d\n", dev, q, vbi));
#ifdef DEBUG_SPINLOCKS
BUG_ON(!spin_is_locked(&dev->slock));
#endif
assert_spin_locked(&dev->slock);
if (!list_empty(&q->queue)) {
/* activate next one from queue */
buf = list_entry(q->queue.next,struct saa7146_buf,vb.queue);
......
......@@ -371,10 +371,8 @@ int saa7134_buffer_queue(struct saa7134_dev *dev,
struct saa7134_buf *buf)
{
struct saa7134_buf *next = NULL;
#ifdef DEBUG_SPINLOCKS
BUG_ON(!spin_is_locked(&dev->slock));
#endif
assert_spin_locked(&dev->slock);
dprintk("buffer_queue %p\n",buf);
if (NULL == q->curr) {
if (!q->need_two) {
......@@ -400,9 +398,7 @@ void saa7134_buffer_finish(struct saa7134_dev *dev,
struct saa7134_dmaqueue *q,
unsigned int state)
{
#ifdef DEBUG_SPINLOCKS
BUG_ON(!spin_is_locked(&dev->slock));
#endif
assert_spin_locked(&dev->slock);
dprintk("buffer_finish %p\n",q->curr);
/* finish current buffer */
......@@ -417,9 +413,7 @@ void saa7134_buffer_next(struct saa7134_dev *dev,
{
struct saa7134_buf *buf,*next = NULL;
#ifdef DEBUG_SPINLOCKS
BUG_ON(!spin_is_locked(&dev->slock));
#endif
assert_spin_locked(&dev->slock);
BUG_ON(NULL != q->curr);
if (!list_empty(&q->queue)) {
......@@ -474,9 +468,7 @@ int saa7134_set_dmabits(struct saa7134_dev *dev)
enum v4l2_field cap = V4L2_FIELD_ANY;
enum v4l2_field ov = V4L2_FIELD_ANY;
#ifdef DEBUG_SPINLOCKS
BUG_ON(!spin_is_locked(&dev->slock));
#endif
assert_spin_locked(&dev->slock);
/* video capture -- dma 0 + video task A */
if (dev->video_q.curr) {
......
......@@ -1600,7 +1600,7 @@ megaraid_queue_command(struct scsi_cmnd *scp, void (* done)(struct scsi_cmnd *))
scp->scsi_done = done;
scp->result = 0;
ASSERT(spin_is_locked(adapter->host_lock));
assert_spin_locked(adapter->host_lock);
spin_unlock(adapter->host_lock);
......@@ -2043,7 +2043,7 @@ megaraid_mbox_runpendq(adapter_t *adapter, scb_t *scb_q)
while (!list_empty(&adapter->pend_list)) {
ASSERT(spin_is_locked(PENDING_LIST_LOCK(adapter)));
assert_spin_locked(PENDING_LIST_LOCK(adapter));
scb = list_entry(adapter->pend_list.next, scb_t, list);
......@@ -2615,7 +2615,7 @@ megaraid_abort_handler(struct scsi_cmnd *scp)
adapter = SCP2ADAPTER(scp);
raid_dev = ADAP2RAIDDEV(adapter);
ASSERT(spin_is_locked(adapter->host_lock));
assert_spin_locked(adapter->host_lock);
con_log(CL_ANN, (KERN_WARNING
"megaraid: aborting-%ld cmd=%x <c=%d t=%d l=%d>\n",
......@@ -2762,7 +2762,7 @@ megaraid_reset_handler(struct scsi_cmnd *scp)
adapter = SCP2ADAPTER(scp);
raid_dev = ADAP2RAIDDEV(adapter);
ASSERT(spin_is_locked(adapter->host_lock));
assert_spin_locked(adapter->host_lock);
con_log(CL_ANN, (KERN_WARNING "megaraid: reseting the host...\n"));
......
......@@ -986,13 +986,10 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
struct ehci_qh *prev;
#ifdef DEBUG
assert_spin_locked(&ehci->lock);
if (ehci->reclaim
|| (qh->qh_state != QH_STATE_LINKED
&& qh->qh_state != QH_STATE_UNLINK_WAIT)
#ifdef CONFIG_SMP
// this macro lies except on SMP compiles
|| !spin_is_locked (&ehci->lock)
#endif
)
BUG ();
#endif
......
......@@ -51,9 +51,7 @@ static inline void _raw_spin_lock(spinlock_t *lock)
static inline void _raw_spin_unlock(spinlock_t *lock)
{
#ifdef CONFIG_DEBUG_SPINLOCK
BUG_ON(!spin_is_locked(lock));
#endif
assert_spin_locked(lock);
lock->lock = 0;
}
......
......@@ -75,7 +75,7 @@ static inline void _raw_spin_unlock(spinlock_t *lock)
{
#ifdef CONFIG_DEBUG_SPINLOCK
BUG_ON(lock->magic != SPINLOCK_MAGIC);
BUG_ON(!spin_is_locked(lock));
assert_spin_locked(lock);
#endif
__asm__ __volatile__(
spin_unlock_string
......@@ -94,7 +94,7 @@ static inline void _raw_spin_unlock(spinlock_t *lock)
char oldval = 1;
#ifdef CONFIG_DEBUG_SPINLOCK
BUG_ON(lock->magic != SPINLOCK_MAGIC);
BUG_ON(!spin_is_locked(lock));
assert_spin_locked(lock);
#endif
__asm__ __volatile__(
spin_unlock_string
......
......@@ -1062,12 +1062,6 @@ extern int jbd_blocks_per_page(struct inode *inode);
#ifdef __KERNEL__
#ifdef CONFIG_SMP
#define assert_spin_locked(lock) J_ASSERT(spin_is_locked(lock))
#else
#define assert_spin_locked(lock) do {} while(0)
#endif
#define buffer_trace_init(bh) do {} while (0)
#define print_buffer_fields(bh) do {} while (0)
#define print_buffer_trace(bh) do {} while (0)
......
......@@ -38,6 +38,8 @@
* If CONFIG_SMP is set, pull in the _raw_* definitions
*/
#ifdef CONFIG_SMP
#define assert_spin_locked(x) BUG_ON(!spin_is_locked(x))
#include <asm/spinlock.h>
int __lockfunc _spin_trylock(spinlock_t *lock);
......@@ -145,6 +147,14 @@ typedef struct {
0; \
})
/* with debugging, assert_spin_locked() on UP does check
* the lock value properly */
#define assert_spin_locked(x) \
({ \
CHECK_LOCK(x); \
BUG_ON(!(x)->lock); \
})
/* without debugging, spin_trylock on UP always says
* TRUE. --> printk if already locked. */
#define _raw_spin_trylock(x) \
......@@ -201,6 +211,7 @@ typedef struct {
#define spin_lock_init(lock) do { (void)(lock); } while(0)
#define _raw_spin_lock(lock) do { (void)(lock); } while(0)
#define spin_is_locked(lock) ((void)(lock), 0)
#define assert_spin_locked(lock) do { (void)(lock); } while(0)
#define _raw_spin_trylock(lock) (((void)(lock), 1))
#define spin_unlock_wait(lock) (void)(lock)
#define _raw_spin_unlock(lock) do { (void)(lock); } while(0)
......
......@@ -778,7 +778,7 @@ static void resched_task(task_t *p)
{
int need_resched, nrpolling;
BUG_ON(!spin_is_locked(&task_rq(p)->lock));
assert_spin_locked(&task_rq(p)->lock);
/* minimise the chance of sending an interrupt to poll_idle() */
nrpolling = test_tsk_thread_flag(p,TIF_POLLING_NRFLAG);
......
......@@ -847,10 +847,7 @@ specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
if (!irqs_disabled())
BUG();
#ifdef CONFIG_SMP
if (!spin_is_locked(&t->sighand->siglock))
BUG();
#endif
assert_spin_locked(&t->sighand->siglock);
if (((unsigned long)info > 2) && (info->si_code == SI_TIMER))
/*
......@@ -1044,10 +1041,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
{
int ret = 0;
#ifdef CONFIG_SMP
if (!spin_is_locked(&p->sighand->siglock))
BUG();
#endif
assert_spin_locked(&p->sighand->siglock);
handle_stop_signal(sig, p);
if (((unsigned long)info > 2) && (info->si_code == SI_TIMER))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment