Skip to contentSkip to conversation

staging: nvec: use guard(mutex) in nvec_write_sync()

PATCH In review Jeremy Dean Clifton 4 participants 6 messages Oct 12 – Oct 15 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/1 staging: nvec: use guard(mutex) in nvec_write_sync()

The three return paths of nvec_write_sync() each release sync_write_mutex with explicit unlock calls.

Use guard(mutex) to unlock the lock automatically on any return path.

This removes the three mutex_unlock() calls.

No functional change.

---
v2:
- Reword the commit message to state the motivation and to make clear that removing the mutex_unlock() calls is the result of the change (Julia Lawall).
v1: https://lore.kernel.org/all/[email protected]/

 drivers/staging/nvec/nvec.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/staging/nvec/nvec.c +2 -7
index 41cbdfdc1da6..716b1b482568 100644
@@ -298,17 +298,15 @@ int nvec_write_sync(struct nvec_chip *nvec,
 		    const unsigned char *data, short size,
 		    struct nvec_msg **msg)
 {
-	mutex_lock(&nvec->sync_write_mutex);
+	guard(mutex)(&nvec->sync_write_mutex);
 
 	if (msg)
 		*msg = NULL;
 
 	nvec->sync_write_pending = (data[1] << 8) + data[0];
 
-	if (nvec_write_async(nvec, data, size) < 0) {
-		mutex_unlock(&nvec->sync_write_mutex);
+	if (nvec_write_async(nvec, data, size) < 0)
 		return -ENOMEM;
-	}
 
 	dev_dbg(nvec->dev, "nvec_sync_write: 0x%04x\n",
 		nvec->sync_write_pending);
@@ -316,7 +314,6 @@ int nvec_write_sync(struct nvec_chip *nvec,
 					  msecs_to_jiffies(2000)))) {
 		dev_warn(nvec->dev,
 			 "Timeout waiting for sync write to complete\n");
-		mutex_unlock(&nvec->sync_write_mutex);
 		return -ETIMEDOUT;
 	}
 
@@ -327,8 +324,6 @@ int nvec_write_sync(struct nvec_chip *nvec,
 	else
 		nvec_msg_free(nvec, nvec->last_sync_msg);
 
-	mutex_unlock(&nvec->sync_write_mutex);
-
 	return 0;
 }
 EXPORT_SYMBOL(nvec_write_sync);
Signature · 1 line
2.43.0
#2 lore raw
Quoted 10 lines · Jeremy Dean Clifton

The three return paths of nvec_write_sync() each release sync_write_mutex with explicit unlock calls.

Use guard(mutex) to unlock the lock automatically on any return path.

This removes the three mutex_unlock() calls.

No functional change.

Quoted 7 lines

---
v2:
- Reword the commit message to state the motivation and to make clear that removing the mutex_unlock() calls is the result of the change (Julia Lawall).
v1: https://lore.kernel.org/all/[email protected]/

Please read the archives for why I will not take guard() rewrites of staging drivers (nor do I want to see you use a LLM in here either.)

sorry,

greg k-h

#3 lore raw

OK, it's understood. I'll look for another candidate.

Thanks for your feedback.

Jeremy

Quoted 25 lines · Greg Kroah-Hartman
Quoted 10 lines · Jeremy Dean Clifton

The three return paths of nvec_write_sync() each release sync_write_mutex with explicit unlock calls.

Use guard(mutex) to unlock the lock automatically on any return path.

This removes the three mutex_unlock() calls.

No functional change.

Quoted 7 lines

---
v2:
- Reword the commit message to state the motivation and to make clear that removing the mutex_unlock() calls is the result of the change (Julia Lawall).
v1: https://lore.kernel.org/all/[email protected]/

Please read the archives for why I will not take guard() rewrites of staging drivers (nor do I want to see you use a LLM in here either.)

sorry,

greg k-h

#4 lore raw
Quoted 3 lines · Jeremy Clifton

OK, it's understood. I'll look for another candidate.

Thanks for your feedback.

This is top posting. Please don't do that. Put your response under what you are responding to.

julia

Quoted 31 lines

Jeremy

Quoted 25 lines · Greg Kroah-Hartman
Quoted 10 lines · Jeremy Dean Clifton

The three return paths of nvec_write_sync() each release sync_write_mutex with explicit unlock calls.

Use guard(mutex) to unlock the lock automatically on any return path.

This removes the three mutex_unlock() calls.

No functional change.

Quoted 7 lines

---
v2:
- Reword the commit message to state the motivation and to make clear that removing the mutex_unlock() calls is the result of the change (Julia Lawall).
v1: https://lore.kernel.org/all/[email protected]/

Please read the archives for why I will not take guard() rewrites of staging drivers (nor do I want to see you use a LLM in here either.)

sorry,

greg k-h

#5 lore raw
In reply to Greg Kroah-Hartman
Quoted 19 lines · Greg Kroah-Hartman
Quoted 10 lines · Jeremy Dean Clifton

The three return paths of nvec_write_sync() each release sync_write_mutex with explicit unlock calls.

Use guard(mutex) to unlock the lock automatically on any return path.

This removes the three mutex_unlock() calls.

No functional change.

Quoted 7 lines

---
v2:
- Reword the commit message to state the motivation and to make clear that removing the mutex_unlock() calls is the result of the change (Julia Lawall).
v1: https://lore.kernel.org/all/[email protected]/

Quoted 6 lines

Please read the archives for why I will not take guard() rewrites of staging drivers (nor do I want to see you use a LLM in here either.)

sorry,

greg k-h

Hello Greg + Everyone,

It turns out that I was unknowingly subscribed to this list and started creating patches for the Outreachy group without ever having submitted an application to Outreachy. I just wanted to learn how to contribute to the Linux Kernel and I saw https://kernelnewbies.org/ as a direct connection to Outreachy.

While I am technically not part of this cohort, I can still review patches. What is preferred?

I assume that the same rules apply outside of Outreachy? No LLMs and no guard() rewrites.

Jeremy

#6 lore raw
Quoted 36 lines · Jeremy Dean Clifton
Quoted 19 lines · Greg Kroah-Hartman
Quoted 10 lines · Jeremy Dean Clifton

The three return paths of nvec_write_sync() each release sync_write_mutex with explicit unlock calls.

Use guard(mutex) to unlock the lock automatically on any return path.

This removes the three mutex_unlock() calls.

No functional change.

Quoted 7 lines

---
v2:
- Reword the commit message to state the motivation and to make clear that removing the mutex_unlock() calls is the result of the change (Julia Lawall).
v1: https://lore.kernel.org/all/[email protected]/

Quoted 6 lines

Please read the archives for why I will not take guard() rewrites of staging drivers (nor do I want to see you use a LLM in here either.)

sorry,

greg k-h

Hello Greg + Everyone,

It turns out that I was unknowingly subscribed to this list and started creating patches for the Outreachy group without ever having submitted an application to Outreachy. I just wanted to learn how to contribute to the Linux Kernel and I saw https://kernelnewbies.org/ as a direct connection to Outreachy.

Quoted 5 lines

While I am technically not part of this cohort, I can still review patches. What is preferred?

I assume that the same rules apply outside of Outreachy? No LLMs and no guard() rewrites.

Yes, to my understanding.

julia

Quoted 5 lines

Jeremy