Linux kernel staging patches
 help / color / mirror / Atom feed
* [PATCH v2] staging: greybus: bootrom: keep fw->size access under bootrom->mutex
@ 2026-12-04 18:25 Omar Yiğitcan Mengü
  0 siblings, 0 replies; only message in thread
From: Omar Yiğitcan Mengü @ 2026-12-04 18:25 UTC (permalink / raw)
  To: Viresh Kumar, Johan Hovold, Alex Elder, Greg Kroah-Hartman
  Cc: greybus-dev, linux-staging, Omar Yiğitcan Mengü

bootrom->mutex is documented to protect bootrom->fw, but
gb_bootrom_get_firmware() dereferences fw->size after releasing
bootrom->mutex when selecting the next expected request type. This
breaks the locking invariant for bootrom->fw and also triggers a
Coccinelle deref_null.cocci error on the error-exit path where fw is
NULL.

Initialize next_request to NEXT_REQ_GET_FIRMWARE and evaluate
offset + size == fw->size while still holding bootrom->mutex.

Signed-off-by: Omar Yiğitcan Mengü <menguomary@gmail.com>
---

Changes in v2:
- Resend using git send-email to avoid line wrapping.

 drivers/staging/greybus/bootrom.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/greybus/bootrom.c b/drivers/staging/greybus/bootrom.c
index fb1fbd3f7b9..ed8e974c622 100644
--- a/drivers/staging/greybus/bootrom.c
+++ b/drivers/staging/greybus/bootrom.c
@@ -245,7 +245,7 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
 	struct gb_bootrom_get_firmware_request *firmware_request;
 	struct device *dev = &op->connection->bundle->dev;
 	unsigned int offset, size;
-	enum next_request_type next_request;
+	enum next_request_type next_request = NEXT_REQ_GET_FIRMWARE;
 	u8 *firmware_response;
 	int ret = 0;
 
@@ -293,16 +293,14 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
 	dev_dbg(dev, "responding with firmware (offs = %u, size = %u)\n",
 		offset, size);
 
+	if (offset + size == fw->size)
+		next_request = NEXT_REQ_READY_TO_BOOT;
+
 unlock:
 	mutex_unlock(&bootrom->mutex);
 
 queue_work:
 	/* Refresh timeout */
-	if (!ret && (offset + size == fw->size))
-		next_request = NEXT_REQ_READY_TO_BOOT;
-	else
-		next_request = NEXT_REQ_GET_FIRMWARE;
-
 	gb_bootrom_set_timeout(bootrom, next_request, NEXT_REQ_TIMEOUT_MS);
 
 	return ret;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-04 18:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 18:25 [PATCH v2] staging: greybus: bootrom: keep fw->size access under bootrom->mutex Omar Yiğitcan Mengü

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox