[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VdnYbJRaYLCC2T1HAkexhExW6Br4r68R5C+_v7K7TD-6A@mail.gmail.com>
Date: Thu, 11 Feb 2016 10:13:11 +0200
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Oliver Neukum <oneukum@...e.de>
Cc: Felipe Balbi <balbi@...nel.org>,
Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
Mathias Nyman <mathias.nyman@...ux.intel.com>,
Greg KH <gregkh@...uxfoundation.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
USB <linux-usb@...r.kernel.org>
Subject: Fwd: [PATCH 2/3] usb: type-c: USB Type-C Connector System Software Interface
---------- Forwarded message ----------
From: Andy Shevchenko <andy.shevchenko@...il.com>
Date: Thu, Feb 11, 2016 at 10:10 AM
Subject: Re: [PATCH 2/3] usb: type-c: USB Type-C Connector System
Software Interface
To: Oliver Neukum <oneukum@...e.de>
On Wed, Feb 10, 2016 at 5:08 PM, Oliver Neukum <oneukum@...e.de> wrote:
> On Wed, 2016-02-10 at 16:24 +0200, Andy Shevchenko wrote:
>> On Wed, Feb 10, 2016 at 4:15 PM, Oliver Neukum <oneukum@...e.com> wrote:
>> > On Wed, 2016-02-10 at 13:56 +0200, Andy Shevchenko wrote:
>> >> > +err:
>> >> > + if (i > 0)
>> >> > + for (; i >= 0; i--, con--)
>> >> > + typec_unregister_port(con->port);
>> >>
>> >> Perhaps
>> >>
>> >> while (--i >= 0) {
>> >> ...
>> >> }
>> >
>> > While we are at it. No we should not change the semantics
>> > of conditionals for the sake of appearance.
>>
>> I'm sorry I didn't get you.
>> How this more or less standard pattern to clean up stuff on error path
>> does with conditional semantics?
>
> You change a postdecrement to a predecrement. The highest
> number the loop is executed for is changed.
I still didn't get.
Variable i is just counter here,
And it seems there is a bug, since when i == 1, we will have
i = 1, con == connector[0]:
typec_unregister_port(con->port);
i = 0, con == connector[1]:
typec_unregister_port(con->port); <<< It wasn't registered yet!
The correct code should be something like
if (i > 0)
for (--i; i >= 0; i--) {}
Which
a) makes conditional redundant;
b) classical pattern of while (--i >= 0) {}
So where am I wrong?
--
With Best Regards,
Andy Shevchenko
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists