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: <YqAGqZgauTnn76KD@google.com>
Date:   Wed, 8 Jun 2022 02:17:13 +0000
From:   Tzung-Bi Shih <tzungbi@...nel.org>
To:     Guenter Roeck <groeck@...gle.com>
Cc:     bleung@...omium.org, groeck@...omium.org,
        chrome-platform@...ts.linux.dev, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 12/15] platform/chrome: use krealloc() for `din` and
 `dout`

On Tue, Jun 07, 2022 at 12:06:23PM -0700, Guenter Roeck wrote:
> On Tue, Jun 7, 2022 at 7:57 AM Tzung-Bi Shih <tzungbi@...nel.org> wrote:
> >
> > Use krealloc() to re-allocate `din` and `dout`.  Don't use devm variant
> > because the two buffers could be re-allocated multiple times during
> > runtime.  Their life cycles aren't quite aligned to the device's.
> 
> While this saves a few lines of code, it is runtime-expensive:
> krealloc() copies the old data, which is a waste of time/resources.
> Maybe it would be better to just use kfree() followed by kzalloc().

Ack.  I wasn't aware of the memcpy().  Let's don't use it.

> > @@ -469,9 +469,9 @@ static int cros_ec_get_host_command_version_mask(struct cros_ec_device *ec_dev,
> >   */
> >  int cros_ec_query_all(struct cros_ec_device *ec_dev)
> >  {
> > -       struct device *dev = ec_dev->dev;
> >         u32 ver_mask = 0;
> >         int ret;
> > +       u8 *din, *dout;
> >
> >         /* First try sending with proto v3. */
> >         if (!cros_ec_get_proto_info(ec_dev, CROS_EC_DEV_EC_INDEX)) {
> > @@ -492,21 +492,15 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev)
> >                 }
> >         }
> >
> > -       devm_kfree(dev, ec_dev->din);
> > -       devm_kfree(dev, ec_dev->dout);
> > -
> > -       ec_dev->din = devm_kzalloc(dev, ec_dev->din_size, GFP_KERNEL);
> > -       if (!ec_dev->din) {
> > -               ret = -ENOMEM;
> > -               goto exit;
> > -       }
> > +       din = krealloc(ec_dev->din, ec_dev->din_size, GFP_KERNEL);
> > +       if (!din)
> > +               return -ENOMEM;
> 
> I would suggest assigning the values directly; the new variables don't
> really add value.

checkpatch.pl generated a warning for it.  See [1].

Will remove the krealloc()s anyway.

[1]: https://github.com/torvalds/linux/commit/972fdea2e6ece7578915d386a5447bc78d3fb8b8

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ