lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CABXOdTfJ6x5ePkmj+w21jTX7EOTXZrCd8PwikAJQTfeQmUBxaQ@mail.gmail.com>
Date:   Thu, 14 Jul 2022 07:29:45 -0700
From:   Guenter Roeck <groeck@...gle.com>
To:     Tzung-Bi Shih <tzungbi@...nel.org>
Cc:     Benson Leung <bleung@...omium.org>,
        Guenter Roeck <groeck@...omium.org>,
        "open list:CHROME HARDWARE PLATFORM SUPPORT" 
        <chrome-platform@...ts.linux.dev>,
        linux-kernel <linux-kernel@...r.kernel.org>
Subject: Re: [RESEND PATCH 05/11] platform/chrome: cros_ec_proto: separate cros_ec_wait_until_complete()

On Wed, Jul 13, 2022 at 8:33 PM Tzung-Bi Shih <tzungbi@...nel.org> wrote:
>
> On Wed, Jul 13, 2022 at 11:15:47AM -0700, Guenter Roeck wrote:
> > On Mon, Jun 27, 2022 at 7:49 PM Tzung-Bi Shih <tzungbi@...nel.org> wrote:
> > > -static int cros_ec_send_command(struct cros_ec_device *ec_dev, struct cros_ec_command *msg)
> > > +static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev, uint32_t *result)
> > >  {
> > > -       int ret = cros_ec_xfer_command(ec_dev, msg);
> > > +       struct cros_ec_command *msg;
> > > +       struct ec_response_get_comms_status *status;
> > > +       int ret = 0, i;
> > > +
> > > +       msg = kzalloc(sizeof(*msg) + sizeof(*status), GFP_KERNEL);
> > > +       if (!msg)
> > > +               return -ENOMEM;
> >
> > AFAICS this is always 24 bytes. I would suggest to allocate it on the
> > stack to reduce overhead.
>
> Ack.
>
> > > +               ret = cros_ec_xfer_command(ec_dev, msg);
> > > +               if (ret == -EAGAIN)
> > > +                       continue;
> > > +               if (ret < 0)
> > > +                       break;
> >
> > With the command allocated on the stack, this can return immediately.
>
> Nack, the function has no goto labels.  `return ret` follows the loop
> immediately.  The `break` here doesn't make it to become too complicated.
> I would prefer to keep it.

Sorry, you lost me here. The code after the loop does

           kfree(msg);
           return ret;

If kfree() is no longer necessary, only the return statement is left. So break;
is identical to return ret;. Am I missing something ?

>
> > > +
> > > +               *result = msg->result;
> > > +               if (msg->result != EC_RES_SUCCESS)
> > > +                       break;
> >
> > Again, this can return immediately if the command buffer is on the stack.
>
> Nack.  See above.
>
> > > -               kfree(status_msg);
> > > +               if (!(status->flags & EC_COMMS_STATUS_PROCESSING))
> > > +                       break;
> >
> > Can return immediately.
>
> Nack.  See above.
>

Really, for those I think that
                   return 0;
would be better and more explicit.

> > > +       kfree(msg);
> > > +       return ret;
> >
> > What should this return on timeout ?
>
> It returns either:
> * -EAGAIN, if cros_ec_xfer_command() returned -EAGAIN
> * 0, if EC_COMMS_STATUS_PROCESSING flag was on
> for EC_COMMAND_RETRIES times so far.
>
> This is a "move" refactor.  I would prefer to keep it as is and change the
> behavior in later patch.

Ok.

Thanks,
Guenter

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ