From: Jonathan Cameron <jic23@kernel.org>
To: Varshini Rajendran <varshini.rajendran@microchip.com>
Cc: <ehristev@kernel.org>, <dlechner@baylibre.com>,
<nuno.sa@analog.com>, <andy@kernel.org>, <robh@kernel.org>,
<krzk+dt@kernel.org>, <conor+dt@kernel.org>,
<nicolas.ferre@microchip.com>, <alexandre.belloni@bootlin.com>,
<claudiu.beznea@tuxon.dev>, <srini@kernel.org>,
<marcelo.schmitt@analog.com>, <radu.sabau@analog.com>,
<Jonathan.Santos@analog.com>, <jorge.marques@analog.com>,
<joshua.crofts1@gmail.com>, <jishnu.prakash@oss.qualcomm.com>,
<antoniu.miclaus@analog.com>, <mazziesaccount@gmail.com>,
<linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>,
Andy Shevchenko <andriy.shevchenko@intel.com>
Subject: Re: [PATCH v4 02/16] iio: adc: at91-sama5d2_adc: use cleanup.h for NVMEM buffer
Date: Thu, 30 Jul 2026 00:24:16 +0100 [thread overview]
Message-ID: <20260730002416.261a6463@jic23-huawei> (raw)
In-Reply-To: <20260727122633.117435-3-varshini.rajendran@microchip.com>
On Mon, 27 Jul 2026 17:56:19 +0530
Varshini Rajendran <varshini.rajendran@microchip.com> wrote:
> Use __free(kfree) and __free(nvmem_cell_put) cleanup helpers in
> at91_adc_temp_sensor_init() to simplify error handling paths.
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Signed-off-by: Varshini Rajendran <varshini.rajendran@microchip.com>
A couple of questions inline
> ---
> drivers/iio/adc/at91-sama5d2_adc.c | 33 +++++++++++++-----------------
> 1 file changed, 14 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
> index e8a5285bb6d4..4a4a25f3c715 100644
> --- a/drivers/iio/adc/at91-sama5d2_adc.c
> +++ b/drivers/iio/adc/at91-sama5d2_adc.c
> @@ -35,6 +35,8 @@
>
> #include <dt-bindings/iio/adc/at91-sama5d2_adc.h>
>
> +DEFINE_FREE(nvmem_cell_put, struct nvmem_cell *, if (_T) nvmem_cell_put(_T))
I've lost track if it was previously discussed, but did you propose this for
more general useage in nvmem-consumer.h
The first randomly selected file I opened with nvmem_cell_put() could
make use of this so I assume it is generally useful?
> +
> struct at91_adc_reg_layout {
> /* Control Register */
> u16 CR;
> @@ -2249,33 +2251,28 @@ static int at91_adc_temp_sensor_init(struct at91_adc_state *st,
> struct device *dev)
> {
> struct at91_adc_temp_sensor_clb *clb = &st->soc_info.temp_sensor_clb;
> - struct nvmem_cell *temp_calib;
> - u32 *buf;
> size_t len;
> - int ret = 0;
>
> if (!st->soc_info.platform->temp_sensor)
> return 0;
>
> /* Get the calibration data from NVMEM. */
> - temp_calib = nvmem_cell_get(dev, "temperature_calib");
> + struct nvmem_cell *temp_calib __free(nvmem_cell_put) =
> + nvmem_cell_get(dev, "temperature_calib");
> if (IS_ERR(temp_calib)) {
> - ret = PTR_ERR(temp_calib);
Why this change? Just to avoid the need for ret?
I'd keep it and reduce the noise in the patch.
> - if (ret != -ENOENT)
> + if (PTR_ERR(temp_calib) != -ENOENT)
> dev_err(dev, "Failed to get temperature_calib cell!\n");
> - return ret;
> + return PTR_ERR(temp_calib);
> }
>
> - buf = nvmem_cell_read(temp_calib, &len);
> - nvmem_cell_put(temp_calib);
> - if (IS_ERR(buf)) {
> - dev_err(dev, "Failed to read calibration data!\n");
> - return PTR_ERR(buf);
> - }
> - if (len < AT91_ADC_TS_CLB_IDX_MAX * 4) {
> + u32 *buf __free(kfree) = nvmem_cell_read(temp_calib, &len);
> + if (IS_ERR(buf))
> + return dev_err_probe(dev, PTR_ERR(buf),
> + "Failed to read calibration data!\n");
> +
> + if (len < AT91_ADC_TS_CLB_IDX_MAX * sizeof(*buf)) {
> dev_err(dev, "Invalid calibration data!\n");
> - ret = -EINVAL;
> - goto free_buf;
> + return -EINVAL;
> }
>
> /* Store calibration data for later use. */
> @@ -2288,9 +2285,7 @@ static int at91_adc_temp_sensor_init(struct at91_adc_state *st,
> */
> clb->p1 = clb->p1 * 1000;
>
> -free_buf:
> - kfree(buf);
> - return ret;
> + return 0;
> }
>
> static int at91_adc_probe(struct platform_device *pdev)
next prev parent reply other threads:[~2026-07-29 23:24 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 12:26 [PATCH v4 00/16] Add thermal management support for sama7d65 Varshini Rajendran
2026-07-27 12:26 ` [PATCH v4 01/16] dt-bindings: iio: adc: at91-sama5d2: document sama7d65 Varshini Rajendran
2026-07-29 23:13 ` Jonathan Cameron
2026-07-27 12:26 ` [PATCH v4 02/16] iio: adc: at91-sama5d2_adc: use cleanup.h for NVMEM buffer Varshini Rajendran
2026-07-27 12:36 ` sashiko-bot
2026-07-29 23:24 ` Jonathan Cameron [this message]
2026-07-27 12:26 ` [PATCH v4 03/16] iio: adc: at91-sama5d2_adc: rework temp calibration layout handling Varshini Rajendran
2026-07-27 12:39 ` sashiko-bot
2026-08-03 6:08 ` Eugen Hristev
2026-07-27 12:26 ` [PATCH v4 04/16] iio: adc: at91-sama5d2_adc: add condition to validate calibration data Varshini Rajendran
2026-07-27 12:42 ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 05/16] iio: adc: at91-sama5d2_adc: remove unnecessary casts in of_device_id Varshini Rajendran
2026-08-03 6:04 ` Eugen Hristev
2026-07-27 12:26 ` [PATCH v4 06/16] iio: adc: at91-sama5d2_adc: adapt the driver for sama7d65 Varshini Rajendran
2026-07-27 12:41 ` sashiko-bot
2026-08-01 1:44 ` Jonathan Cameron
2026-07-27 12:26 ` [PATCH v4 07/16] dt-bindings: nvmem: microchip,sama7g5-otpc: add sama7d65 and dt node example Varshini Rajendran
2026-07-27 12:41 ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 08/16] nvmem: microchip-otpc: nvmem: microchip-otpc: add tag-based packet lookup Varshini Rajendran
2026-07-27 12:44 ` sashiko-bot
2026-08-07 1:04 ` Andy Shevchenko
2026-07-27 12:26 ` [PATCH v4 09/16] nvmem: microchip-otpc: nvmem: add emulation mode and OTP access validation Varshini Rajendran
2026-07-27 12:39 ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 10/16] ARM: dts: microchip: sama7d65: add cpu opps Varshini Rajendran
2026-07-27 12:26 ` [PATCH v4 11/16] ARM: dts: microchip: sama7d65: Add ADC node Varshini Rajendran
2026-07-27 12:26 ` [PATCH v4 12/16] ARM: dts: microchip: sama7d65_curiosity: Enable ADC, DVFS Varshini Rajendran
2026-07-27 12:26 ` [PATCH v4 13/16] ARM: dts: microchip: sama7d65: add otpc node Varshini Rajendran
2026-07-27 12:44 ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 14/16] ARM: dts: microchip: sama7d65: add cells for temperature calibration Varshini Rajendran
2026-07-27 12:50 ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 15/16] ARM: dts: microchip: sama7d65: add temperature sensor Varshini Rajendran
2026-07-27 12:45 ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 16/16] ARM: dts: microchip: sama7d65: add thermal zones node Varshini Rajendran
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=20260730002416.261a6463@jic23-huawei \
--to=jic23@kernel.org \
--cc=Jonathan.Santos@analog.com \
--cc=alexandre.belloni@bootlin.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=antoniu.miclaus@analog.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=ehristev@kernel.org \
--cc=jishnu.prakash@oss.qualcomm.com \
--cc=jorge.marques@analog.com \
--cc=joshua.crofts1@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt@analog.com \
--cc=mazziesaccount@gmail.com \
--cc=nicolas.ferre@microchip.com \
--cc=nuno.sa@analog.com \
--cc=radu.sabau@analog.com \
--cc=robh@kernel.org \
--cc=srini@kernel.org \
--cc=varshini.rajendran@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 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.