All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: unisys: visorbus: visorchannel: Refactor locking code to be statically deterministic.
@ 2016-10-19 11:30 Cathal Mullaney
  2016-10-19 17:00 ` Sell, Timothy C
  2016-10-19 21:43 ` [PATCH v2] " Cathal Mullaney
  0 siblings, 2 replies; 6+ messages in thread
From: Cathal Mullaney @ 2016-10-19 11:30 UTC (permalink / raw)
  To: david.kershner
  Cc: gregkh, sparmaintainer, devel, linux-kernel, Cathal Mullaney

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>
---
 drivers/staging/unisys/visorbus/visorchannel.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/unisys/visorbus/visorchannel.c b/drivers/staging/unisys/visorbus/visorchannel.c
index a1381eb..1eea5d8 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;
 
-	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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* RE: [PATCH] staging: unisys: visorbus: visorchannel: Refactor locking code to be statically deterministic.
  2016-10-19 11:30 [PATCH] staging: unisys: visorbus: visorchannel: Refactor locking code to be statically deterministic Cathal Mullaney
@ 2016-10-19 17:00 ` Sell, Timothy C
  2016-10-19 21:56   ` Chuckleberryfinn
  2016-10-19 21:43 ` [PATCH v2] " Cathal Mullaney
  1 sibling, 1 reply; 6+ messages in thread
From: Sell, Timothy C @ 2016-10-19 17:00 UTC (permalink / raw)
  To: 'Cathal Mullaney'
  Cc: gregkh, *S-Par-Maintainer, devel, linux-kernel, Kershner, David A

On Wednesday, October 19, 2016 7:31 AM, Cathal Mullaney wrote:
> 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>
> ---
>  drivers/staging/unisys/visorbus/visorchannel.c | 26 +++++++++++++++++---
> ------
>  1 file changed, 17 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/staging/unisys/visorbus/visorchannel.c
> b/drivers/staging/unisys/visorbus/visorchannel.c
> index a1381eb..1eea5d8 100644
> --- a/drivers/staging/unisys/visorbus/visorchannel.c
> +++ b/drivers/staging/unisys/visorbus/visorchannel.c
> @@ -300,22 +300,30 @@
> ---
>  bool
>  visorchannel_signalempty(struct visorchannel *channel, u32 queue)
>  {
>  	unsigned long flags = 0;
> -	struct signal_queue_header sig_hdr;
>  	bool rc = false;

It appears as if you no longer need to initialize 'rc' above.

Although this is NOT caused by your patch, it also looks like 'flags'
is being unnecessarily initialized.  You may want to fix that too
while you're in the neighborhood.

(Kernel folks seem to frown on unnecessary variable initializations.)

> 
> -	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

Besides that, your patch looks good to me.  Thanks.

- Tim Sell

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] staging: unisys: visorbus: visorchannel: Refactor locking code to be statically deterministic.
  2016-10-19 11:30 [PATCH] staging: unisys: visorbus: visorchannel: Refactor locking code to be statically deterministic Cathal Mullaney
  2016-10-19 17:00 ` Sell, Timothy C
@ 2016-10-19 21:43 ` Cathal Mullaney
  2016-10-20  0:04   ` Kershner, David A
  1 sibling, 1 reply; 6+ messages in thread
From: Cathal Mullaney @ 2016-10-19 21:43 UTC (permalink / raw)
  To: david.kershner
  Cc: Timothy.Sell, gregkh, sparmaintainer, devel, linux-kernel,
	Cathal Mullaney

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>
---
V2: Removed unnecessary variable initialization, as suggested by Tim Sell <Timothy.Sell@unisys.com>.

 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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: unisys: visorbus: visorchannel: Refactor locking code to be statically deterministic.
  2016-10-19 17:00 ` Sell, Timothy C
@ 2016-10-19 21:56   ` Chuckleberryfinn
  0 siblings, 0 replies; 6+ messages in thread
From: Chuckleberryfinn @ 2016-10-19 21:56 UTC (permalink / raw)
  To: Sell, Timothy C
  Cc: gregkh, *S-Par-Maintainer, devel, linux-kernel, Kershner, David A

On Wed, Oct 19, 2016 at 05:00:53PM +0000, Sell, Timothy C wrote:
> On Wednesday, October 19, 2016 7:31 AM, Cathal Mullaney wrote:
> > 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>
> > ---
> >  drivers/staging/unisys/visorbus/visorchannel.c | 26 +++++++++++++++++---
> > ------
> >  1 file changed, 17 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/staging/unisys/visorbus/visorchannel.c
> > b/drivers/staging/unisys/visorbus/visorchannel.c
> > index a1381eb..1eea5d8 100644
> > --- a/drivers/staging/unisys/visorbus/visorchannel.c
> > +++ b/drivers/staging/unisys/visorbus/visorchannel.c
> > @@ -300,22 +300,30 @@
> > ---
> >  bool
> >  visorchannel_signalempty(struct visorchannel *channel, u32 queue)
> >  {
> >  	unsigned long flags = 0;
> > -	struct signal_queue_header sig_hdr;
> >  	bool rc = false;
> 
> It appears as if you no longer need to initialize 'rc' above.
> 
> Although this is NOT caused by your patch, it also looks like 'flags'
> is being unnecessarily initialized.  You may want to fix that too
> while you're in the neighborhood.
> 
> (Kernel folks seem to frown on unnecessary variable initializations.)
> 
> > 
> > -	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
> 
> Besides that, your patch looks good to me.  Thanks.
> 
> - Tim Sell
>

Thanks for your feedback Tim.
Submitted v2 with the suggested updates.
Thanks again.

Kind regards,
Cathal

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v2] staging: unisys: visorbus: visorchannel: Refactor locking code to be statically deterministic.
  2016-10-19 21:43 ` [PATCH v2] " Cathal Mullaney
@ 2016-10-20  0:04   ` Kershner, David A
  2016-10-20  3:10     ` Sell, Timothy C
  0 siblings, 1 reply; 6+ messages in thread
From: Kershner, David A @ 2016-10-20  0:04 UTC (permalink / raw)
  To: Cathal Mullaney
  Cc: Sell, Timothy C, gregkh, *S-Par-Maintainer, devel, linux-kernel

> -----Original Message-----
> From: Cathal Mullaney [mailto:chuckleberryfinn@gmail.com]
> Subject: [PATCH v2] 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>

> ---
> V2: Removed unnecessary variable initialization, as suggested by Tim Sell
> <Timothy.Sell@unisys.com>.
> 
>  drivers/staging/unisys/visorbus/visorchannel.c | 30 ++++++++++++++++----
> ------

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v2] staging: unisys: visorbus: visorchannel: Refactor locking code to be statically deterministic.
  2016-10-20  0:04   ` Kershner, David A
@ 2016-10-20  3:10     ` Sell, Timothy C
  0 siblings, 0 replies; 6+ messages in thread
From: Sell, Timothy C @ 2016-10-20  3:10 UTC (permalink / raw)
  To: Kershner, David A, Cathal Mullaney
  Cc: Sell, Timothy C, gregkh, *S-Par-Maintainer, devel, linux-kernel

> -----Original Message-----
> From: Kershner, David A
> Sent: Wednesday, October 19, 2016 8:04 PM
> To: Cathal Mullaney <chuckleberryfinn@gmail.com>

> Subject: RE: [PATCH v2] staging: unisys: visorbus: visorchannel: Refactor
> locking code to be statically deterministic.
> 
> > -----Original Message-----
> > From: Cathal Mullaney [mailto:chuckleberryfinn@gmail.com]
> > Subject: [PATCH v2] 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>
> 
> > ---
> > V2: Removed unnecessary variable initialization, as suggested by Tim Sell
> > <Timothy.Sell@unisys.com>.
> >
> >  drivers/staging/unisys/visorbus/visorchannel.c | 30 ++++++++++++++++--
> --
> > ------

Thanks for the quick turnaround, folks.
v2 looks great to me.

- Tim Sell

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-10-20  3:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-19 11:30 [PATCH] staging: unisys: visorbus: visorchannel: Refactor locking code to be statically deterministic Cathal Mullaney
2016-10-19 17:00 ` Sell, Timothy C
2016-10-19 21:56   ` Chuckleberryfinn
2016-10-19 21:43 ` [PATCH v2] " Cathal Mullaney
2016-10-20  0:04   ` Kershner, David A
2016-10-20  3:10     ` Sell, Timothy C

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.