From patchwork Thu Nov 21 08:20:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13881745 Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9755512FB1B; Thu, 21 Nov 2024 08:20:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732177218; cv=none; b=OU5JGo5IDmzAAxcEa/X9ghhEFhJ2JcIfBMZhsH5BafJck84V77c0ifUWixsHJHkLYyqi/K0T+Bx9gobzR5wG8nj9kBhUTyQxx9ZOE05nVJJKw0vDoLgEq/31Cw3tdRaldreW/A3/Ap5xcfT9R/RH3E8UKTlGPYxLKTLgoBiC1vw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732177218; c=relaxed/simple; bh=7Rt42u/XCjYpglpy1boRCDwPVpqgQFmGqiV2rb0uP6Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ho/ucXURCugH8FdgPLzl/7/rek6G5/BXAmjj5XTiYnHng5o0VG5RaOswcXeXGYwD0vKxMtu7unPXGDGniEHBT1U657eDVEurS/y++5Q8tjghmpGDkys6jtUyWpoiWy7dIki1dYIkIlEs8Lr4LrdtgcQzOuVmxLd5fgUlEHAMpaI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hMn8/S+T; arc=none smtp.client-ip=209.85.208.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hMn8/S+T" Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2fb561f273eso6545201fa.2; Thu, 21 Nov 2024 00:20:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732177215; x=1732782015; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=lmhBGQ/m+qVWheJtFzpyd5mx+oTRXoNs7skerrQrF0g=; b=hMn8/S+TZQm9Eg9CYjyQ3yEAZHMoc0td6eVgn09fueJljMj2+tolJ9ZtiNbJihw4Hb nOPGdIc7DauUD/m+2orxSTLSrgrLAyqfSdB3soggJuvV+yG0sHZT/7UYXtuAEaKPmsIW xOhg10T4kRXq2AH4x4n3CmxohO+q/ZYxLVcE0U1KdrbSKTq2XRV9jwky8Y5XVlv6RvHJ LjhGVB5JnDRNXm0bN16EbJs8UESl0H1JF6+CDX+z2MaPtihnovA0AZWpqbKbT3ViT4Iy GEcWS0qv/eMJU/k7WPXK9owK1K7skHZOeUsAwBEifiiEBW1XhYmVFDt0iHc9/Nnmse51 6YuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732177215; x=1732782015; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lmhBGQ/m+qVWheJtFzpyd5mx+oTRXoNs7skerrQrF0g=; b=XBlTqhhiDwWO3aL0exiXNy96yI1dqH+0LUIP5q/NTGV6RxjVRn9KSjNHJGI1a8kQ73 G8gBU9rpCB4+tTGHG4Rf4Ir/82jThEzcUnS71Le/vgKa0lcpMrhn0VPXWcOnV1u9HIjl SIN1ISqyPZUZ+ghGg7i4X7VqzdlYPhtbfynou0DjY5u+GgBvOxGKTZBFbWjAMovQkXeQ So/vaExsHAHfdqd6NpFPCwLuOW9KbE0N421A33/nRJkFgswJpvwiWFbQmnXaXLHNB59o EBDr1UYBADgW/abZBBIXwtzW80GycWyHbHdbPbRbchjT3hezh8BZOMEWTg2eqiqWRWVo 65SA== X-Forwarded-Encrypted: i=1; AJvYcCW7Ecrkie4ucaVUc10F8urh2BpsPEpkOnZr/KFapFSeTvwrwJ1AA6pQALpMzL73BBN9qRQRCwvUAQXd@vger.kernel.org, AJvYcCX+3Ox2RN9FYoeBSAzVvnEWpE5DlTzrEVFRwAMwCAyJXHbcCFtoiIOUZWsn+ju9HPBuPH+lzsfr1nC99g8+@vger.kernel.org, AJvYcCXfbhv6SXWMFgoxrf6mnWaTP47KOagOr9VXqMJxd8zhunAsS3Vv6XgBnijq4lJ1dOt6uMcpyC9UCtW9@vger.kernel.org X-Gm-Message-State: AOJu0YyFKZG3TrWokWTJoZEoASafB+25nSgtaRkO8hzPuHTq9PTWoltA tGwpvf9TaBmtP4Pbuywgvcz6640vLZnHO7/7y0bGmSTKjmhe8NxMUbgiDdEu X-Google-Smtp-Source: AGHT+IEXAKD/iUvWWuPhg6BgTI8jpoaIDpC5HIqcCZiH/v34w/m3LLezWKo9yLndSf2xo7t5UfgRfA== X-Received: by 2002:a05:651c:e04:b0:2fb:5723:c9ea with SMTP id 38308e7fff4ca-2ff8dcc9c31mr21887501fa.30.1732177214588; Thu, 21 Nov 2024 00:20:14 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ff69967dedsm18104251fa.56.2024.11.21.00.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 00:20:12 -0800 (PST) Date: Thu, 21 Nov 2024 10:20:07 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matti Vaittinen , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/8] iio: gts: Simplify using __free Message-ID: <5efc30d832275778d1f48d7e2c75b1ecc63511d5.1732105157.git.mazziesaccount@gmail.com> References: Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 --- Revision history: v1 => v2: - patch number changed because a change was added to the series. - rebased on iio/testing to avoid conflicts with queued fixes --- drivers/iio/industrialio-gts-helper.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c index 291c0fc332c9..602d3d338e66 100644 --- a/drivers/iio/industrialio-gts-helper.c +++ b/drivers/iio/industrialio-gts-helper.c @@ -4,6 +4,7 @@ * Copyright (c) 2023 Matti Vaittinen */ +#include #include #include #include @@ -167,8 +168,8 @@ 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 i, j, new_idx, time_idx, ret = 0; - int *all_gains; + int ret, i, j, new_idx, time_idx; + 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; } /**