From: Herbert Poetzl Consolidate the various private implementations of this into a kernel-wide implementation. Signed-off-by: Andrew Morton --- 25-akpm/arch/s390/mm/extmem.c | 4 ++-- 25-akpm/drivers/md/raid5.c | 2 +- 25-akpm/drivers/md/raid6main.c | 2 +- 25-akpm/drivers/media/common/saa7146_fops.c | 12 +++--------- 25-akpm/drivers/media/video/saa7134/saa7134-core.c | 16 ++++------------ 25-akpm/drivers/scsi/megaraid/megaraid_mbox.c | 8 ++++---- 25-akpm/drivers/usb/host/ehci-q.c | 5 +---- 25-akpm/include/asm-sh/spinlock.h | 4 +--- 25-akpm/include/asm-x86_64/spinlock.h | 4 ++-- 25-akpm/include/linux/jbd.h | 6 ------ 25-akpm/include/linux/spinlock.h | 11 +++++++++++ 25-akpm/kernel/sched.c | 2 +- 25-akpm/kernel/signal.c | 10 ++-------- 13 files changed, 33 insertions(+), 53 deletions(-) diff -puN arch/s390/mm/extmem.c~assert_spin_locked arch/s390/mm/extmem.c --- 25/arch/s390/mm/extmem.c~assert_spin_locked Thu Jan 27 13:37:27 2005 +++ 25-akpm/arch/s390/mm/extmem.c Thu Jan 27 13:37:27 2005 @@ -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_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)) diff -puN drivers/md/raid5.c~assert_spin_locked drivers/md/raid5.c --- 25/drivers/md/raid5.c~assert_spin_locked Thu Jan 27 13:37:27 2005 +++ 25-akpm/drivers/md/raid5.c Thu Jan 27 13:37:27 2005 @@ -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 diff -puN drivers/md/raid6main.c~assert_spin_locked drivers/md/raid6main.c --- 25/drivers/md/raid6main.c~assert_spin_locked Thu Jan 27 13:37:27 2005 +++ 25-akpm/drivers/md/raid6main.c Thu Jan 27 13:37:27 2005 @@ -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 diff -puN drivers/media/common/saa7146_fops.c~assert_spin_locked drivers/media/common/saa7146_fops.c --- 25/drivers/media/common/saa7146_fops.c~assert_spin_locked Thu Jan 27 13:37:27 2005 +++ 25-akpm/drivers/media/common/saa7146_fops.c Thu Jan 27 13:37:27 2005 @@ -73,9 +73,7 @@ int saa7146_buffer_queue(struct saa7146_ 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 saa714 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_ 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); diff -puN drivers/media/video/saa7134/saa7134-core.c~assert_spin_locked drivers/media/video/saa7134/saa7134-core.c --- 25/drivers/media/video/saa7134/saa7134-core.c~assert_spin_locked Thu Jan 27 13:37:27 2005 +++ 25-akpm/drivers/media/video/saa7134/saa7134-core.c Thu Jan 27 13:37:27 2005 @@ -371,10 +371,8 @@ int saa7134_buffer_queue(struct saa7134_ 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 saa713 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_ { 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_d 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) { diff -puN drivers/scsi/megaraid/megaraid_mbox.c~assert_spin_locked drivers/scsi/megaraid/megaraid_mbox.c --- 25/drivers/scsi/megaraid/megaraid_mbox.c~assert_spin_locked Thu Jan 27 13:37:27 2005 +++ 25-akpm/drivers/scsi/megaraid/megaraid_mbox.c Thu Jan 27 13:37:27 2005 @@ -1600,7 +1600,7 @@ megaraid_queue_command(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 *adapte 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 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 \n", @@ -2762,7 +2762,7 @@ megaraid_reset_handler(struct scsi_cmnd 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")); diff -puN drivers/usb/host/ehci-q.c~assert_spin_locked drivers/usb/host/ehci-q.c --- 25/drivers/usb/host/ehci-q.c~assert_spin_locked Thu Jan 27 13:37:27 2005 +++ 25-akpm/drivers/usb/host/ehci-q.c Thu Jan 27 13:37:27 2005 @@ -986,13 +986,10 @@ static void start_unlink_async (struct e 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 diff -puN include/asm-sh/spinlock.h~assert_spin_locked include/asm-sh/spinlock.h --- 25/include/asm-sh/spinlock.h~assert_spin_locked Thu Jan 27 13:37:27 2005 +++ 25-akpm/include/asm-sh/spinlock.h Thu Jan 27 13:37:27 2005 @@ -51,9 +51,7 @@ static inline void _raw_spin_lock(spinlo 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; } diff -puN include/asm-x86_64/spinlock.h~assert_spin_locked include/asm-x86_64/spinlock.h --- 25/include/asm-x86_64/spinlock.h~assert_spin_locked Thu Jan 27 13:37:27 2005 +++ 25-akpm/include/asm-x86_64/spinlock.h Thu Jan 27 13:37:27 2005 @@ -75,7 +75,7 @@ static inline void _raw_spin_unlock(spin { #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(spin 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 diff -puN include/linux/jbd.h~assert_spin_locked include/linux/jbd.h --- 25/include/linux/jbd.h~assert_spin_locked Thu Jan 27 13:37:27 2005 +++ 25-akpm/include/linux/jbd.h Thu Jan 27 13:37:27 2005 @@ -1068,12 +1068,6 @@ extern int jbd_blocks_per_page(struct in #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) diff -puN include/linux/spinlock.h~assert_spin_locked include/linux/spinlock.h --- 25/include/linux/spinlock.h~assert_spin_locked Thu Jan 27 13:37:27 2005 +++ 25-akpm/include/linux/spinlock.h Thu Jan 27 13:37:27 2005 @@ -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 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) diff -puN kernel/sched.c~assert_spin_locked kernel/sched.c --- 25/kernel/sched.c~assert_spin_locked Thu Jan 27 13:37:27 2005 +++ 25-akpm/kernel/sched.c Thu Jan 27 13:37:27 2005 @@ -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); diff -puN kernel/signal.c~assert_spin_locked kernel/signal.c --- 25/kernel/signal.c~assert_spin_locked Thu Jan 27 13:37:27 2005 +++ 25-akpm/kernel/signal.c Thu Jan 27 13:37:27 2005 @@ -847,10 +847,7 @@ specific_send_sig_info(int sig, struct s 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 si { 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)) _