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