Skip to contentSkip to conversation

Staging: speakup: Remove an unnecessary initialization in function

PATCH In review Madhumitha Prabakaran 3 participants 9 messages Mar 12, 2019 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: speakup: Remove an unnecessary initialization in function

Remove an unnecessary initialization of local variable dt_stat in function. Issue suggested by Coccinelle using ret.cocci.

---
 drivers/staging/speakup/speakup_decpc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/speakup/speakup_decpc.c +2 -3
index 459ee0c0bd57..3ad49bb93829 100644
@@ -233,9 +233,8 @@ static struct spk_synth synth_dec_pc = {
 
 static int dt_getstatus(void)
 {
-	dt_stat = inb_p(speakup_info.port_tts) |
-		 (inb_p(speakup_info.port_tts + 1) << 8);
-	return dt_stat;
+	return inb_p(speakup_info.port_tts) |
+	       (inb_p(speakup_info.port_tts + 1) << 8);
 }
 
 static void dt_sendcmd(u_int cmd)
Signature · 1 line
2.17.1
#1 lore raw

Madhumitha Prabakaran, le mar. 12 mars 2019 12:37:30 -0500, a ecrit:

Quoted 2 lines

Remove an unnecessary initialization of local variable dt_stat in function. Issue suggested by Coccinelle using ret.cocci.

dt_stat is a global variable, so this is not the same, with your change it wouldn't get written to.

Quoted 24 lines
---
 drivers/staging/speakup/speakup_decpc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/speakup/speakup_decpc.c +2 -3
index 459ee0c0bd57..3ad49bb93829 100644
@@ -233,9 +233,8 @@ static struct spk_synth synth_dec_pc = {
 
 static int dt_getstatus(void)
 {
-	dt_stat = inb_p(speakup_info.port_tts) |
-		 (inb_p(speakup_info.port_tts + 1) << 8);
-	return dt_stat;
+	return inb_p(speakup_info.port_tts) |
+	       (inb_p(speakup_info.port_tts + 1) << 8);
 }
 
 static void dt_sendcmd(u_int cmd)
Signature · 1 line
2.17.1
Signature · 6 lines
Samuel
    if (argc > 1 && strcmp(argv[1], "-advice") == 0) {
	printf("Don't Panic!\n");
	exit(42);
    }
	-- Arnold Robbins in the LJ of February '95, describing RCS
#2 lore raw
Quoted 27 lines · Samuel Thibault

Madhumitha Prabakaran, le mar. 12 mars 2019 12:37:30 -0500, a ecrit:

Quoted 2 lines

Remove an unnecessary initialization of local variable dt_stat in function. Issue suggested by Coccinelle using ret.cocci.

dt_stat is a global variable, so this is not the same, with your change it wouldn't get written to.

Quoted 20 lines
---
 drivers/staging/speakup/speakup_decpc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/speakup/speakup_decpc.c +2 -3
index 459ee0c0bd57..3ad49bb93829 100644
@@ -233,9 +233,8 @@ static struct spk_synth synth_dec_pc = {
 
 static int dt_getstatus(void)
 {
-	dt_stat = inb_p(speakup_info.port_tts) |
-		 (inb_p(speakup_info.port_tts + 1) << 8);
-	return dt_stat;
+	return inb_p(speakup_info.port_tts) |
+	       (inb_p(speakup_info.port_tts + 1) << 8);
 }
 
Quoted 19 lines
Quoted 4 lines
drivers/staging/speakup/speakup_decpc.c +0 -0
 static void dt_sendcmd(u_int cmd)
Signature · 1 line
2.17.1
Signature · 13 lines
Samuel
    if (argc > 1 && strcmp(argv[1], "-advice") == 0) {
	printf("Don't Panic!\n");
	exit(42);
    }
	-- Arnold Robbins in the LJ of February '95, describing RCS

-- 
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/20190312173911.dttfxifz42x2weaw%40function.
For more options, visit https://groups.google.com/d/optout.

Yeah. I will drop this patch.

Thanks.

#3 lore raw
In reply to Madhumitha Prabakaran
Quoted 13 lines · Madhumitha Prabakaran

Remove an unnecessary initialization of local variable dt_stat in function. Issue suggested by Coccinelle using ret.cocci.

---
 drivers/staging/speakup/speakup_decpc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/speakup/speakup_decpc.c +0 -0
index 459ee0c0bd57..3ad49bb93829 100644

drivers/staging/speakup/speakup_decpc.c static struct spk_synth synth_dec_pc = { · line 237

Quoted 8 lines
drivers/staging/speakup/speakup_decpc.c +2 -3
@@ -233,9 +233,8 @@ static struct spk_synth synth_dec_pc = {
 
 static int dt_getstatus(void)
 {
-	dt_stat = inb_p(speakup_info.port_tts) |
-		 (inb_p(speakup_info.port_tts + 1) << 8);
-	return dt_stat;
+	return inb_p(speakup_info.port_tts) |
+	       (inb_p(speakup_info.port_tts + 1) << 8);

This doesn't look correct, because dt_stat is not declared in this function. Did you get this result from the semantic patch that is at:

https://kernelnewbies.org/JuliaLawall

That says "local idexpression ret;", so it should only report on the case where the variable is declared in the same function.

julia

Quoted 13 lines
drivers/staging/speakup/speakup_decpc.c +0 -1
 }
 
 static void dt_sendcmd(u_int cmd)
--

2.17.1

--
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/20190312173730.23281-1-madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#4 lore raw
Quoted 42 lines · Julia Lawall
Quoted 13 lines · Madhumitha Prabakaran

Remove an unnecessary initialization of local variable dt_stat in function. Issue suggested by Coccinelle using ret.cocci.

---
 drivers/staging/speakup/speakup_decpc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/speakup/speakup_decpc.c +0 -0
index 459ee0c0bd57..3ad49bb93829 100644

drivers/staging/speakup/speakup_decpc.c static struct spk_synth synth_dec_pc = { · line 237

Quoted 8 lines
drivers/staging/speakup/speakup_decpc.c +2 -3
@@ -233,9 +233,8 @@ static struct spk_synth synth_dec_pc = {
 
 static int dt_getstatus(void)
 {
-	dt_stat = inb_p(speakup_info.port_tts) |
-		 (inb_p(speakup_info.port_tts + 1) << 8);
-	return dt_stat;
+	return inb_p(speakup_info.port_tts) |
+	       (inb_p(speakup_info.port_tts + 1) << 8);

This doesn't look correct, because dt_stat is not declared in this function. Did you get this result from the semantic patch that is at:

https://kernelnewbies.org/JuliaLawall

That says "local idexpression ret;", so it should only report on the case where the variable is declared in the same function.

julia

Quoted 6 lines
drivers/staging/speakup/speakup_decpc.c +0 -1
 }
 
 static void dt_sendcmd(u_int cmd)
--

2.17.1

Quoted 14 lines
Quoted 7 lines

--
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/20190312173730.23281-1-madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Signature · 5 lines
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/alpine.DEB.2.20.1903121850370.4097%40hadrien.
For more options, visit https://groups.google.com/d/optout.

Yes.

1. I created a file in home ret.cocci, which is

@@
local idexpression ret;
expression e;
@@

-ret =
+return

     e;

-return ret;

2. I run a command
spatch --sp-file ret.cocci --no-includes --dir git/kernels/staging/drivers/staging/ > ret.out which generated this file.

Please correct me, if I'm wrong here

Thanks,
Madhu

#5 lore raw
Quoted 72 lines · Madhumthia Prabakaran
Quoted 50 lines · Julia Lawall
Quoted 13 lines · Madhumitha Prabakaran

Remove an unnecessary initialization of local variable dt_stat in function. Issue suggested by Coccinelle using ret.cocci.

---
 drivers/staging/speakup/speakup_decpc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/speakup/speakup_decpc.c +0 -0
index 459ee0c0bd57..3ad49bb93829 100644

drivers/staging/speakup/speakup_decpc.c static struct spk_synth synth_dec_pc = { · line 237

Quoted 8 lines
drivers/staging/speakup/speakup_decpc.c +2 -3
@@ -233,9 +233,8 @@ static struct spk_synth synth_dec_pc = {
 
 static int dt_getstatus(void)
 {
-	dt_stat = inb_p(speakup_info.port_tts) |
-		 (inb_p(speakup_info.port_tts + 1) << 8);
-	return dt_stat;
+	return inb_p(speakup_info.port_tts) |
+	       (inb_p(speakup_info.port_tts + 1) << 8);

This doesn't look correct, because dt_stat is not declared in this function. Did you get this result from the semantic patch that is at:

https://kernelnewbies.org/JuliaLawall

That says "local idexpression ret;", so it should only report on the case where the variable is declared in the same function.

julia

Quoted 6 lines
drivers/staging/speakup/speakup_decpc.c +0 -1
 }
 
 static void dt_sendcmd(u_int cmd)
--

2.17.1

Quoted 7 lines

--
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/20190312173730.23281-1-madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Quoted 6 lines

--
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/alpine.DEB.2.20.1903121850370.4097%40hadrien.
For more options, visit https://groups.google.com/d/optout.

Yes.

1. I created a file in home ret.cocci, which is

@@
local idexpression ret;
expression e;
@@

(quoted diff) +1 -2
-ret =
+return
     e;
-return ret;
Quoted 3 lines

2. I run a command
spatch --sp-file ret.cocci --no-includes --dir git/kernels/staging/drivers/staging/ > ret.out which generated this file.

The approach looks fine, but I don't get any output related to that file. Can you double check that your semantic patch is exactly as you have put it above? What do you get when you run it giving the name of the specific file?

julia

Quoted 13 lines

Please correct me, if I'm wrong here

Thanks,
Madhu

--
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/20190312180344.GA17075%40madhuleo.
For more options, visit https://groups.google.com/d/optout.

#6 lore raw
Quoted 85 lines · Julia Lawall
Quoted 72 lines · Madhumthia Prabakaran
Quoted 50 lines · Julia Lawall
Quoted 13 lines · Madhumitha Prabakaran

Remove an unnecessary initialization of local variable dt_stat in function. Issue suggested by Coccinelle using ret.cocci.

---
 drivers/staging/speakup/speakup_decpc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/speakup/speakup_decpc.c +0 -0
index 459ee0c0bd57..3ad49bb93829 100644

drivers/staging/speakup/speakup_decpc.c static struct spk_synth synth_dec_pc = { · line 237

Quoted 8 lines
drivers/staging/speakup/speakup_decpc.c +2 -3
@@ -233,9 +233,8 @@ static struct spk_synth synth_dec_pc = {
 
 static int dt_getstatus(void)
 {
-	dt_stat = inb_p(speakup_info.port_tts) |
-		 (inb_p(speakup_info.port_tts + 1) << 8);
-	return dt_stat;
+	return inb_p(speakup_info.port_tts) |
+	       (inb_p(speakup_info.port_tts + 1) << 8);

This doesn't look correct, because dt_stat is not declared in this function. Did you get this result from the semantic patch that is at:

https://kernelnewbies.org/JuliaLawall

That says "local idexpression ret;", so it should only report on the case where the variable is declared in the same function.

julia

Quoted 6 lines
drivers/staging/speakup/speakup_decpc.c +0 -1
 }
 
 static void dt_sendcmd(u_int cmd)
--

2.17.1

Quoted 7 lines

--
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/20190312173730.23281-1-madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Quoted 6 lines

--
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/alpine.DEB.2.20.1903121850370.4097%40hadrien.
For more options, visit https://groups.google.com/d/optout.

Yes.

1. I created a file in home ret.cocci, which is

@@
local idexpression ret;
expression e;
@@

(quoted diff) +1 -2
-ret =
+return
     e;
-return ret;
Quoted 3 lines

2. I run a command
spatch --sp-file ret.cocci --no-includes --dir git/kernels/staging/drivers/staging/ > ret.out which generated this file.

The approach looks fine, but I don't get any output related to that file. Can you double check that your semantic patch is exactly as you have put it above? What do you get when you run it giving the name of the specific file?

Quoted 15 lines

julia

Quoted 13 lines

Please correct me, if I'm wrong here

Thanks,
Madhu

--
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/20190312180344.GA17075%40madhuleo.
For more options, visit https://groups.google.com/d/optout.

I did have same semantic patch.

Output of file -

...
...
HANDLING: git/kernels/staging/drivers/staging/speakup/main.c
HANDLING: git/kernels/staging/drivers/staging/speakup/speakup_bns.c
HANDLING: git/kernels/staging/drivers/staging/speakup/speakup_apollo.mod.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_sii164.c diff =
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_chip.c diff =
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_swi2c.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_mode.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_dvi.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750_accel.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750fb.mod.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_hwi2c.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_display.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_power.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750_hw.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750_cursor.c

Here, Do I need to consider the file, which states diff =
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_chip.c

Thanks,
Madhumitha

#7 lore raw
Quoted 23 lines

Output of file -

...
...
HANDLING: git/kernels/staging/drivers/staging/speakup/main.c
HANDLING: git/kernels/staging/drivers/staging/speakup/speakup_bns.c
HANDLING: git/kernels/staging/drivers/staging/speakup/speakup_apollo.mod.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_sii164.c diff =
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_chip.c diff =
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_swi2c.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_mode.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_dvi.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750_accel.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750fb.mod.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_hwi2c.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_display.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_power.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750_hw.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750_cursor.c

Quoted 2 lines

Here, Do I need to consider the file, which states diff =
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_chip.c

You would indeed find changes on standard output for the files that have diff here.

If you don't want to see this output, you can use the option --very-quiet. Usually I put both standrad output and standard error in files, so I can look at them later if there are any issues.

I don't see the entry for the file that was incorrectly transformed, so I'm still not sure what the issue is. Can you try your semantic patch on just the file drivers/staging/speakup/speakup_decpc.c? Are you sure that your semantic patch has the word "local"? If you have idexpression without the local, that would explain the result.

julia

#8 lore raw
Quoted 33 lines · Julia Lawall
Quoted 23 lines

Output of file -

...
...
HANDLING: git/kernels/staging/drivers/staging/speakup/main.c
HANDLING: git/kernels/staging/drivers/staging/speakup/speakup_bns.c
HANDLING: git/kernels/staging/drivers/staging/speakup/speakup_apollo.mod.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_sii164.c diff =
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_chip.c diff =
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_swi2c.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_mode.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_dvi.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750_accel.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750fb.mod.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_hwi2c.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_display.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_power.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750_hw.c
HANDLING: git/kernels/staging/drivers/staging/sm750fb/sm750_cursor.c

Quoted 2 lines

Here, Do I need to consider the file, which states diff =
HANDLING: git/kernels/staging/drivers/staging/sm750fb/ddk750_chip.c

You would indeed find changes on standard output for the files that have diff here.

If you don't want to see this output, you can use the option --very-quiet. Usually I put both standrad output and standard error in files, so I can look at them later if there are any issues.

Quoted 14 lines

I don't see the entry for the file that was incorrectly transformed, so I'm still not sure what the issue is. Can you try your semantic patch on just the file drivers/staging/speakup/speakup_decpc.c? Are you sure that your semantic patch has the word "local"? If you have idexpression without the local, that would explain the result.

julia

Signature · 5 lines
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/alpine.DEB.2.21.1903122008400.2722%40hadrien.
For more options, visit https://groups.google.com/d/optout.

1. Output for spatch --sp-file Coco/ret.cocci --no-includes --dir git/kernels/staging/drivers/staging/speakup/speakup_decpc.c > ret.out -

init_defs_builtins: /usr/lib/coccinelle/standard.h
HANDLING: git/kernels/staging/drivers/staging/speakup/speakup_decpc.c

Content of file ret.cocci

@@
local idexpression ret;
expression e;
@@

-ret =
+return

     e;

-return ret;

2. Output for spatch --sp-file Coco/ret.cocci --no-includes --dir git/kernels/staging/drivers/staging/speakup/speakup_decpc.c > ret.out

init_defs_builtins: /usr/lib/coccinelle/standard.h
HANDLING: git/kernels/staging/drivers/staging/speakup/speakup_decpc.c diff =

Now, content of file ret.cocci

@@
idexpression ret;
expression e;
@@

-ret =
+return

     e;

-return ret;

So, there was no local when I tried earlier. I will fix it and resend another patch.

I will drop this one.

Thanks,
Madhumitha