From: Michal Simek <michal.simek@amd.com>
To: James Clark <james.clark@arm.com>, linux-kernel@vger.kernel.org
Cc: Jonathan Corbet <corbet@lwn.net>,
Guenter Roeck <linux@roeck-us.net>,
Jean Delvare <jdelvare@suse.com>,
Anand Ashok Dumbre <anand.ashok.dumbre@xilinx.com>,
Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Michal Simek <michal.simek@xilinx.com>,
Andy Gross <agross@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konrad.dybcio@linaro.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>,
linux-doc@vger.kernel.org, linux-hwmon@vger.kernel.org,
linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org
Subject: Re: [PATCH 3/4] iio: adc: Use devm_krealloc_array
Date: Wed, 8 Mar 2023 12:58:46 +0100 [thread overview]
Message-ID: <a5bb0516-9a21-5d46-d557-f02893ac8bf4@amd.com> (raw)
In-Reply-To: <20230306152723.3090195-4-james.clark@arm.com>
On 3/6/23 16:27, James Clark wrote:
>
> Now that it exists, use it instead of doing the multiplication and
> checking for overflow manually.
>
> Signed-off-by: James Clark <james.clark@arm.com>
> ---
> drivers/iio/adc/xilinx-ams.c | 9 +++------
> drivers/iio/adc/xilinx-xadc-core.c | 17 +++++++----------
> 2 files changed, 10 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/iio/adc/xilinx-ams.c b/drivers/iio/adc/xilinx-ams.c
> index 34cf336b3490..f0b71a1220e0 100644
> --- a/drivers/iio/adc/xilinx-ams.c
> +++ b/drivers/iio/adc/xilinx-ams.c
> @@ -1263,7 +1263,7 @@ static int ams_parse_firmware(struct iio_dev *indio_dev)
> struct device *dev = indio_dev->dev.parent;
> struct fwnode_handle *child = NULL;
> struct fwnode_handle *fwnode = dev_fwnode(dev);
> - size_t ams_size, dev_size;
> + size_t ams_size;
> int ret, ch_cnt = 0, i, rising_off, falling_off;
> unsigned int num_channels = 0;
>
> @@ -1320,11 +1320,8 @@ static int ams_parse_firmware(struct iio_dev *indio_dev)
> }
> }
>
> - dev_size = array_size(sizeof(*dev_channels), num_channels);
> - if (dev_size == SIZE_MAX)
> - return -ENOMEM;
> -
> - dev_channels = devm_krealloc(dev, ams_channels, dev_size, GFP_KERNEL);
> + dev_channels = devm_krealloc_array(dev, ams_channels, num_channels,
> + sizeof(*dev_channels), GFP_KERNEL);
> if (!dev_channels)
> return -ENOMEM;
>
> diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c
> index 292f2892d223..287df3bb951e 100644
> --- a/drivers/iio/adc/xilinx-xadc-core.c
> +++ b/drivers/iio/adc/xilinx-xadc-core.c
> @@ -613,20 +613,17 @@ static int xadc_update_scan_mode(struct iio_dev *indio_dev,
> const unsigned long *mask)
> {
> struct xadc *xadc = iio_priv(indio_dev);
> - size_t new_size, n;
> + size_t n;
> void *data;
>
> n = bitmap_weight(mask, indio_dev->masklength);
>
> - if (check_mul_overflow(n, sizeof(*xadc->data), &new_size))
> - return -ENOMEM;
> -
> - data = devm_krealloc(indio_dev->dev.parent, xadc->data,
> - new_size, GFP_KERNEL);
> + data = devm_krealloc_array(indio_dev->dev.parent, xadc->data,
> + n, sizeof(*xadc->data), GFP_KERNEL);
> if (!data)
> return -ENOMEM;
>
> - memset(data, 0, new_size);
> + memset(data, 0, n*sizeof(*xadc->data));
this is not correct coding style.
M
next prev parent reply other threads:[~2023-03-08 11:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-06 15:27 [PATCH 0/4] devres: Provide krealloc_array James Clark
2023-03-06 15:27 ` [PATCH 1/4] " James Clark
2023-03-06 15:27 ` [PATCH 2/4] hwmon: pmbus: Use devm_krealloc_array James Clark
2023-03-06 15:30 ` Guenter Roeck
2023-03-06 15:27 ` [PATCH 3/4] iio: adc: " James Clark
2023-03-08 11:58 ` Michal Simek [this message]
2023-03-09 15:04 ` James Clark
2023-03-06 15:27 ` [PATCH 4/4] serial: qcom_geni: " James Clark
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=a5bb0516-9a21-5d46-d557-f02893ac8bf4@amd.com \
--to=michal.simek@amd.com \
--cc=agross@kernel.org \
--cc=anand.ashok.dumbre@xilinx.com \
--cc=andersson@kernel.org \
--cc=corbet@lwn.net \
--cc=gregkh@linuxfoundation.org \
--cc=james.clark@arm.com \
--cc=jdelvare@suse.com \
--cc=jic23@kernel.org \
--cc=jirislaby@kernel.org \
--cc=konrad.dybcio@linaro.org \
--cc=lars@metafoo.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=michal.simek@xilinx.com \
/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