All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>
Subject: Re: [PATCH v1 3/8] iio: core: Switch to krealloc_array()
Date: Fri, 21 Jul 2023 12:53:53 +0200	[thread overview]
Message-ID: <f565b705ba6656ae1c8b34740aa176ccfe260f60.camel@gmail.com> (raw)
In-Reply-To: <ZLpaeHlJujd8l0DS@smile.fi.intel.com>

On Fri, 2023-07-21 at 13:14 +0300, Andy Shevchenko wrote:
> On Fri, Jul 21, 2023 at 09:59:37AM +0200, Nuno Sá wrote:
> > On Thu, 2023-07-20 at 23:53 +0300, Andy Shevchenko wrote:
> 
> ...
> 
> > > +       struct attribute **attrs, **attr, *clk = NULL;
> > >         struct iio_dev_attr *p;
> > > -       struct attribute **attr, *clk = NULL;
> > >  
> > >         /* First count elements in any existing group */
> > > -       if (indio_dev->info->attrs) {
> > > -               attr = indio_dev->info->attrs->attrs;
> > > -               while (*attr++ != NULL)
> > > +       attrs = indio_dev->info->attrs ? indio_dev->info->attrs->attrs :
> > > NULL;
> > > +       if (attrs) {
> > > +               for (attr = attrs; *attr; attr++)
> > >                         attrcount_orig++;
> 
> > not really related with the change... maybe just mention it in the commit?
> 
> Hmm... It's related to make krealloc_array() to work as expected.
> 

Hmm, I think it's arguable :). while() -> for() it's not really needed unless
I'm missing something. You could even initialize 'attrs' to NULL at declaration
and keep the above diff minimum.

That said, I actually prefer this style (even though some people don't like much
the ternary operator).

> > >         }
> 
> ...
> 
> > >         iio_dev_opaque->chan_attr_group.attrs =
> > > -               kcalloc(attrcount + 1,
> > > -                       sizeof(iio_dev_opaque->chan_attr_group.attrs[0]),
> > > -                       GFP_KERNEL);
> > > +               krealloc_array(attrs, attrcount + 1, sizeof(*attrs),
> > > GFP_KERNEL);
> > >         if (iio_dev_opaque->chan_attr_group.attrs == NULL) {
> > 
> > since you're here and you also already did some style cleanups above, maybe
> > change it to 'if (!iio_dev_opaque->chan_attr_group.attrs)'?
> 
> I don't think it's related (but you can tell that this check related to
> the allocator, and since we touch it, we may touch this), if Jonathan
> wants this, I definitely do.

Fair enough...


- Nuno Sá

  reply	other threads:[~2023-07-21 10:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-20 20:53 [PATCH v1 0/8] iio: core: A few code cleanups and documentation fixes Andy Shevchenko
2023-07-20 20:53 ` [PATCH v1 1/8] iio: core: Add opaque_struct_size() helper and use it Andy Shevchenko
2023-07-20 20:53 ` [PATCH v1 2/8] iio: core: Use sysfs_match_string() helper Andy Shevchenko
2023-07-21  8:03   ` Nuno Sá
2023-07-20 20:53 ` [PATCH v1 3/8] iio: core: Switch to krealloc_array() Andy Shevchenko
2023-07-21  7:59   ` Nuno Sá
2023-07-21 10:14     ` Andy Shevchenko
2023-07-21 10:53       ` Nuno Sá [this message]
2023-07-21 11:28         ` Andy Shevchenko
2023-07-21 11:31           ` Andy Shevchenko
2023-07-20 20:53 ` [PATCH v1 4/8] iio: core: Use min() instead of min_t() to make code more robust Andy Shevchenko
2023-07-20 20:53 ` [PATCH v1 5/8] iio: core: Get rid of redundant 'else' Andy Shevchenko
2023-07-20 20:53 ` [PATCH v1 6/8] iio: core: Fix issues and style of the comments Andy Shevchenko
2023-07-20 20:53 ` [PATCH v1 7/8] iio: core: Move initcalls closer to the respective calls Andy Shevchenko
2023-07-20 20:53 ` [PATCH v1 8/8] iio: core: Improve indentation in a few places Andy Shevchenko
2023-07-21  8:06 ` [PATCH v1 0/8] iio: core: A few code cleanups and documentation fixes Nuno Sá
2023-07-21 10:15   ` Andy Shevchenko
2023-07-21 16:55   ` Andy Shevchenko
2023-07-21 16:57     ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f565b705ba6656ae1c8b34740aa176ccfe260f60.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.