Re: [PATCH 4.19 28/37] dmaengine: dmatest: Fix iteration non-stop logic

From: Pavel Machek
Date: Tue May 05 2020 - 11:57:39 EST


On Tue 2020-05-05 11:32:27, Sasha Levin wrote:
> On Tue, May 05, 2020 at 05:05:37PM +0300, Andy Shevchenko wrote:
> > On Tue, May 5, 2020 at 4:37 PM Pavel Machek <pavel@xxxxxxx> wrote:
> > > On Tue 2020-05-05 16:19:11, Andy Shevchenko wrote:
> > > > On Tue, May 5, 2020 at 3:58 PM Pavel Machek <pavel@xxxxxxx> wrote:
> > > > > On Tue 2020-05-05 15:51:16, Andy Shevchenko wrote:
> > > > > > On Tue, May 5, 2020 at 3:37 PM Pavel Machek <pavel@xxxxxxx> wrote:
> > > > > Yeah, I pointed that out above. Both && and || permit short
> > > > > execution. But that does not matter, as neither "params->iterations"
> > > > > nor "total_tests >= params->iterations" have side effects.
> > > > >
> > > > > Where is the runtime difference?
> > > >
> > > > We have to check *both* conditions. If we don't check iterations, we
> > > > just wait indefinitely until somebody tells us to stop.
> > > > Everything in the commit message and mentioned there commit IDs which
> > > > you may check.
> > >
> > > No.
> >
> > Yes. Please, read carefully the commit message (for your convenience I
> > emphasized above). I don't want to spend time on this basics stuff
> > anymore.
>
> I'm a bit confused about this too. Maybe it's too early in the morning,
> so I wrote this little test program:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, char *argv[])
> {
> int a = atoi(argv[1]);
> int b = atoi(argv[2]);
>
> if (!a && !b)
> printf("A");
> else
> printf("B");
>
> if (!(a || b))
> printf("A");
> else
> printf("B");
>
> printf("\n");
>
> return 0;
> }
>
> Andy, could you give an example of two values which will print something
> other than "AA" or "BB"?

The issue here is "sideffects". Does b have to be evaluated at all?
There is no difference between

int a, b;
if (a && b)

and

if ((!!a) & (!!b))
.

But there would be difference between

int a, b;
if (a && b++)

and
if ((!!a) & (!!(b++)))

But:

1) && and || behave same way w.r.t. side effects

2) in the patch we are talking about b has no important side effects

Best regards,
Pavel
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

Attachment: signature.asc
Description: PGP signature