From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Angel Iglesias <ang.iglesiasg@gmail.com>
Cc: linux-iio@vger.kernel.org,
"Biju Das" <biju.das.jz@bp.renesas.com>,
linux-kernel@vger.kernel.org,
"Jonathan Cameron" <jic23@kernel.org>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Subject: Re: [PATCH 4/5] iio: pressure: bmp280: Allow multiple chips id per family of devices
Date: Mon, 16 Oct 2023 10:53:38 +0300 [thread overview]
Message-ID: <ZSzsAnE38p7zwM2+@smile.fi.intel.com> (raw)
In-Reply-To: <9f8489d82325b2dfb5c8c71c3d558d509b2b01bf.1697381932.git.ang.iglesiasg@gmail.com>
On Sun, Oct 15, 2023 at 05:16:26PM +0200, Angel Iglesias wrote:
> Improve device detection in certain chip families known to have various
> chip ids.
...
> +#include <linux/overflow.h>
Probably you don't need this, see below.
...
> ret = regmap_read(regmap, data->chip_info->id_reg, &chip_id);
> if (ret < 0)
> return ret;
> + 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(data->chip_info->num_chip_id, 5, &nbuf))
> + return ret;
First of all, it _implicitly_ returns 0 here...
> + buf = kmalloc_array(data->chip_info->num_chip_id, 5, GFP_KERNEL);
> + if (!buf)
> + return ret;
...and here.
Second, kmalloc_array() has that check inside.
Third, define this magic 5 either as strlen(), or a constant (in latter case
with the comment of its meaning).
> + for (i = 0; i < data->chip_info->num_chip_id; i++)
> + snprintf(&buf[i*5], nbuf - i*5, "0x%x ", data->chip_info->chip_id[i]);
Fourth, use incremental position, i.e. use retuned value from snprintf().
> + dev_err(dev, "bad chip id: expected one of [ %s ] got 0x%x\n", buf, chip_id);
> + kfree(buf);
> + return ret;
As per "first" and "second" above.
> }
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2023-10-16 7:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-15 15:16 [PATCH 0/5] Add support for BMP390 and various driver cleanups Angel Iglesias
2023-10-15 15:16 ` [PATCH 1/5] iio: pressure: bmp280: Use i2c_get_match_data() Angel Iglesias
2023-10-15 15:16 ` [PATCH 2/5] iio: pressure: bmp280: Use spi_get_device_match_data() Angel Iglesias
2023-10-15 15:16 ` [PATCH 3/5] iio: pressure: bmp280: Rearrange vars in reverse xmas tree order Angel Iglesias
2023-10-16 8:40 ` Jonathan Cameron
2023-10-15 15:16 ` [PATCH 4/5] iio: pressure: bmp280: Allow multiple chips id per family of devices Angel Iglesias
2023-10-16 7:53 ` Andy Shevchenko [this message]
2023-10-16 8:38 ` Jonathan Cameron
2023-10-15 15:16 ` [PATCH 5/5] iio: pressure: bmp280: Add support for BMP390 Angel Iglesias
2023-10-16 7:54 ` [PATCH 0/5] Add support for BMP390 and various driver cleanups 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=ZSzsAnE38p7zwM2+@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=ang.iglesiasg@gmail.com \
--cc=biju.das.jz@bp.renesas.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox