staging: most: move assignment out of function call
Subsystems (2)
PATCH 1/1 staging: most: move assignment out of function call
Pull out assignment used as a function argument before the function call to improve readability. Change was made by hand while the following coccinelle script was used to pinpoint the issue:
@a@
identifier func;
expression list E;
position p;
@@
func@p(E);
@script:python b@
E << a.E;
func << a.func;
p << a.p;arg_list;
@@arg_list = []
for i in E:
if ( '=' in i
and not '"' in i
and not '==' in i
and not '!=' in i
and not '<=' in i
and not '>=' in i
):
print "function: " + func + " has assignment at arg: " + i print "in file: " + p[0].file + " , line: " + p[0].line arg_list.append(i)
for j in arg_list:
print j
--- drivers/staging/most/aim-sound/sound.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/most/aim-sound/sound.c +3 -3
@@ -236,12 +236,12 @@ static int playback_thread(void *data)bool period_elapsed = false;int ret; + mbo =most_get_mbo (channel->iface, channel->id, + &audio_aim);wait_event_interruptible ( channel->playback_waitq,kthread_should_stop () || - (channel->is_stream_running && - (mbo =most_get_mbo (channel->iface, channel->id, - &audio_aim)))); + (channel->is_stream_running && mbo));if (!mbo)continue ;
Signature · 1 line
2.7.4
Quoted 24 lines · Eva Rachel Retuya
Pull out assignment used as a function argument before the function call to improve readability. Change was made by hand while the following coccinelle script was used to pinpoint the issue:
@a@
identifier func;
expression list E;
position p;
@@func@p(E);
@script:python b@
E << a.E;
func << a.func;
p << a.p;arg_list;
@@arg_list= []
for i in E:
if ( '=' in i
and not '"' in i
and not '==' in i
and not '!=' in i
Quoted 8 lines
and not '<=' in i
and not '>=' in i
):
print "function: " + func + " has assignment at arg: " + i print "in file: " + p[0].file + " , line: " + p[0].linearg_list.append(i)
for j inarg_list:
print j
This is definitely inventive :). It's really nice that you thought of combining pattern matching and python. On the other hand, I think that it could have been done easily with only pattern matching too. In recent versions of ocaml, there is a metavariable type
assignment operator a;
Then you can say eg x a e, for any kind of assignment of e to x.
No need to update the semantic patch for this case, though.
Quoted 10 lines
Signed-off-by Eva Rachel Retuya <[email protected]>--- drivers/staging/most/aim-sound/sound.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/staging/most/aim-sound/sound.c +0
-0
drivers/staging/most/aim-sound/sound.c static int playback_thread(void *data) · line 240
Quoted 5 lines
drivers/staging/most/aim-sound/sound.c +2
-0@@ -236,12 +236,12 @@ static int playback_thread(void *data)bool period_elapsed = false;int ret; + mbo =most_get_mbo (channel->iface, channel->id, + &audio_aim);
Does &audio_aim not fit on the same line?
drivers/staging/most/aim-sound/sound.c static int playback_thread(void *data) · line 242
Quoted 4 lines
drivers/staging/most/aim-sound/sound.c +0
-1wait_event_interruptible( channel->playback_waitq, kthread_should_stop() || - (channel->is_stream_running &&
Unfortunately, in the end, it looks like this may not be correct, because the most_get_mbo call should only happen if channel->is_stream_running is true. To make the change, you would need to pull the condition out of the argument list too.
julia
Quoted 16 lines
drivers/staging/most/aim-sound/sound.c +1
-3- (mbo =most_get_mbo (channel->iface, channel->id, - &audio_aim)))); + (channel->is_stream_running && mbo));if (!mbo)continue ; --2.7.4
--
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/1473739629-17286-1-git-send-email-eraretuya%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 40 lines · Julia Lawall
Quoted 24 lines · Eva Rachel Retuya
Pull out assignment used as a function argument before the function call to improve readability. Change was made by hand while the following coccinelle script was used to pinpoint the issue:
@a@
identifier func;
expression list E;
position p;
@@func@p(E);
@script:python b@
E << a.E;
func << a.func;
p << a.p;arg_list;
@@arg_list= []
for i in E:
if ( '=' in i
and not '"' in i
and not '==' in i
and not '!=' in iQuoted 8 lines
and not '<=' in i
and not '>=' in i
):
print "function: " + func + " has assignment at arg: " + i print "in file: " + p[0].file + " , line: " + p[0].linearg_list.append(i)
for j inarg_list:
print jThis is definitely inventive :). It's really nice that you thought of combining pattern matching and python. On the other hand, I think that it could have been done easily with only pattern matching too. In recent versions of ocaml, there is a metavariable type
Quoted 6 lines
assignment operator a;
Then you can say eg x a e, for any kind of assignment of e to x.
No need to update the semantic patch for this case, though.
Noted! Thank you for the feedback.
Quoted 19 lines
Quoted 11 lines
Signed-off-by Eva Rachel Retuya <[email protected]>--- drivers/staging/most/aim-sound/sound.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/staging/most/aim-sound/sound.c +0
-0drivers/staging/most/aim-sound/sound.c static int playback_thread(void *data) · line 240
Quoted 5 lines
drivers/staging/most/aim-sound/sound.c +2
-0@@ -236,12 +236,12 @@ static int playback_thread(void *data)bool period_elapsed = false;int ret; + mbo =most_get_mbo (channel->iface, channel->id, + &audio_aim);Does
&audio_aimnot fit on the same line?
Quoted 10 lines
drivers/staging/most/aim-sound/sound.c static int playback_thread(void *data) · line 242
Quoted 4 lines
drivers/staging/most/aim-sound/sound.c +0
-1wait_event_interruptible( channel->playback_waitq, kthread_should_stop() || - (channel->is_stream_running &&Unfortunately, in the end, it looks like this may not be correct, because the
most_get_mbocall should only happen ifchannel->is_stream_runningis true. To make the change, you would need to pull the condition out of the argument list too.
Thanks for pointing this out. Looks like I'm going to drop this patch because it is entirely wrong due to reasons both you and Greg stated.
Quoted 18 lines
julia
Quoted 16 lines
drivers/staging/most/aim-sound/sound.c +1
-3- (mbo =most_get_mbo (channel->iface, channel->id, - &audio_aim)))); + (channel->is_stream_running && mbo));if (!mbo)continue ; --2.7.4
--
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/1473739629-17286-1-git-send-email-eraretuya%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Greg KH
maintainerQuoted 45 lines · Eva Rachel Retuya
Pull out assignment used as a function argument before the function call to improve readability. Change was made by hand while the following coccinelle script was used to pinpoint the issue:
@a@
identifier func;
expression list E;
position p;
@@func@p(E);
@script:python b@
E << a.E;
func << a.func;
p << a.p;arg_list;
@@arg_list= []
for i in E:
if ( '=' in i
and not '"' in i
and not '==' in i
and not '!=' in i
and not '<=' in i
and not '>=' in i
):
print "function: " + func + " has assignment at arg: " + i print "in file: " + p[0].file + " , line: " + p[0].linearg_list.append(i)
for j inarg_list:
print jSigned-off-by Eva Rachel Retuya <[email protected]>--- drivers/staging/most/aim-sound/sound.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/staging/most/aim-sound/sound.c +0
-0@@ -236,12 +236,12 @@ static int playback_thread(void *data)bool period_elapsed = false;int ret;
drivers/staging/most/aim-sound/sound.c static int playback_thread(void *data) · line 244
Quoted 10 lines
drivers/staging/most/aim-sound/sound.c +3
-3+ mbo =most_get_mbo (channel->iface, channel->id, + &audio_aim);wait_event_interruptible ( channel->playback_waitq,kthread_should_stop () || - (channel->is_stream_running && - (mbo =most_get_mbo (channel->iface, channel->id, - &audio_aim)))); + (channel->is_stream_running && mbo));
This patch isn't doing what you think it is doing :(
You need to keep calling most_get_mbo() for this to work properly, look up how wait_event_interruptible() works.
thanks,
greg k-h
Quoted 59 lines · Greg KH
Quoted 45 lines · Eva Rachel Retuya
Pull out assignment used as a function argument before the function call to improve readability. Change was made by hand while the following coccinelle script was used to pinpoint the issue:
@a@
identifier func;
expression list E;
position p;
@@func@p(E);
@script:python b@
E << a.E;
func << a.func;
p << a.p;arg_list;
@@arg_list= []
for i in E:
if ( '=' in i
and not '"' in i
and not '==' in i
and not '!=' in i
and not '<=' in i
and not '>=' in i
):
print "function: " + func + " has assignment at arg: " + i print "in file: " + p[0].file + " , line: " + p[0].linearg_list.append(i)
for j inarg_list:
print jSigned-off-by Eva Rachel Retuya <[email protected]>--- drivers/staging/most/aim-sound/sound.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/staging/most/aim-sound/sound.c +0
-0@@ -236,12 +236,12 @@ static int playback_thread(void *data)bool period_elapsed = false;int ret;drivers/staging/most/aim-sound/sound.c static int playback_thread(void *data) · line 244
Quoted 10 lines
drivers/staging/most/aim-sound/sound.c +3
-3+ mbo =most_get_mbo (channel->iface, channel->id, + &audio_aim);wait_event_interruptible ( channel->playback_waitq,kthread_should_stop () || - (channel->is_stream_running && - (mbo =most_get_mbo (channel->iface, channel->id, - &audio_aim)))); + (channel->is_stream_running && mbo));This patch isn't doing what you think it is doing :(
Quoted 3 lines
You need to keep calling
most_get_mbo()for this to work properly, look up howwait_event_interruptible()works.
My bad. Thank you for the feedback. I will be more extra careful next time.
Quoted 3 lines
thanks,
greg k-h