Skip to contentSkip to conversation

Staging: unisys: visorbus: visorchipset: Converted arrays to static const

PATCH In review Shivani Bhardwaj 3 participants 7 messages Sep 29, 2015 – Sep 30, 2015 4 messages not in the archive Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: unisys: visorbus: visorchipset: Converted arrays to static const

Replaced the declaration of character array from char * to static const char * const as the array is not intended to be used anywhere outside the function plus the values in array and the pointer to it don't have to be changed.

---
 drivers/staging/unisys/visorbus/visorchipset.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/unisys/visorbus/visorchipset.c +2 -2
index 4b76cb4..073b45b 100644
@@ -1411,7 +1411,7 @@ static int
 visorchipset_chipset_selftest(void)
 {
 	char env_selftest[20];
-	char *envp[] = { env_selftest, NULL };
+	static const char * const envp[] = { env_selftest, NULL };
 
 	sprintf(env_selftest, "SPARSP_SELFTEST=%d", 1);
 	kobject_uevent_env(&visorchipset_platform_device.dev.kobj, KOBJ_CHANGE,
@@ -1561,7 +1561,7 @@ parahotplug_request_kickoff(struct parahotplug_request *req)
 	struct controlvm_message_packet *cmd = &req->msg.cmd;
 	char env_cmd[40], env_id[40], env_state[40], env_bus[40], env_dev[40],
 	    env_func[40];
-	char *envp[] = {
+	static const char * const envp[] = {
 		env_cmd, env_id, env_state, env_bus, env_dev, env_func, NULL
 	};
 
Signature · 1 line
2.1.0
maintainer
#1 lore raw
Quoted 15 lines · Shivani Bhardwaj

Replaced the declaration of character array from char * to static const char * const as the array is not intended to be used anywhere outside the function plus the values in array and the pointer to it don't have to be changed.

---
 drivers/staging/unisys/visorbus/visorchipset.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/unisys/visorbus/visorchipset.c +0 -0
index 4b76cb4..073b45b 100644

drivers/staging/unisys/visorbus/visorchipset.c static int · line 1414

Quoted 5 lines
drivers/staging/unisys/visorbus/visorchipset.c +1 -1
@@ -1411,7 +1411,7 @@ static int
 visorchipset_chipset_selftest(void)
 {
 	char env_selftest[20];
-	char *envp[] = { env_selftest, NULL };
+	static const char * const envp[] = { env_selftest, NULL };

The compiler didn't complain when you did this? That's really strange, it should have.

Think about what you just turned envp into, and how env_selftest could ever be correct now, given that the scope lifetime rules just changed between the two variables.

I would leave this one alone, it's tricky and odds are, something is going to be wrong with changing it, there's nothing wrong with the original code as-is.

thanks,

greg k-h

#4 lore raw
In reply to a message not in the archive

This was a warning message by compiler only that I need to convert char * to static const char * const. I just did that without noticing env_selftest which is directly related. and then when I compiled, it worked. Compilers aren't very reliable, I see.

Thanks, Greg!

Quoted 12 lines · Greg KH

On Wed, Sep 30, 2015 at 09:41:14AM +0530, Shivani Bhardwaj wrote:

<snip>

For some reason you sent this only to me, which is a bit rude to everyone else on the mailing list. I'll be glad to respond if you resend it to everyone.

thanks,

greg k-h

#5 lore raw

This was a warning message by compiler only that I need to convert char * to static const char * const. I just did that without noticing env_selftest which is directly related. and then when I compiled, it worked. Compilers aren't very reliable, I see.

Thanks, Greg!

Quoted 24 lines · Shivani Bhardwaj

This was a warning message by compiler only that I need to convert char * to static const char * const. I just did that without noticing env_selftest which is directly related. and then when I compiled, it worked. Compilers aren't very reliable, I see.

Thanks, Greg!

Quoted 12 lines · Greg KH

On Wed, Sep 30, 2015 at 09:41:14AM +0530, Shivani Bhardwaj wrote:

<snip>

For some reason you sent this only to me, which is a bit rude to everyone else on the mailing list. I'll be glad to respond if you resend it to everyone.

thanks,

greg k-h

#6 lore raw
Quoted 4 lines · Shivani Bhardwaj

This was a warning message by compiler only that I need to convert char * to static const char * const. I just did that without noticing env_selftest which is directly related. and then when I compiled, it worked. Compilers aren't very reliable, I see.

Please do not top-post. When you are responding to email, respond inline. You can use this link to understand proper communication style:
http://kernelnewbies.org/FirstKernelPatch#head-9799d3ebaa1221875dfdb0a05c4063dc4eb474a1

Quoted 39 lines

Thanks, Greg!

Quoted 6 lines · Shivani Bhardwaj

This was a warning message by compiler only that I need to convert char * to static const char * const. I just did that without noticing env_selftest which is directly related. and then when I compiled, it worked. Compilers aren't very reliable, I see.

Quoted 18 lines

Thanks, Greg!

Quoted 12 lines · Greg KH

On Wed, Sep 30, 2015 at 09:41:14AM +0530, Shivani Bhardwaj wrote:

<snip>

For some reason you sent this only to me, which is a bit rude to everyone else on the mailing list. I'll be glad to respond if you resend it to everyone.

thanks,

greg k-h

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected]. To view this discussion on the web visit
https://groups.google.com/d/msgid/outreachy-kernel/CAKHNQQGy1mPrWEcWqHFBNz_8BiG2sFSGAL9LmHgSLS0gPn9cog%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Signature · 1 line
Vaishali
maintainer
#7 lore raw
In reply to Shivani Bhardwaj
Quoted 2 lines · Shivani Bhardwaj

This was a warning message by compiler only that I need to convert char * to static const char * const.

The compiler said that? Can you post the exact message gcc gave you for this line, that seems very odd.

thanks,

greg k-h

#10 lore raw
In reply to a message not in the archive

Thanks Julia!
And Greg, I'm really sorry, warning was generated by checkpatch script not gcc. I read online that it does generate false warnings. Thank you.

Quoted 77 lines · Shivani Bhardwaj

Thanks Julia!
And Greg, I'm really sorry, warning was generated by checkpatch script not gcc. I read online that it does generate false warnings. Thank you.

Quoted 67 lines · Julia Lawall
Quoted 4 lines · Shivani Bhardwaj

Replaced the declaration of character array from char * to static const char * const as the array is not intended to be used anywhere outside the function plus the values in array and the pointer to it don't have to be changed.

It's confusing, but static should not be used on local variable because they are not used outside the function. Static means that the variable is allocated only once over all executions of the functions. Actually, it becomes like a global variable that no one else can see. If you call the function once, and change the value of the variable, then on the next call you see the changed value until the variable is modified.

Here that all makes no sense, because you say that the array is not modified, and anyway the code explicitly sets the variable to its original value.

julia

Review

Quoted 6 lines
---
 drivers/staging/unisys/visorbus/visorchipset.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/unisys/visorbus/visorchipset.c

drivers/staging/unisys/visorbus/visorchipset.c static int · line 1417

Quoted 12 lines

index 4b76cb4..073b45b 100644

drivers/staging/unisys/visorbus/visorchipset.c +1 -1
@@ -1411,7 +1411,7 @@ static int
 visorchipset_chipset_selftest(void)
 {
      char env_selftest[20];
-     char *envp[] = { env_selftest, NULL };
+     static const char * const envp[] = { env_selftest, NULL };
 
      sprintf(env_selftest, "SPARSP_SELFTEST=%d", 1);
      kobject_uevent_env(&visorchipset_platform_device.dev.kobj,

KOBJ_CHANGE,

drivers/staging/unisys/visorbus/visorchipset.c parahotplug_request_kickoff(struct

Quoted 1 line
drivers/staging/unisys/visorbus/visorchipset.c +0 -0
@@ -1561,7 +1561,7 @@ parahotplug_request_kickoff(struct

parahotplug_request *req)

drivers/staging/unisys/visorbus/visorchipset.c parahotplug_request_kickoff(struct · line 1562

Quoted 2 lines
drivers/staging/unisys/visorbus/visorchipset.c +0 -0
      struct controlvm_message_packet *cmd = &req->msg.cmd;
      char env_cmd[40], env_id[40], env_state[40], env_bus[40],

env_dev[40],

drivers/staging/unisys/visorbus/visorchipset.c parahotplug_request_kickoff(struct parahotplug_request *req)

Quoted 4 lines
drivers/staging/unisys/visorbus/visorchipset.c +1 -1
          env_func[40];
-     char *envp[] = {
+     static const char * const envp[] = {
              env_cmd, env_id, env_state, env_bus, env_dev, env_func,

NULL

Quoted 7 lines
drivers/staging/unisys/visorbus/visorchipset.c +0 -1
      };
 
--

2.1.0

--
You received this message because you are subscribed to the Google

Groups "outreachy-kernel" group.

Quoted 1 line

To unsubscribe from this group and stop receiving emails from it, send

an email to [email protected].

Quoted 2 lines

To post to this group, send email to [email protected]. To view this discussion on the web visit

https://groups.google.com/d/msgid/outreachy-kernel/20150929232413.GA16457%40ubuntu
.

Quoted 2 lines

For more options, visit https://groups.google.com/d/optout.