* [PATCH] staging: most: move assignment out of function call
@ 2016-09-13 4:07 Eva Rachel Retuya
2016-09-13 4:47 ` [Outreachy kernel] " Julia Lawall
2016-09-13 6:05 ` Greg KH
0 siblings, 2 replies; 5+ messages in thread
From: Eva Rachel Retuya @ 2016-09-13 4:07 UTC (permalink / raw)
To: gregkh; +Cc: outreachy-kernel, 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].line
arg_list.append(i)
for j in arg_list:
print j
Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com>
---
drivers/staging/most/aim-sound/sound.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/most/aim-sound/sound.c b/drivers/staging/most/aim-sound/sound.c
index 9c64580..e9d6b67 100644
--- a/drivers/staging/most/aim-sound/sound.c
+++ b/drivers/staging/most/aim-sound/sound.c
@@ -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;
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Outreachy kernel] [PATCH] staging: most: move assignment out of function call
2016-09-13 4:07 [PATCH] staging: most: move assignment out of function call Eva Rachel Retuya
@ 2016-09-13 4:47 ` Julia Lawall
2016-09-13 8:59 ` Eva Rachel Retuya
2016-09-13 6:05 ` Greg KH
1 sibling, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2016-09-13 4:47 UTC (permalink / raw)
To: Eva Rachel Retuya; +Cc: gregkh, outreachy-kernel
On Tue, 13 Sep 2016, Eva Rachel Retuya wrote:
> 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
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.
> Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com>
> ---
> drivers/staging/most/aim-sound/sound.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/most/aim-sound/sound.c b/drivers/staging/most/aim-sound/sound.c
> index 9c64580..e9d6b67 100644
> --- a/drivers/staging/most/aim-sound/sound.c
> +++ b/drivers/staging/most/aim-sound/sound.c
> @@ -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?
> wait_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
> - (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 outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> 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.
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] staging: most: move assignment out of function call
2016-09-13 4:07 [PATCH] staging: most: move assignment out of function call Eva Rachel Retuya
2016-09-13 4:47 ` [Outreachy kernel] " Julia Lawall
@ 2016-09-13 6:05 ` Greg KH
2016-09-13 9:02 ` Eva Rachel Retuya
1 sibling, 1 reply; 5+ messages in thread
From: Greg KH @ 2016-09-13 6:05 UTC (permalink / raw)
To: Eva Rachel Retuya; +Cc: outreachy-kernel
On Tue, Sep 13, 2016 at 12:07:09PM +0800, Eva Rachel Retuya wrote:
> 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
>
> Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com>
> ---
> drivers/staging/most/aim-sound/sound.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/most/aim-sound/sound.c b/drivers/staging/most/aim-sound/sound.c
> index 9c64580..e9d6b67 100644
> --- a/drivers/staging/most/aim-sound/sound.c
> +++ b/drivers/staging/most/aim-sound/sound.c
> @@ -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));
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Outreachy kernel] [PATCH] staging: most: move assignment out of function call
2016-09-13 4:47 ` [Outreachy kernel] " Julia Lawall
@ 2016-09-13 8:59 ` Eva Rachel Retuya
0 siblings, 0 replies; 5+ messages in thread
From: Eva Rachel Retuya @ 2016-09-13 8:59 UTC (permalink / raw)
To: Julia Lawall; +Cc: gregkh, outreachy-kernel
On Tue, Sep 13, 2016 at 06:47:37AM +0200, Julia Lawall wrote:
> On Tue, 13 Sep 2016, Eva Rachel Retuya wrote:
>
> > 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
>
> 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.
>
Noted! Thank you for the feedback.
>
> > Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com>
> > ---
> > drivers/staging/most/aim-sound/sound.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/staging/most/aim-sound/sound.c b/drivers/staging/most/aim-sound/sound.c
> > index 9c64580..e9d6b67 100644
> > --- a/drivers/staging/most/aim-sound/sound.c
> > +++ b/drivers/staging/most/aim-sound/sound.c
> > @@ -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?
>
> > wait_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.
>
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.
> julia
>
> > - (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 outreachy-kernel+unsubscribe@googlegroups.com.
> > To post to this group, send email to outreachy-kernel@googlegroups.com.
> > 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.
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] staging: most: move assignment out of function call
2016-09-13 6:05 ` Greg KH
@ 2016-09-13 9:02 ` Eva Rachel Retuya
0 siblings, 0 replies; 5+ messages in thread
From: Eva Rachel Retuya @ 2016-09-13 9:02 UTC (permalink / raw)
To: Greg KH; +Cc: outreachy-kernel
On Tue, Sep 13, 2016 at 08:05:22AM +0200, Greg KH wrote:
> On Tue, Sep 13, 2016 at 12:07:09PM +0800, Eva Rachel Retuya wrote:
> > 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
> >
> > Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com>
> > ---
> > drivers/staging/most/aim-sound/sound.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/staging/most/aim-sound/sound.c b/drivers/staging/most/aim-sound/sound.c
> > index 9c64580..e9d6b67 100644
> > --- a/drivers/staging/most/aim-sound/sound.c
> > +++ b/drivers/staging/most/aim-sound/sound.c
> > @@ -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));
>
> 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.
>
My bad. Thank you for the feedback. I will be more extra careful next
time.
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-09-13 9:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-13 4:07 [PATCH] staging: most: move assignment out of function call Eva Rachel Retuya
2016-09-13 4:47 ` [Outreachy kernel] " Julia Lawall
2016-09-13 8:59 ` Eva Rachel Retuya
2016-09-13 6:05 ` Greg KH
2016-09-13 9:02 ` Eva Rachel Retuya
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.