Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754284AbcJSVo1 (ORCPT ); Wed, 19 Oct 2016 17:44:27 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:35815 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751742AbcJSVoZ (ORCPT ); Wed, 19 Oct 2016 17:44:25 -0400 From: Cathal Mullaney To: david.kershner@unisys.com Cc: Timothy.Sell@unisys.com, gregkh@linuxfoundation.org, sparmaintainer@unisys.com, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Cathal Mullaney Subject: [PATCH v2] staging: unisys: visorbus: visorchannel: Refactor locking code to be statically deterministic. Date: Wed, 19 Oct 2016 22:43:25 +0100 Message-Id: <1476913405-4151-1-git-send-email-chuckleberryfinn@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476876643-3708-1-git-send-email-chuckleberryfinn@gmail.com> References: <1476876643-3708-1-git-send-email-chuckleberryfinn@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2094 Lines: 66 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 --- V2: Removed unnecessary variable initialization, as suggested by Tim Sell . drivers/staging/unisys/visorbus/visorchannel.c | 30 ++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/staging/unisys/visorbus/visorchannel.c b/drivers/staging/unisys/visorbus/visorchannel.c index a1381eb..a411157 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; } -- 2.7.4