linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Staging: greybus: Fix spinlock_t definition without comment
@ 2019-04-05 20:00 Madhumitha Prabakaran
  2019-04-05 20:53 ` Dan Carpenter
  0 siblings, 1 reply; 6+ messages in thread
From: Madhumitha Prabakaran @ 2019-04-05 20:00 UTC (permalink / raw)
  To: johan, elder, gregkh, greybus-dev, devel, linux-kernel
  Cc: Madhumitha Prabakaran

Fix spinlock_t definition without comment.

Signed-off-by: Madhumitha Prabakaran <madhumithabiw@gmail.com>
---
 drivers/staging/greybus/connection.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/greybus/connection.h b/drivers/staging/greybus/connection.h
index 5ca3befc0636..0aedd246e94a 100644
--- a/drivers/staging/greybus/connection.h
+++ b/drivers/staging/greybus/connection.h
@@ -47,7 +47,7 @@ struct gb_connection {
 	unsigned long			flags;
 
 	struct mutex			mutex;
-	spinlock_t			lock;
+	spinlock_t			lock; /* Protect structure fields */
 	enum gb_connection_state	state;
 	struct list_head		operations;
 
-- 
2.17.1


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

* Re: [PATCH] Staging: greybus: Fix spinlock_t definition without comment
  2019-04-05 20:00 [PATCH] Staging: greybus: Fix spinlock_t definition without comment Madhumitha Prabakaran
@ 2019-04-05 20:53 ` Dan Carpenter
  2019-04-05 22:50   ` [greybus-dev] " Alex Elder
  2019-04-06 22:55   ` Madhumthia Prabakaran
  0 siblings, 2 replies; 6+ messages in thread
From: Dan Carpenter @ 2019-04-05 20:53 UTC (permalink / raw)
  To: Madhumitha Prabakaran
  Cc: johan, elder, gregkh, greybus-dev, devel, linux-kernel

On Fri, Apr 05, 2019 at 03:00:46PM -0500, Madhumitha Prabakaran wrote:
> Fix spinlock_t definition without comment.
> 
> Signed-off-by: Madhumitha Prabakaran <madhumithabiw@gmail.com>
> ---
>  drivers/staging/greybus/connection.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/greybus/connection.h b/drivers/staging/greybus/connection.h
> index 5ca3befc0636..0aedd246e94a 100644
> --- a/drivers/staging/greybus/connection.h
> +++ b/drivers/staging/greybus/connection.h
> @@ -47,7 +47,7 @@ struct gb_connection {
>  	unsigned long			flags;
>  
>  	struct mutex			mutex;
> -	spinlock_t			lock;
> +	spinlock_t			lock; /* Protect structure fields */
>  	enum gb_connection_state	state;

What does the mutex do then?  Why can't we just use the spinlock for
everything?

I did glance at the code and it wasn't immediately obvious to me.

regards,
dan carpenter


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

* Re: [greybus-dev] [PATCH] Staging: greybus: Fix spinlock_t definition without comment
  2019-04-05 20:53 ` Dan Carpenter
@ 2019-04-05 22:50   ` Alex Elder
  2019-04-06 23:06     ` Madhumthia Prabakaran
  2019-04-15 12:59     ` Johan Hovold
  2019-04-06 22:55   ` Madhumthia Prabakaran
  1 sibling, 2 replies; 6+ messages in thread
From: Alex Elder @ 2019-04-05 22:50 UTC (permalink / raw)
  To: Dan Carpenter, Madhumitha Prabakaran
  Cc: devel, elder, johan, linux-kernel, greybus-dev

On 4/5/19 3:53 PM, Dan Carpenter wrote:
> On Fri, Apr 05, 2019 at 03:00:46PM -0500, Madhumitha Prabakaran
> wrote:
>> Fix spinlock_t definition without comment.
>> 
>> Signed-off-by: Madhumitha Prabakaran <madhumithabiw@gmail.com>

Madhumitha, the reason one would want a comment associated with
a lock field in a structure is to get some understanding of why
it's needed.  Saying "protect structure fields" is not enough,
because that can pretty much be assumed, so a comment like that
adds no value.

Looking at the code, you can see the lock field protects the
connection's operations list.  It also appears to be needed
for accessing the state field (reading or updating).

Given that, a better comment might be:

        spinlock_t                      lock;	/* operations list and state */

>> --- drivers/staging/greybus/connection.h | 2 +- 1 file changed, 1
>> insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/staging/greybus/connection.h
>> b/drivers/staging/greybus/connection.h index
>> 5ca3befc0636..0aedd246e94a 100644 ---
>> a/drivers/staging/greybus/connection.h +++
>> b/drivers/staging/greybus/connection.h @@ -47,7 +47,7 @@ struct
>> gb_connection { unsigned long			flags;
>> 
>> struct mutex			mutex; -	spinlock_t			lock; +	spinlock_t			lock; /*
>> Protect structure fields */ enum gb_connection_state	state;
> 
> What does the mutex do then?  Why can't we just use the spinlock for 
> everything?

The mutex needs to be held during enable and disable of a connection.
Johan might be able to give you a more complete answer but these
operations (or at least the enable) need to block, so can't hold a
spinlock.

					-Alex

> I did glance at the code and it wasn't immediately obvious to me.
> 
> regards, dan carpenter
> 
> _______________________________________________ greybus-dev mailing
> list greybus-dev@lists.linaro.org 
> https://lists.linaro.org/mailman/listinfo/greybus-dev
> 


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

* Re: [PATCH] Staging: greybus: Fix spinlock_t definition without comment
  2019-04-05 20:53 ` Dan Carpenter
  2019-04-05 22:50   ` [greybus-dev] " Alex Elder
@ 2019-04-06 22:55   ` Madhumthia Prabakaran
  1 sibling, 0 replies; 6+ messages in thread
From: Madhumthia Prabakaran @ 2019-04-06 22:55 UTC (permalink / raw)
  To: Dan Carpenter, johan, elder, gregkh, greybus-dev, devel, linux-kernel

On Fri, Apr 05, 2019 at 11:53:04PM +0300, Dan Carpenter wrote:
> On Fri, Apr 05, 2019 at 03:00:46PM -0500, Madhumitha Prabakaran wrote:
> > Fix spinlock_t definition without comment.
> > 
> > Signed-off-by: Madhumitha Prabakaran <madhumithabiw@gmail.com>
> > ---
> >  drivers/staging/greybus/connection.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/staging/greybus/connection.h b/drivers/staging/greybus/connection.h
> > index 5ca3befc0636..0aedd246e94a 100644
> > --- a/drivers/staging/greybus/connection.h
> > +++ b/drivers/staging/greybus/connection.h
> > @@ -47,7 +47,7 @@ struct gb_connection {
> >  	unsigned long			flags;
> >  
> >  	struct mutex			mutex;
> > -	spinlock_t			lock;
> > +	spinlock_t			lock; /* Protect structure fields */
> >  	enum gb_connection_state	state;
> 
> What does the mutex do then?  Why can't we just use the spinlock for
> everything?

Here, mutexes protect spinlock_t for gb_connection_state fields and
gb_connection_state fields itself in struct gb_connection.

However, I wasn't sure then and now exactly, how to find out which resources in the
structure, the spinlock or mutex is performing kernel synchronization.

> 
> I did glance at the code and it wasn't immediately obvious to me.

Thanks for reviewing it.

> 
> regards,
> dan carpenter
> 

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

* Re: [greybus-dev] [PATCH] Staging: greybus: Fix spinlock_t definition without comment
  2019-04-05 22:50   ` [greybus-dev] " Alex Elder
@ 2019-04-06 23:06     ` Madhumthia Prabakaran
  2019-04-15 12:59     ` Johan Hovold
  1 sibling, 0 replies; 6+ messages in thread
From: Madhumthia Prabakaran @ 2019-04-06 23:06 UTC (permalink / raw)
  To: Alex Elder, dan.carpenter, devel, johan, linux-kernel, greybus-dev

On Fri, Apr 05, 2019 at 05:50:10PM -0500, Alex Elder wrote:
> On 4/5/19 3:53 PM, Dan Carpenter wrote:
> > On Fri, Apr 05, 2019 at 03:00:46PM -0500, Madhumitha Prabakaran
> > wrote:
> >> Fix spinlock_t definition without comment.
> >> 
> >> Signed-off-by: Madhumitha Prabakaran <madhumithabiw@gmail.com>
> 
> Madhumitha, the reason one would want a comment associated with
> a lock field in a structure is to get some understanding of why
> it's needed.  Saying "protect structure fields" is not enough,
> because that can pretty much be assumed, so a comment like that
> adds no value.

That's true. It doesn't make much sense.

> 
> Looking at the code, you can see the lock field protects the
> connection's operations list.  It also appears to be needed
> for accessing the state field (reading or updating).
> 

Along with that, in some cases the spinlocks are protecting hd_links and
bundle_links list.

Lines : drivers/staging/greybus/connection.c#895 #896


> Given that, a better comment might be:
> 
>         spinlock_t                      lock;	/* operations list and state */
> 
> >> --- drivers/staging/greybus/connection.h | 2 +- 1 file changed, 1
> >> insertion(+), 1 deletion(-)
> >> 
> >> diff --git a/drivers/staging/greybus/connection.h
> >> b/drivers/staging/greybus/connection.h index
> >> 5ca3befc0636..0aedd246e94a 100644 ---
> >> a/drivers/staging/greybus/connection.h +++
> >> b/drivers/staging/greybus/connection.h @@ -47,7 +47,7 @@ struct
> >> gb_connection { unsigned long			flags;
> >> 
> >> struct mutex			mutex; -	spinlock_t			lock; +	spinlock_t			lock; /*
> >> Protect structure fields */ enum gb_connection_state	state;
> > 
> > What does the mutex do then?  Why can't we just use the spinlock for 
> > everything?
> 
> The mutex needs to be held during enable and disable of a connection.
> Johan might be able to give you a more complete answer but these
> operations (or at least the enable) need to block, so can't hold a
> spinlock.
> 
> 					-Alex

Thanks for explaining it. Checking on the code, mutexes protect spinlock_t
for gb_connection_state fields and gb_connection_state fields itself in
struct gb_connection.

> 
> > I did glance at the code and it wasn't immediately obvious to me.
> > 
> > regards, dan carpenter
> > 
> > _______________________________________________ greybus-dev mailing
> > list greybus-dev@lists.linaro.org 
> > https://lists.linaro.org/mailman/listinfo/greybus-dev
> > 
> 

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

* Re: [greybus-dev] [PATCH] Staging: greybus: Fix spinlock_t definition without comment
  2019-04-05 22:50   ` [greybus-dev] " Alex Elder
  2019-04-06 23:06     ` Madhumthia Prabakaran
@ 2019-04-15 12:59     ` Johan Hovold
  1 sibling, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2019-04-15 12:59 UTC (permalink / raw)
  To: Alex Elder
  Cc: Dan Carpenter, Madhumitha Prabakaran, devel, elder, johan,
	linux-kernel, greybus-dev

On Fri, Apr 05, 2019 at 05:50:10PM -0500, Alex Elder wrote:
> On 4/5/19 3:53 PM, Dan Carpenter wrote:
> > On Fri, Apr 05, 2019 at 03:00:46PM -0500, Madhumitha Prabakaran
> > wrote:
> >> Fix spinlock_t definition without comment.
> >> 
> >> Signed-off-by: Madhumitha Prabakaran <madhumithabiw@gmail.com>
> 
> Madhumitha, the reason one would want a comment associated with
> a lock field in a structure is to get some understanding of why
> it's needed.  Saying "protect structure fields" is not enough,
> because that can pretty much be assumed, so a comment like that
> adds no value.
> 
> Looking at the code, you can see the lock field protects the
> connection's operations list.  It also appears to be needed
> for accessing the state field (reading or updating).
> 
> Given that, a better comment might be:
> 
>         spinlock_t                      lock;	/* operations list and state */
> 
> >> --- drivers/staging/greybus/connection.h | 2 +- 1 file changed, 1
> >> insertion(+), 1 deletion(-)
> >> 
> >> diff --git a/drivers/staging/greybus/connection.h
> >> b/drivers/staging/greybus/connection.h index
> >> 5ca3befc0636..0aedd246e94a 100644 ---
> >> a/drivers/staging/greybus/connection.h +++
> >> b/drivers/staging/greybus/connection.h @@ -47,7 +47,7 @@ struct
> >> gb_connection { unsigned long			flags;
> >> 
> >> struct mutex			mutex; -	spinlock_t			lock; +	spinlock_t			lock; /*
> >> Protect structure fields */ enum gb_connection_state	state;
> > 
> > What does the mutex do then?  Why can't we just use the spinlock for 
> > everything?
> 
> The mutex needs to be held during enable and disable of a connection.
> Johan might be able to give you a more complete answer but these
> operations (or at least the enable) need to block, so can't hold a
> spinlock.

Yeah, I should have documented this at the time.

You're right that the connection spinlock protects the operation list,
and the mutex the connection state, but there are some other
dependencies here and I don't have time to look at this at the moment.

Better to leave as is, I'd say.

Johan

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

end of thread, other threads:[~2019-04-15 12:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-05 20:00 [PATCH] Staging: greybus: Fix spinlock_t definition without comment Madhumitha Prabakaran
2019-04-05 20:53 ` Dan Carpenter
2019-04-05 22:50   ` [greybus-dev] " Alex Elder
2019-04-06 23:06     ` Madhumthia Prabakaran
2019-04-15 12:59     ` Johan Hovold
2019-04-06 22:55   ` Madhumthia Prabakaran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).