From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 77209C2BD09 for ; Sat, 6 Jul 2024 05:09:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To :Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=rPWdxEVy01XbEmQzwFDU/75IZUWA5mBvB3v234ZS1cg=; b=IDROxYfryqfciUl3ktm/xbaiUn F9kHkqIJk3O7sDE4LDVAkmz+sYcvoKB/e6HpPNie1oLmkmC1Rrv19UU3SeVinqXBppL7fqDf3zpHU adCwxE9P7E1yG7reUHzNpTEpf6QuiLKsL00X9WVaN9wl8qqv23Qqx0fI314ox9E5ugEEIkzAB5hhz iu1VnZ6tim3sxjr81Hz7+yXd1Y79ihqKmKgT3m31BJYEh+GJOWbZ4KRTuh5RI4CsMCVdjmVxj5gsN rViebR6w8NapaBLODFa2coBTFUkVjyKW0Qk4B+vQyHMy7ctxPvU4JcrFR+lVd+lqu/A0MK+jzyeiI q6BM3Mog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPxfL-0000000HLIQ-0WBm; Sat, 06 Jul 2024 05:08:55 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPxf6-0000000HLF7-17oN for linux-arm-kernel@lists.infradead.org; Sat, 06 Jul 2024 05:08:42 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sPxek-0001bt-VF; Sat, 06 Jul 2024 07:08:18 +0200 Received: from [2a0a:edc0:2:b01:1d::c5] (helo=pty.whiteo.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sPxeh-007V4g-TI; Sat, 06 Jul 2024 07:08:15 +0200 Received: from ore by pty.whiteo.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1sPxeh-000hrD-2b; Sat, 06 Jul 2024 07:08:15 +0200 Date: Sat, 6 Jul 2024 07:08:15 +0200 From: Oleksij Rempel To: Krzysztof Kozlowski Subject: Re: [PATCH 5/6] iio: adc: ti-tsc2046: simplify with cleanup.h Message-ID: References: <20240705-cleanup-h-iio-v1-0-77114c7e84c5@linaro.org> <20240705-cleanup-h-iio-v1-5-77114c7e84c5@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240705-cleanup-h-iio-v1-5-77114c7e84c5@linaro.org> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240705_220840_328536_1E188DA9 X-CRM114-Status: GOOD ( 24.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Dan Robertson , Michael Hennerich , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Claudiu Beznea , Lars-Peter Clausen , linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de, Jonathan Cameron Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 Reviewed-by: Oleksij Rempel 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 > +#include > #include > #include > #include > @@ -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 |