Skip to contentSkip to conversation

staging: greybus: bootrom: fix uninitialized variables

PATCH In review Saurav Girepunje 4 participants 5 messages Jan 25, 2020 – Jan 27, 2020

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

PATCH 1/1 staging: greybus: bootrom: fix uninitialized variables

fix uninitialized variables issue found using static code analysis tool

(error) Uninitialized variable: offset
(error) Uninitialized variable: size

---
 drivers/staging/greybus/bootrom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/bootrom.c +1 -1
index a8efb86..9eabeb3 100644
@@ -245,7 +245,7 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
 	struct gb_bootrom_get_firmware_request *firmware_request;
 	struct gb_bootrom_get_firmware_response *firmware_response;
 	struct device *dev = &op->connection->bundle->dev;
-	unsigned int offset, size;
+	unsigned int offset = 0, size = 0;
 	enum next_request_type next_request;
 	int ret = 0;
 
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 1 line · Saurav Girepunje

fix uninitialized variables issue found using static code analysis tool

Which tool is that?

Quoted 13 lines

(error) Uninitialized variable: offset
(error) Uninitialized variable: size

---
  drivers/staging/greybus/bootrom.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/bootrom.c +0 -0
index a8efb86..9eabeb3 100644

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

Quoted 7 lines
drivers/staging/greybus/bootrom.c +1 -1
@@ -245,7 +245,7 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
  	struct gb_bootrom_get_firmware_request *firmware_request;
  	struct gb_bootrom_get_firmware_response *firmware_response;
  	struct device *dev = &op->connection->bundle->dev;
-	unsigned int offset, size;
+	unsigned int offset = 0, size = 0;
  	enum next_request_type next_request;
  	int ret = 0;

I think this has come up in the past, and while the code in question is overly complicated and confuses static checkers as well as humans, it looks correct to me.

Please make sure to verify the output of any tools before posting patches based on them.

Johan

#2 lore raw
Quoted 30 lines · Johan Hovold
Quoted 1 line · Saurav Girepunje

fix uninitialized variables issue found using static code analysis tool

Which tool is that?

Quoted 13 lines

(error) Uninitialized variable: offset
(error) Uninitialized variable: size

---
  drivers/staging/greybus/bootrom.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/bootrom.c +0 -0
index a8efb86..9eabeb3 100644

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

Quoted 7 lines
drivers/staging/greybus/bootrom.c +1 -1
@@ -245,7 +245,7 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
  	struct gb_bootrom_get_firmware_request *firmware_request;
  	struct gb_bootrom_get_firmware_response *firmware_response;
  	struct device *dev = &op->connection->bundle->dev;
-	unsigned int offset, size;
+	unsigned int offset = 0, size = 0;
  	enum next_request_type next_request;
  	int ret = 0;

I think this has come up in the past, and while the code in question is overly complicated and confuses static checkers as well as humans, it looks correct to me.

Quoted 4 lines

Please make sure to verify the output of any tools before posting patches based on them.

Johan

I used cppcheck tool .

#3 lore raw
Quoted 31 lines · SAURAV GIREPUNJE
Quoted 30 lines · Johan Hovold
Quoted 1 line · Saurav Girepunje

fix uninitialized variables issue found using static code analysis tool

Which tool is that?

Quoted 13 lines

(error) Uninitialized variable: offset
(error) Uninitialized variable: size

---
  drivers/staging/greybus/bootrom.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/bootrom.c +0 -0
index a8efb86..9eabeb3 100644

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

Quoted 7 lines
drivers/staging/greybus/bootrom.c +1 -1
@@ -245,7 +245,7 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
       struct gb_bootrom_get_firmware_request *firmware_request;
       struct gb_bootrom_get_firmware_response *firmware_response;
       struct device *dev = &op->connection->bundle->dev;
-    unsigned int offset, size;
+    unsigned int offset = 0, size = 0;
       enum next_request_type next_request;
       int ret = 0;

I think this has come up in the past, and while the code in question is overly complicated and confuses static checkers as well as humans, it looks correct to me.

Quoted 5 lines
Quoted 4 lines

Please make sure to verify the output of any tools before posting patches based on them.

Johan

I used cppcheck tool .

Implied in Johan's question is a suggestion.

When you propose a patch that addresses something flagged by a tool of some kind, it is good practice to identify the tool in the patch description, and even better, give an example of how the tool was invoked when reported the problem you're fixing. Sometimes people even include the output of the tool, though I think that can sometimes be a bit much.

And as you have now heard several times, do not blindly trust the output of these tools. They're intended to call attention to things for you to examine; they are no match for a human, and things they tell you about are not guaranteed to be real problems.

-Alex

Quoted 4 lines

_______________________________________________
greybus-dev mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/greybus-dev

#4 lore raw
In reply to Saurav Girepunje
Quoted 5 lines · Saurav Girepunje

fix uninitialized variables issue found using static code analysis tool

(error) Uninitialized variable: offset
(error) Uninitialized variable: size

These are false positives as Johan said. Don't change the code just to make the static analysis tool happy, fix the tools instead.

Also the patch doesn't apply. Read the first paragraph of Documentation/process/email-clients.rst and figure out why it's not working.

regards,
dan carpenter