mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matvey Oborotov <oborotovmatvey@gmail.com>
To: Johan Hovold <johan@kernel.org>, Alex Elder <elder@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Matvey Oborotov <oborotovmatvey@gmail.com>
Subject: [PATCH] staging: greybus: Use guard(mutex) in receive_data()
Date: Wed, 25 Feb 2026 15:30:06 +0500	[thread overview]
Message-ID: <20260225103006.295553-1-oborotovmatvey@gmail.com> (raw)

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


             reply	other threads:[~2026-02-25 10:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-25 10:30 Matvey Oborotov [this message]
2026-02-25 14:54 ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260225103006.295553-1-oborotovmatvey@gmail.com \
    --to=oborotovmatvey@gmail.com \
    --cc=elder@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=greybus-dev@lists.linaro.org \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®