Skip to contentSkip to conversation

misc: kgdbts: Fix restrict error

PATCH Superseded Laura Abbott 2 participants 3 messages Sep 10, 2018 – Sep 11, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: kgdbts: Fix restrict error

kgdbts current fails when compiled with restrict:

drivers/misc/kgdbts.c: In function ‘configure_kgdbts’:
drivers/misc/kgdbts.c:1070:2: error: ‘strcpy’ source argument is the same as destination [-Werror=restrict]
strcpy(config, opt);
^~~~~~~~~~~~~~~~~~~

As the error says, config is being used in both the source and destination. Refactor the code to only do the copy when needed.

---
 drivers/misc/kgdbts.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/misc/kgdbts.c +11 -10
index 6193270e7b3d..4447ad68ea39 100644
@@ -1061,20 +1061,23 @@ static void kgdbts_run_tests(void)
 	configured = 0;
 }
 
-static int kgdbts_option_setup(char *opt)
+static void kgdbts_set_verbose(void)
 {
-	if (strlen(opt) >= MAX_CONFIG_LEN) {
-		printk(KERN_ERR "kgdbts: config string too long\n");
-		return -ENOSPC;
-	}
-	strcpy(config, opt);
-
 	verbose = 0;
 	if (strstr(config, "V1"))
 		verbose = 1;
 	if (strstr(config, "V2"))
 		verbose = 2;
+}
 
+static int kgdbts_option_setup(char *opt)
+{
+	if (strlen(opt) >= MAX_CONFIG_LEN) {
+		printk(KERN_ERR "kgdbts: config string too long\n");
+		return -ENOSPC;
+	}
+	strcpy(config, opt);
+	kgdbts_set_verbose();
 	return 0;
 }
 
@@ -1086,9 +1089,7 @@ static int configure_kgdbts(void)
 
 	if (!strlen(config) || isspace(config[0]))
 		goto noconfig;
-	err = kgdbts_option_setup(config);
-	if (err)
-		goto noconfig;
+	kgdbts_set_verbose();
 
 	final_ack = 0;
 	run_plant_and_detach_test(1);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 37 lines · Laura Abbott

kgdbts current fails when compiled with restrict:

drivers/misc/kgdbts.c: In function ‘configure_kgdbts’:
drivers/misc/kgdbts.c:1070:2: error: ‘strcpy’ source argument is the same as destination [-Werror=restrict]
strcpy(config, opt);
^~~~~~~~~~~~~~~~~~~

As the error says, config is being used in both the source and destination. Refactor the code to only do the copy when needed.

---
 drivers/misc/kgdbts.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/misc/kgdbts.c +1 -7
index 6193270e7b3d..4447ad68ea39 100644
@@ -1061,20 +1061,23 @@ static void kgdbts_run_tests(void)
 	configured = 0;
 }
 
-static int kgdbts_option_setup(char *opt)
+static void kgdbts_set_verbose(void)
 {
-	if (strlen(opt) >= MAX_CONFIG_LEN) {
-		printk(KERN_ERR "kgdbts: config string too long\n");
-		return -ENOSPC;
-	}
-	strcpy(config, opt);
-
 	verbose = 0;
 	if (strstr(config, "V1"))
 		verbose = 1;
 	if (strstr(config, "V2"))
 		verbose = 2;

drivers/misc/kgdbts.c static void kgdbts_run_tests(void) · line 1080

Quoted 10 lines
drivers/misc/kgdbts.c +9 -0
+}
 
+static int kgdbts_option_setup(char *opt)
+{
+	if (strlen(opt) >= MAX_CONFIG_LEN) {
+		printk(KERN_ERR "kgdbts: config string too long\n");
+		return -ENOSPC;
+	}
+	strcpy(config, opt);
+	kgdbts_set_verbose();

I know this is honouring the existing code paths but I think kgdbts_set_verbose() is redundant here. Directly setting up verbose from kgdbts_run_tests() where the rest of the config string is parsed should be sufficient.

Having said that I don't want to bounce perfectly correct fixes just because they could have done more. Do you want to send a v2 or prefer me to put further clean up on my TODO list?

Daniel.

Quoted 17 lines
drivers/misc/kgdbts.c +1 -3
 	return 0;
 }
 
@@ -1086,9 +1089,7 @@ static int configure_kgdbts(void)
 
 	if (!strlen(config) || isspace(config[0]))
 		goto noconfig;
-	err = kgdbts_option_setup(config);
-	if (err)
-		goto noconfig;
+	kgdbts_set_verbose();
 
 	final_ack = 0;
 	run_plant_and_detach_test(1);
Signature · 1 line
2.17.1
#2 lore raw
Quoted 54 lines · Daniel Thompson
Quoted 37 lines · Laura Abbott

kgdbts current fails when compiled with restrict:

drivers/misc/kgdbts.c: In function ‘configure_kgdbts’:
drivers/misc/kgdbts.c:1070:2: error: ‘strcpy’ source argument is the same as destination [-Werror=restrict]

   strcpy(config, opt);
   ^~~~~~~~~~~~~~~~~~~

As the error says, config is being used in both the source and destination. Refactor the code to only do the copy when needed.

---
  drivers/misc/kgdbts.c | 21 +++++++++++----------
  1 file changed, 11 insertions(+), 10 deletions(-)
drivers/misc/kgdbts.c +1 -7
index 6193270e7b3d..4447ad68ea39 100644
@@ -1061,20 +1061,23 @@ static void kgdbts_run_tests(void)
  	configured = 0;
  }
 
-static int kgdbts_option_setup(char *opt)
+static void kgdbts_set_verbose(void)
  {
-	if (strlen(opt) >= MAX_CONFIG_LEN) {
-		printk(KERN_ERR "kgdbts: config string too long\n");
-		return -ENOSPC;
-	}
-	strcpy(config, opt);
-
  	verbose = 0;
  	if (strstr(config, "V1"))
  		verbose = 1;
  	if (strstr(config, "V2"))
  		verbose = 2;

drivers/misc/kgdbts.c static void kgdbts_run_tests(void) · line 1080

Quoted 10 lines
drivers/misc/kgdbts.c +9 -0
+}
 
+static int kgdbts_option_setup(char *opt)
+{
+	if (strlen(opt) >= MAX_CONFIG_LEN) {
+		printk(KERN_ERR "kgdbts: config string too long\n");
+		return -ENOSPC;
+	}
+	strcpy(config, opt);
+	kgdbts_set_verbose();

I know this is honouring the existing code paths but I think kgdbts_set_verbose() is redundant here. Directly setting up verbose from kgdbts_run_tests() where the rest of the config string is parsed should be sufficient.

Quoted 5 lines

Having said that I don't want to bounce perfectly correct fixes just because they could have done more. Do you want to send a v2 or prefer me to put further clean up on my TODO list?

I'll go ahead and send a v2

Quoted 19 lines

Daniel.

Quoted 17 lines
drivers/misc/kgdbts.c +1 -3
  	return 0;
  }
 
@@ -1086,9 +1089,7 @@ static int configure_kgdbts(void)
 
  	if (!strlen(config) || isspace(config[0]))
  		goto noconfig;
-	err = kgdbts_option_setup(config);
-	if (err)
-		goto noconfig;
+	kgdbts_set_verbose();
 
  	final_ack = 0;
  	run_plant_and_detach_test(1);
Signature · 1 line
2.17.1