Skip to contentSkip to conversation

Staging: unisys: Change char * array type as static const

PATCH In review Yeliz Taneroglu 2 participants 2 messages Mar 4, 2015 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: unisys: Change char * array type as static const

This patch fixes "char * array declaration might be better as static const" checkpatch.pl warning in visorchipset_main.c

---
 drivers/staging/unisys/visorchipset/visorchipset_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/unisys/visorchipset/visorchipset_main.c +3 -3
index f606ee9..7e97b8e 100644
@@ -1009,7 +1009,7 @@ device_epilog(u32 busNo, u32 devNo, struct spar_segment_state state, u32 cmd,
 
 	struct visorchipset_device_info *pDevInfo =
 		finddevice(&DevInfoList, busNo, devNo);
-	char *envp[] = {
+	static const char *const envp[] = {
 		"SPARSP_DIAGPOOL_PAUSED_STATE = 1",
 		NULL
 	};
@@ -1481,7 +1481,7 @@ 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,
@@ -1637,7 +1637,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
1.8.3.2
#1 lore raw

drivers/staging/unisys/visorchipset/visorchipset_main.c int · line 1484

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

This appears to be quite incorrect. env_selftest is an array with no initialized information at this point. Adding the const declarations should make it impossible to put anything in the array. It seems unlikely that the compiler would allow this, unless the array is not used at all. Furthermore, env_selftest is allocated on the stack, whereas a variable that is declared as static is initialized only once, when the declaration is first executed. On subsequent calls to the function, envp will contain a pointer to an address that now refers to something completely different.

julia

Quoted 21 lines
drivers/staging/unisys/visorchipset/visorchipset_main.c +1 -2
 	sprintf(env_selftest, "SPARSP_SELFTEST=%d", 1);
 	kobject_uevent_env(&Visorchipset_platform_device.dev.kobj, KOBJ_CHANGE,
@@ -1637,7 +1637,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
 	};
 
--

1.8.3.2

--
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/1425499377-11968-1-git-send-email-yeliztaneroglu%40gmail.com.
For more options, visit https://groups.google.com/d/optout.