* [PATCH] staging: greybus: Use guard(mutex) in receive_data()
@ 2026-02-25 10:30 Matvey Oborotov
2026-02-25 14:54 ` Greg Kroah-Hartman
0 siblings, 1 reply; 2+ messages in thread
From: Matvey Oborotov @ 2026-02-25 10:30 UTC (permalink / raw)
To: Johan Hovold, Alex Elder, Greg Kroah-Hartman
Cc: greybus-dev, linux-staging, linux-kernel, Matvey Oborotov
Replace manual mutex_lock/unlock with guard(mutex) in raw.c
receive_data(). This automates lock release on function exit, ensures
that lock is released on early returns, and makes the code cleaner.
Signed-off-by: Matvey Oborotov <oborotovmatvey@gmail.com>
---
drivers/staging/greybus/raw.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/drivers/staging/greybus/raw.c b/drivers/staging/greybus/raw.c
index 3027a2c25bcd..6c31bae0d8ea 100644
--- a/drivers/staging/greybus/raw.c
+++ b/drivers/staging/greybus/raw.c
@@ -59,34 +59,28 @@ static int receive_data(struct gb_raw *raw, u32 len, u8 *data)
{
struct raw_data *raw_data;
struct device *dev = &raw->connection->bundle->dev;
- int retval = 0;
if (len > MAX_PACKET_SIZE) {
dev_err(dev, "Too big of a data packet, rejected\n");
return -EINVAL;
}
- mutex_lock(&raw->list_lock);
+ guard(mutex)(&raw->list_lock);
if ((raw->list_data + len) > MAX_DATA_SIZE) {
dev_err(dev, "Too much data in receive buffer, now dropping packets\n");
- retval = -EINVAL;
- goto exit;
+ return -EINVAL;
}
raw_data = kmalloc_flex(*raw_data, data, len);
- if (!raw_data) {
- retval = -ENOMEM;
- goto exit;
- }
+ if (!raw_data)
+ return -ENOMEM;
raw->list_data += len;
raw_data->len = len;
memcpy(&raw_data->data[0], data, len);
list_add_tail(&raw_data->entry, &raw->list);
-exit:
- mutex_unlock(&raw->list_lock);
- return retval;
+ return 0;
}
static int gb_raw_request_handler(struct gb_operation *op)
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] staging: greybus: Use guard(mutex) in receive_data()
2026-02-25 10:30 [PATCH] staging: greybus: Use guard(mutex) in receive_data() Matvey Oborotov
@ 2026-02-25 14:54 ` Greg Kroah-Hartman
0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2026-02-25 14:54 UTC (permalink / raw)
To: Matvey Oborotov
Cc: Johan Hovold, Alex Elder, greybus-dev, linux-staging, linux-kernel
On Wed, Feb 25, 2026 at 03:30:06PM +0500, Matvey Oborotov wrote:
> Replace manual mutex_lock/unlock with guard(mutex) in raw.c
> receive_data(). This automates lock release on function exit, ensures
> that lock is released on early returns, and makes the code cleaner.
>
> Signed-off-by: Matvey Oborotov <oborotovmatvey@gmail.com>
> ---
> drivers/staging/greybus/raw.c | 16 +++++-----------
> 1 file changed, 5 insertions(+), 11 deletions(-)
Please only use guard() logic with new code, or if you are fixing a bug.
Making changes like this to existing code is not needed at all, it just
causes unwanted churn for no good reason.
sorry,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-25 14:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-25 10:30 [PATCH] staging: greybus: Use guard(mutex) in receive_data() Matvey Oborotov
2026-02-25 14:54 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®