Skip to contentSkip to conversation

staging: greybus: fix fw is NULL but dereferenced.

PATCH In review Saurav Girepunje 3 participants 3 messages Jan 26, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: greybus: fix fw is NULL but dereferenced.

Fix the warning reported by cocci check.

Changes:

In queue_work fw dereference before it actually get assigned. move queue_work before gb_bootrom_set_timeout.

As gb_bootrom_get_firmware () return NEXT_REQ_READY_TO_BOOT only when there is no error and offset + size is actually equal to fw->size. So initialized next_request to NEXT_REQ_GET_FIRMWARE for return in other case.

---
 drivers/staging/greybus/bootrom.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/greybus/bootrom.c +2 -4
index a8efb86..f54514e 100644
@@ -246,7 +246,7 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
 	struct gb_bootrom_get_firmware_response *firmware_response;
 	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;
 	int ret = 0;
 
 	/* Disable timeouts */
@@ -296,13 +296,11 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
 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;
 
+queue_work:
 	gb_bootrom_set_timeout(bootrom, next_request, NEXT_REQ_TIMEOUT_MS);
 
 	return ret;
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 6 lines · Saurav Girepunje

Fix the warning reported by cocci check.

Changes:

In queue_work fw dereference before it actually get assigned. move queue_work before gb_bootrom_set_timeout.

Nope. As I said yesterday, you need to verify the output of any static checkers you use.

The code may be unnecessarily subtle, but there's no way fw can be dereferenced before being initialised currently.

Quoted 3 lines

-queue_work:
/* Refresh timeout */
if (!ret && (offset + size == fw->size))

Specifically, the second operand is never evaluated if ret is non-zero.

drivers/staging/greybus/bootrom.c static int gb_bootrom_get_firmware(struct gb_operation *op) · line 306

Quoted 8 lines
  		next_request = NEXT_REQ_READY_TO_BOOT;
drivers/staging/greybus/bootrom.c +1 -2
-	else
-		next_request = NEXT_REQ_GET_FIRMWARE;
 
+queue_work:
  	gb_bootrom_set_timeout(bootrom, next_request, NEXT_REQ_TIMEOUT_MS);
 
  	return ret;

Johan

maintainer
#2 lore raw
In reply to Saurav Girepunje
Quoted 1 line · Saurav Girepunje

Fix the warning reported by cocci check.

What is "cocci check"?

Quoted 2 lines

Changes:

Why add that line?

Quoted 8 lines

In queue_work fw dereference before it actually get assigned. move queue_work before gb_bootrom_set_timeout.

As gb_bootrom_get_firmware () return NEXT_REQ_READY_TO_BOOT only when there is no error and offset + size is actually equal to fw->size. So initialized next_request to NEXT_REQ_GET_FIRMWARE for return in other case.

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

As Johan said, there are a lot of really bad "static checking" tools out there that can not properly parse C code. Always verify by hand what the tools said is wrong, really is an issue before sending a patch out for something that is not correct. This looks like you need to use a better tool.

greg k-h