diff options
author | Cathal Mullaney | 2016-10-19 23:43:25 +0200 |
---|---|---|
committer | Greg Kroah-Hartman | 2016-10-25 10:53:27 +0200 |
commit | f0208b7155bc6e395c09652290a16b66e77442f3 (patch) | |
tree | 09494f6508682801c767d0db476c66a331be6ff8 /drivers/staging/unisys/visorbus/visorchannel.c | |
parent | staging: wlan-ng: Replace data type declaration with variable of same type in... (diff) | |
download | kernel-qcow2-linux-f0208b7155bc6e395c09652290a16b66e77442f3.tar.gz kernel-qcow2-linux-f0208b7155bc6e395c09652290a16b66e77442f3.tar.xz kernel-qcow2-linux-f0208b7155bc6e395c09652290a16b66e77442f3.zip |
staging: unisys: visorbus: visorchannel: Refactor locking code to be statically deterministic.
This patch makes locking in visorchannel_signalempty statically
deterministic.
As a result this patch fixes the sparse warning:
Context imbalance in 'visorchannel_signalempty' - different lock
contexts for basic block.
The logic of the locking code doesn't change but the layout of the
original code is "frowned upon"
according to mails on sparse context checking.
Refactoring removes the warning and makes the code more readable.
Signed-off-by: Cathal Mullaney <chuckleberryfinn@gmail.com>
Tested-by: David Kershner <david.kershner@unisys.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/unisys/visorbus/visorchannel.c')
-rw-r--r-- | drivers/staging/unisys/visorbus/visorchannel.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/drivers/staging/unisys/visorbus/visorchannel.c b/drivers/staging/unisys/visorbus/visorchannel.c index a1381eb81674..a41115733a50 100644 --- a/drivers/staging/unisys/visorbus/visorchannel.c +++ b/drivers/staging/unisys/visorbus/visorchannel.c @@ -300,22 +300,30 @@ EXPORT_SYMBOL_GPL(visorchannel_signalremove); * Return: boolean indicating whether any messages in the designated * channel/queue are present */ + +static bool +queue_empty(struct visorchannel *channel, u32 queue) +{ + struct signal_queue_header sig_hdr; + + if (sig_read_header(channel, queue, &sig_hdr)) + return true; + + return (sig_hdr.head == sig_hdr.tail); +} + bool visorchannel_signalempty(struct visorchannel *channel, u32 queue) { - unsigned long flags = 0; - struct signal_queue_header sig_hdr; - bool rc = false; + bool rc; + unsigned long flags; - if (channel->needs_lock) - spin_lock_irqsave(&channel->remove_lock, flags); + if (!channel->needs_lock) + return queue_empty(channel, queue); - if (sig_read_header(channel, queue, &sig_hdr)) - rc = true; - if (sig_hdr.head == sig_hdr.tail) - rc = true; - if (channel->needs_lock) - spin_unlock_irqrestore(&channel->remove_lock, flags); + spin_lock_irqsave(&channel->remove_lock, flags); + rc = queue_empty(channel, queue); + spin_unlock_irqrestore(&channel->remove_lock, flags); return rc; } |