Skip to contentSkip to conversation

Staging: greybus: Fix spinlock_t definition without comment

PATCH In review Madhumitha Prabakaran 4 participants 6 messages Apr 5, 2019 – Apr 15, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: greybus: Fix spinlock_t definition without comment

Fix spinlock_t definition without comment.

---
 drivers/staging/greybus/connection.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/connection.h +1 -1
index 5ca3befc0636..0aedd246e94a 100644
@@ -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;
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 12 lines · Madhumitha Prabakaran

Fix spinlock_t definition without comment.

---
 drivers/staging/greybus/connection.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/connection.h +0 -0
index 5ca3befc0636..0aedd246e94a 100644

drivers/staging/greybus/connection.h struct gb_connection { · line 51

Quoted 6 lines
drivers/staging/greybus/connection.h +1 -1
@@ -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

#2 lore raw
Quoted 5 lines · Dan Carpenter
Quoted 3 lines · Madhumitha Prabakaran

Fix spinlock_t definition without comment.

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

Quoted 10 lines
Quoted 10 lines

--- drivers/staging/greybus/connection.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)

(quoted diff) +0 -0

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;

Quoted 5 lines
Quoted 2 lines

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

Quoted 8 lines

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

regards, dan carpenter

_______________________________________________ greybus-dev mailing list [email protected]
https://lists.linaro.org/mailman/listinfo/greybus-dev

#3 lore raw
Quoted 5 lines · Alex Elder
Quoted 4 lines · Dan Carpenter
Quoted 2 lines · Madhumitha Prabakaran

Fix spinlock_t definition without comment.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

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.

Quoted 5 lines

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

Quoted 20 lines

Given that, a better comment might be:

spinlock_t lock; /* operations list and state */

Quoted 10 lines
Quoted 10 lines

--- drivers/staging/greybus/connection.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)

(quoted diff) +0 -0

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;

Quoted 5 lines
Quoted 2 lines

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?

Quoted 6 lines

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.

Quoted 10 lines
Quoted 9 lines

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

regards, dan carpenter

_______________________________________________ greybus-dev mailing list [email protected]
https://lists.linaro.org/mailman/listinfo/greybus-dev

maintainer
#4 lore raw
In reply to Alex Elder
Quoted 37 lines · Alex Elder
Quoted 5 lines · Dan Carpenter
Quoted 3 lines · Madhumitha Prabakaran

Fix spinlock_t definition without comment.

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

Quoted 10 lines
Quoted 10 lines

--- drivers/staging/greybus/connection.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)

(quoted diff) +0 -0

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;

Quoted 5 lines
Quoted 2 lines

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?

Quoted 4 lines

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

#5 lore raw
In reply to Dan Carpenter
Quoted 15 lines · Dan Carpenter
Quoted 14 lines · Madhumitha Prabakaran

Fix spinlock_t definition without comment.

---
 drivers/staging/greybus/connection.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/connection.h +0 -0
index 5ca3befc0636..0aedd246e94a 100644
@@ -47,7 +47,7 @@ struct gb_connection {
 	unsigned long			flags;
 
Quoted 7 lines

drivers/staging/greybus/connection.h struct gb_connection { · line 51

Quoted 4 lines
drivers/staging/greybus/connection.h +1 -1
 	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.

Quoted 2 lines

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

Thanks for reviewing it.

Quoted 4 lines

regards,
dan carpenter