* [PATCH v2] staging: greybus: bootrom: keep fw->size access under bootrom->mutex
@ 2026-12-04 18:25 Omar Yiğitcan Mengü
2026-12-05 11:29 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread
* Re: [PATCH v2] staging: greybus: bootrom: keep fw->size access under bootrom->mutex
2026-12-04 18:25 [PATCH v2] staging: greybus: bootrom: keep fw->size access under bootrom->mutex Omar Yiğitcan Mengü
@ 2026-12-05 11:29 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2026-12-05 11:29 UTC (permalink / raw)
To: Omar Yiğitcan Mengü
Cc: Viresh Kumar, Johan Hovold, Alex Elder, Greg Kroah-Hartman,
greybus-dev, linux-staging
On Fri, Dec 04, 2026 at 09:25:29PM +0300, Omar Yiğitcan Mengü wrote:
> 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.
Thanks!
Reviewed-by: Dan Carpenter <error27@gmail.com>
Btw, I think we added an annotation for Clang which says certain pointers
can only be dereferenced when we're holding the lock? You could look at
adding that annotation here.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 11:29 UTC | newest]
Thread overview: 2+ messages (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ü
2026-12-05 11:29 ` Dan Carpenter
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.