lkml.org 
[lkml]   [2022]   [Jun]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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@kernel.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

\
 
 \ /
  Last update: 2022-06-08 07:23    [W:0.107 / U:0.460 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site