All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: greybus: fix fw is NULL but dereferenced.
@ 2020-01-26  8:31 ` Saurav Girepunje
  0 siblings, 0 replies; 18+ messages in thread
From: Saurav Girepunje @ 2020-01-26  8:31 UTC (permalink / raw)
  To: vireshk, johan, elder, gregkh, greybus-dev, devel, linux-kernel
  Cc: 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.

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.

Signed-off-by: Saurav Girepunje <saurav.girepunje@gmail.com>
---
  drivers/staging/greybus/bootrom.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/greybus/bootrom.c b/drivers/staging/greybus/bootrom.c
index a8efb86..f54514e 100644
--- a/drivers/staging/greybus/bootrom.c
+++ b/drivers/staging/greybus/bootrom.c
@@ -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;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [PATCH]  staging: greybus: fix fw is NULL but dereferenced
@ 2021-03-25 10:19 ` Jian Dong
  0 siblings, 0 replies; 18+ messages in thread
From: Jian Dong @ 2021-03-25 10:19 UTC (permalink / raw)
  To: vireshk, johan, elder, gregkh
  Cc: greybus-dev, devel, linux-kernel, huyue2, Jian Dong

From: Jian Dong <dongjian@yulong.com>

 fixes coccicheck Error:

 drivers/staging/greybus/bootrom.c:301:41-45: ERROR:
 fw is NULL but dereferenced.

 if procedure goto label directly, ret will be nefative, so the fw is NULL
 and the if(condition) end with dereferenced fw. let's fix it.

Signed-off-by: Jian Dong <dongjian@yulong.com>
---
 drivers/staging/greybus/bootrom.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/greybus/bootrom.c b/drivers/staging/greybus/bootrom.c
index a8efb86..0439efa 100644
--- a/drivers/staging/greybus/bootrom.c
+++ b/drivers/staging/greybus/bootrom.c
@@ -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 */
@@ -298,10 +298,10 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
 
 queue_work:
 	/* Refresh timeout */
-	if (!ret && (offset + size == fw->size))
-		next_request = NEXT_REQ_READY_TO_BOOT;
-	else
+	if (!!ret)
 		next_request = NEXT_REQ_GET_FIRMWARE;
+	else if (offset + size == fw->size)
+		next_request = NEXT_REQ_READY_TO_BOOT;
 
 	gb_bootrom_set_timeout(bootrom, next_request, NEXT_REQ_TIMEOUT_MS);
 
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-03-25 11:41 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-26  8:31 [PATCH] staging: greybus: fix fw is NULL but dereferenced Saurav Girepunje
2020-01-26  8:31 ` Saurav Girepunje
2020-01-26 11:04 ` Johan Hovold
2020-01-26 11:04   ` Johan Hovold
2020-01-26 18:30 ` Greg KH
2020-01-26 18:30   ` Greg KH
2021-03-25 10:19 Jian Dong
2021-03-25 10:19 ` Jian Dong
2021-03-25 10:29 ` Greg KH
2021-03-25 10:29   ` Greg KH
2021-03-25 11:03   ` Jian Dong
2021-03-25 11:03     ` Jian Dong
2021-03-25 11:32     ` Greg KH
2021-03-25 11:32       ` Greg KH
2021-03-25 10:50 ` Dan Carpenter
2021-03-25 10:50   ` Dan Carpenter
2021-03-25 10:51 ` Viresh Kumar
2021-03-25 10:51   ` Viresh Kumar

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.