From: Angel Iglesias <ang.iglesiasg@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 v2 2/3] iio: pressure: bmp280: Allow multiple chips id per family of devices
Date: Fri, 25 Aug 2023 11:30:28 +0200 [thread overview]
Message-ID: <e3a73cfff0e91e22859ebdd671067ac06cfd9adf.camel@gmail.com> (raw)
In-Reply-To: <ZOYzIvrvZGjQldDe@smile.fi.intel.com>
On Wed, 2023-08-23 at 19:26 +0300, Andy Shevchenko wrote:
> On Wed, Aug 23, 2023 at 05:58:06PM +0200, Angel Iglesias wrote:
> > Improve device detection in certain chip families known to have various
> > chip ids.
>
> IDs
>
> ...
>
> > #include <linux/completion.h>
> > #include <linux/pm_runtime.h>
> > #include <linux/random.h>
> > +#include <linux/overflow.h>
>
> Please, preserve ordering.
>
> ...
>
> > struct bmp280_data *data;
> > struct gpio_desc *gpiod;
> > unsigned int chip_id;
> > - int ret;
> > + int ret, i;
>
> unsigned int i;
>
> ...
>
> > + if (i == data->chip_info->num_chip_id) {
> > + size_t nbuf;
> > + char *buf;
> > +
> > + // 0x<id>, so four chars per number plus one space + ENDL
>
> > + if (check_mul_overflow(5, data->chip_info->num_chip_id,
> > &nbuf))
> > + return ret;
> > +
> > + buf = kmalloc_array(nbuf, sizeof(char), GFP_KERNEL);
>
> We almost never do a array allocation for byte sizes. Instead of the above you
> need to use
>
> buf = kmalloc_array(data->chip_info->num_chip_id, 5,
> GFP_KERNEL);
>
> > + if (!buf)
>
> This check assumes that num_chip_id is never 0, so...
>
> > + return ret;
> > +
> > + for (i = 0; i < data->chip_info->num_chip_id; i++)
> > + snprintf(&buf[i*5], nbuf, "0x%x ", data->chip_info-
> > >chip_id[i]);
>
> > + buf[nbuf-1] = '\0';
>
> ...this is redundant assignment. sprintf() guarantees the NUL termination.
>
> > +
> > + dev_err(dev, "bad chip id: expected [ %s ] got 0x%x\n", buf,
> > chip_id);
>
> "...expected one of..."
>
> > + kfree(buf);
> > + return ret;
>
> Oh, I didn't get that you allocated memory only to print a message...
Yes, I just wanted to print the known IDs like before in a readable manner. If
it is overkill, I'll change it for a more generic error message.
>
> > }
>
Kind regards,
Angel
next prev parent reply other threads:[~2023-08-25 9:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-23 15:58 [PATCH v2 0/3] iio: pressure: bmp280: Add support for BMP390 Angel Iglesias
2023-08-23 15:58 ` [PATCH v2 1/3] iio: pressure: bmp280: Use uint8 to store chip ids Angel Iglesias
2023-08-23 16:10 ` Andy Shevchenko
2023-08-23 16:17 ` Andy Shevchenko
2023-08-25 9:28 ` Angel Iglesias
2023-08-23 15:58 ` [PATCH v2 2/3] iio: pressure: bmp280: Allow multiple chips id per family of devices Angel Iglesias
2023-08-23 16:26 ` Andy Shevchenko
2023-08-25 9:30 ` Angel Iglesias [this message]
2023-08-23 15:58 ` [PATCH v2 3/3] iio: pressure: bmp280: Add support for BMP390 Angel Iglesias
2023-08-23 16:27 ` 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=e3a73cfff0e91e22859ebdd671067ac06cfd9adf.camel@gmail.com \
--to=ang.iglesiasg@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.