[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4db5d44854c9af1b7ec8a70b28f03d8488628868.1731495937.git.mazziesaccount@gmail.com>
Date: Wed, 13 Nov 2024 13:19:41 +0200
From: Matti Vaittinen <mazziesaccount@...il.com>
To: Matti Vaittinen <mazziesaccount@...il.com>,
Matti Vaittinen <matti.vaittinen@...rohmeurope.com>
Cc: Jonathan Cameron <jic23@...nel.org>,
Lars-Peter Clausen <lars@...afoo.de>, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>,
Matti Vaittinen <mazziesaccount@...il.com>,
linux-iio@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH 1/5] iio: gts: Simplify using __free
The error path in the gain_to_scaletables() uses goto for unwinding an
allocation on failure. This can be slightly simplified by using the
automated free when exiting the scope.
Use __free(kfree) and drop the goto based error handling.
Signed-off-by: Matti Vaittinen <mazziesaccount@...il.com>
---
drivers/iio/industrialio-gts-helper.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c
index 5f131bc1a01e..85b43441b5d1 100644
--- a/drivers/iio/industrialio-gts-helper.c
+++ b/drivers/iio/industrialio-gts-helper.c
@@ -4,6 +4,7 @@
* Copyright (c) 2023 Matti Vaittinen <mazziesaccount@...il.com>
*/
+#include <linux/cleanup.h>
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/export.h>
@@ -168,7 +169,7 @@ static int iio_gts_gain_cmp(const void *a, const void *b)
static int gain_to_scaletables(struct iio_gts *gts, int **gains, int **scales)
{
int ret, i, j, new_idx, time_idx;
- int *all_gains;
+ int *all_gains __free(kfree) = NULL;
size_t gain_bytes;
for (i = 0; i < gts->num_itime; i++) {
@@ -232,10 +233,9 @@ static int gain_to_scaletables(struct iio_gts *gts, int **gains, int **scales)
gts->avail_all_scales_table = kcalloc(new_idx, 2 * sizeof(int),
GFP_KERNEL);
- if (!gts->avail_all_scales_table) {
- ret = -ENOMEM;
- goto free_out;
- }
+ if (!gts->avail_all_scales_table)
+ return -ENOMEM;
+
gts->num_avail_all_scales = new_idx;
for (i = 0; i < gts->num_avail_all_scales; i++) {
@@ -246,14 +246,11 @@ static int gain_to_scaletables(struct iio_gts *gts, int **gains, int **scales)
if (ret) {
kfree(gts->avail_all_scales_table);
gts->num_avail_all_scales = 0;
- goto free_out;
+ return ret;
}
}
-free_out:
- kfree(all_gains);
-
- return ret;
+ return 0;
}
/**
--
2.47.0
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists