From: Oleksij Rempel <o.rempel@pengutronix.de>
To: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Cc: Dan Robertson <dan@dlrobertson.com>,
Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Nicolas Ferre <nicolas.ferre@microchip.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Claudiu Beznea <claudiu.beznea@tuxon.dev>,
kernel@pengutronix.de, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 5/6] iio: adc: ti-tsc2046: simplify with cleanup.h
Date: Sat, 6 Jul 2024 07:08:15 +0200 [thread overview]
Message-ID: <ZojRPxa0SWUvqGgC@pengutronix.de> (raw)
In-Reply-To: <20240705-cleanup-h-iio-v1-5-77114c7e84c5@linaro.org>
On Fri, Jul 05, 2024 at 12:40:48PM +0200, Krzysztof Kozlowski wrote:
> Allocate the memory with scoped/cleanup.h to reduce error handling and
> make the code a bit simpler.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>
Thank you!
> ---
> drivers/iio/adc/ti-tsc2046.c | 29 ++++++++++++-----------------
> 1 file changed, 12 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/iio/adc/ti-tsc2046.c b/drivers/iio/adc/ti-tsc2046.c
> index edcef8f11522..24b1d4390872 100644
> --- a/drivers/iio/adc/ti-tsc2046.c
> +++ b/drivers/iio/adc/ti-tsc2046.c
> @@ -6,6 +6,7 @@
> */
>
> #include <linux/bitfield.h>
> +#include <linux/cleanup.h>
> #include <linux/delay.h>
> #include <linux/module.h>
> #include <linux/regulator/consumer.h>
> @@ -273,7 +274,6 @@ static int tsc2046_adc_read_one(struct tsc2046_adc_priv *priv, int ch_idx,
> u32 *effective_speed_hz)
> {
> struct tsc2046_adc_ch_cfg *ch = &priv->ch_cfg[ch_idx];
> - struct tsc2046_adc_atom *rx_buf, *tx_buf;
> unsigned int val, val_normalized = 0;
> int ret, i, count_skip = 0, max_count;
> struct spi_transfer xfer;
> @@ -287,18 +287,20 @@ static int tsc2046_adc_read_one(struct tsc2046_adc_priv *priv, int ch_idx,
> max_count = 1;
> }
>
> - if (sizeof(*tx_buf) * max_count > PAGE_SIZE)
> + if (sizeof(struct tsc2046_adc_atom) * max_count > PAGE_SIZE)
> return -ENOSPC;
>
> - tx_buf = kcalloc(max_count, sizeof(*tx_buf), GFP_KERNEL);
> + struct tsc2046_adc_atom *tx_buf __free(kfree) = kcalloc(max_count,
> + sizeof(*tx_buf),
> + GFP_KERNEL);
> if (!tx_buf)
> return -ENOMEM;
>
> - rx_buf = kcalloc(max_count, sizeof(*rx_buf), GFP_KERNEL);
> - if (!rx_buf) {
> - ret = -ENOMEM;
> - goto free_tx;
> - }
> + struct tsc2046_adc_atom *rx_buf __free(kfree) = kcalloc(max_count,
> + sizeof(*rx_buf),
> + GFP_KERNEL);
> + if (!rx_buf)
> + return -ENOMEM;
>
> /*
> * Do not enable automatic power down on working samples. Otherwise the
> @@ -326,7 +328,7 @@ static int tsc2046_adc_read_one(struct tsc2046_adc_priv *priv, int ch_idx,
> if (ret) {
> dev_err_ratelimited(&priv->spi->dev, "SPI transfer failed %pe\n",
> ERR_PTR(ret));
> - goto free_bufs;
> + return ret;
> }
>
> if (effective_speed_hz)
> @@ -337,14 +339,7 @@ static int tsc2046_adc_read_one(struct tsc2046_adc_priv *priv, int ch_idx,
> val_normalized += val;
> }
>
> - ret = DIV_ROUND_UP(val_normalized, max_count - count_skip);
> -
> -free_bufs:
> - kfree(rx_buf);
> -free_tx:
> - kfree(tx_buf);
> -
> - return ret;
> + return DIV_ROUND_UP(val_normalized, max_count - count_skip);
> }
>
> static size_t tsc2046_adc_group_set_layout(struct tsc2046_adc_priv *priv,
>
> --
> 2.43.0
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2024-07-06 5:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-05 10:40 [PATCH 0/6] iio: adc: simplify with cleanup.h Krzysztof Kozlowski
2024-07-05 10:40 ` [PATCH 1/6] iio: accel: bma400: " Krzysztof Kozlowski
2024-07-05 10:40 ` [PATCH 2/6] iio: adc: ad7280a: " Krzysztof Kozlowski
2024-07-05 11:43 ` Nuno Sá
2024-07-05 10:40 ` [PATCH 3/6] iio: adc: at91: " Krzysztof Kozlowski
2024-07-05 10:40 ` [PATCH 4/6] iio: adc: max1363: " Krzysztof Kozlowski
2024-07-05 11:45 ` Nuno Sá
2024-07-05 10:40 ` [PATCH 5/6] iio: adc: ti-tsc2046: " Krzysztof Kozlowski
2024-07-06 5:08 ` Oleksij Rempel [this message]
2024-07-05 10:40 ` [PATCH 6/6] iio: adc: ad5755: drop redundant devm_kfree() Krzysztof Kozlowski
2024-07-05 11:47 ` Nuno Sá
2024-07-06 10:52 ` Jonathan Cameron
2024-07-07 11:34 ` Krzysztof Kozlowski
2024-07-06 10:55 ` [PATCH 0/6] iio: adc: simplify with cleanup.h Jonathan Cameron
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=ZojRPxa0SWUvqGgC@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=Michael.Hennerich@analog.com \
--cc=alexandre.belloni@bootlin.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=dan@dlrobertson.com \
--cc=jic23@kernel.org \
--cc=kernel@pengutronix.de \
--cc=krzysztof.kozlowski@linaro.org \
--cc=lars@metafoo.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.ferre@microchip.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;
as well as URLs for NNTP newsgroup(s).