From patchwork Fri Jul 5 10:40:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13724928 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 5E47DC30658 for ; Fri, 5 Jul 2024 10:42:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=oTC/Azk6QuGeCqi4nXZfSzWiS7YtP2rKGZn+knA+oxU=; b=sWjuPn9G8C3DzrkET/EbvjeIKv ALit8U1Bh3Y6TDCO+Ti9ZRzmTSyh4wmVPA/RfqPL3hLAic93GY/hYQMosIFi7+O4zuW6dgR0wU+wH MYDOs3rNkICXWm3wdfnTXGq1FWRMqcL7qZDZ7VSp+mSdJST1DIHXvCeJlTvuu4x1tflduxP4Ry772 H0KRIEVEb186QF69aOc7vZ1MqgMu+/ADbIjCAVNeVF3Zgkyoyl+Y78nb1Cj2jeGnvP8SnPq7Hv/N1 Tq0gWu7zYn8c/k7YRAPoF6XWtaaKXn+43NNsZ6HXDwpeViwlYuVLUH4aTCDTh0tfo6VXPie9c8UWY JXybrjOA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPgO3-0000000Fg4A-1o03; Fri, 05 Jul 2024 10:41:55 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPgNB-0000000Ffks-3sTJ for linux-arm-kernel@lists.infradead.org; Fri, 05 Jul 2024 10:41:03 +0000 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-36796bbf687so875872f8f.0 for ; Fri, 05 Jul 2024 03:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720176060; x=1720780860; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=oTC/Azk6QuGeCqi4nXZfSzWiS7YtP2rKGZn+knA+oxU=; b=AffIXeqI7gj6QBJGwc+S3mgn3oSCmMH41NQmpnsQWjTmOrjDPdWLvDiWqRBUSuJ+dF Xv8WKYraF3ec1KZqe1Y9nwmi7gjz2VPxpZCCLqNSVdmmSDbeLBawwYP9yXpBio8J6elr o5AircvNUrPzRg+5iDgJ+pb+WS7/79K596ALQFyRISl6871lBsaLADzcHEpkAS7p61T2 6OYx9u7vIOIMEugWZFgdoyvD/yEYPdMUzY3OOj1llWavRSwoX9cJypO106e4IjPRLCGL sLRFaDjOPq6Q++v4IgM4E5J3X6Qqc0Pbbsz6ZTtr4QvUjwWWbxyGg6UcqBh0pPb8oscG tgdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720176060; x=1720780860; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oTC/Azk6QuGeCqi4nXZfSzWiS7YtP2rKGZn+knA+oxU=; b=rE4gs0VTBFJRzxGU5Cs4mpEGMWcpktrT8WIT0DDDeIrz7edKO6P39NkfuE97/0xALq wegZUnCI/e0mzy2EtI99lza59uHkVGFmASsLrdfGnlJGJMk4wD9FZz1E9kI71jbzYKRY JAC8VlKTN5T5lQ/zaOSUzWOj5nKmsTLD1S5/hLHO3csH6G6/tjwYFGRptQIR1f66I2Y1 braCpecHGxQ17x/tJTYXD5ymIwQKiiRqUY+UlNIRhmq86FlvcNSQro0Qfhl7pvm9/q0e kQfiJByojqUwa9PGb7cOH2ptuNqujxd5UMk7CdmsQhmIssmn6cnBtlV/kqz7011bejrG 9c4Q== X-Forwarded-Encrypted: i=1; AJvYcCWII7FaN6PESX4ugqq8pDbbtsO3dx9mdcU4//Pa120lm67BVSwUCbg/uDDcGgc7obOY2RS08GptNymRbi9p9tZSuxNmYqDiKB55sI6953elLXq5dHg= X-Gm-Message-State: AOJu0YwzVJLYBalWj9Kwh421qK71g8eoHPMSJ0RuqLvsEwZ2Zxiq9Ew3 /uVSQnvp8RD0DUdbcGFuXRiNwYLlap1zqgxU4jZh49IAp5Mq34YSvHo87A6fB6E= X-Google-Smtp-Source: AGHT+IFpPHqmjxp2CPDg1mV84p7LQ3rhp2DLU/4rV2/xi9+XlRjQpCs244ba3YRg8O8NY0lubgaIhw== X-Received: by 2002:adf:f7d1:0:b0:366:eade:bfbb with SMTP id ffacd0b85a97d-3679dd651ddmr2544484f8f.46.1720176060011; Fri, 05 Jul 2024 03:41:00 -0700 (PDT) Received: from [127.0.1.1] ([178.197.219.137]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36789d5ec1csm8680446f8f.37.2024.07.05.03.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 03:40:59 -0700 (PDT) From: Krzysztof Kozlowski Date: Fri, 05 Jul 2024 12:40:47 +0200 Subject: [PATCH 4/6] iio: adc: max1363: simplify with cleanup.h MIME-Version: 1.0 Message-Id: <20240705-cleanup-h-iio-v1-4-77114c7e84c5@linaro.org> References: <20240705-cleanup-h-iio-v1-0-77114c7e84c5@linaro.org> In-Reply-To: <20240705-cleanup-h-iio-v1-0-77114c7e84c5@linaro.org> To: Dan Robertson , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Oleksij Rempel , kernel@pengutronix.de Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Krzysztof Kozlowski X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2264; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=8UqNvu97RyQCvnTqNuJYZZnXKv3X2QTRkCh8H7bl7SE=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBmh82wGqZAMadIz1XR5aj+8tdWoDISp1r2Kw1oO rXfx9a4AMKJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZofNsAAKCRDBN2bmhouD 16lzD/9AhnxwXv5OrwJjGIWy8uU3qbq+Ay+EYJfL4l7G5eN2ahNnoKc2trvkQGgIk4WpPVAl/We GkkGk91bFiIseEUezi8Pq2WkeJE4jah4gZ1ygbkxeSoKAVnlO+SAGNANz7jDm41gc/Cdxfb7gfw RoxJrHybC9EUzc/Snj1m8vWzWcqbw6cMpbaZwsYGNA3hOxzdM41aC0zySf1oV/XpDuUoaAfthbA M0YWsOzOt987EMMYpFobfLLz9XC3M6CZ3vX4dvm/RRnGqtwg99piq5uPgVHV0lSgCi8EfyJLSZN zejEnA1hsYNUX8M22MABU7/A5LHcKcuT54Qm2bqIBl0vV4VqDMnHp1QcTyiVAG9TVcbk4ikpMCM iSd3V+bj1cxn2zQfR8C+UxzTzHX92pK5G0YYcL8x4MFdemOQ6VN0Icb46+2qHYmirioczwvybFJ 500larK7cxtaZ75pdWVz0Snsfwk6C7wcsPY7n1gf0NZOG14tx2Cc5K6LyWNsfoB9xFndwAAKiUJ WETcQ86+nEMU0vwIPBMsPc30EF36mLPmM1ImODNcM9VXC5Myq5luyWftG3KqH+BJXoGGg/KYA8+ rs9rV6DqNRDyFhplpy3WFo7+5A//cOVA98Oo548YWTh2Qgmbe/ynrm7kVPK6pVp6ACc5YkeH/sx FBbXnIJipqkVO6g== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240705_034101_997444_08CA13A5 X-CRM114-Status: GOOD ( 14.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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: Nuno Sa --- drivers/iio/adc/max1363.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index bf4b6dc53fd2..d0c6e94f7204 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -13,6 +13,7 @@ */ #include +#include #include #include #include @@ -818,7 +819,6 @@ static int max1363_read_event_config(struct iio_dev *indio_dev, static int max1363_monitor_mode_update(struct max1363_state *st, int enabled) { - u8 *tx_buf; int ret, i = 3, j; unsigned long numelements; int len; @@ -850,11 +850,10 @@ static int max1363_monitor_mode_update(struct max1363_state *st, int enabled) } numelements = bitmap_weight(modemask, MAX1363_MAX_CHANNELS); len = 3 * numelements + 3; - tx_buf = kmalloc(len, GFP_KERNEL); - if (!tx_buf) { - ret = -ENOMEM; - goto error_ret; - } + u8 *tx_buf __free(kfree) = kmalloc(len, GFP_KERNEL); + if (!tx_buf) + return -ENOMEM; + tx_buf[0] = st->configbyte; tx_buf[1] = st->setupbyte; tx_buf[2] = (st->monitor_speed << 1); @@ -893,11 +892,9 @@ static int max1363_monitor_mode_update(struct max1363_state *st, int enabled) ret = st->send(st->client, tx_buf, len); if (ret < 0) - goto error_ret; - if (ret != len) { - ret = -EIO; - goto error_ret; - } + return ret; + if (ret != len) + return -EIO; /* * Now that we hopefully have sensible thresholds in place it is @@ -910,18 +907,13 @@ static int max1363_monitor_mode_update(struct max1363_state *st, int enabled) tx_buf[1] = MAX1363_MON_INT_ENABLE | (st->monitor_speed << 1) | 0xF0; ret = st->send(st->client, tx_buf, 2); if (ret < 0) - goto error_ret; - if (ret != 2) { - ret = -EIO; - goto error_ret; - } - ret = 0; + return ret; + if (ret != 2) + return -EIO; + st->monitor_on = true; -error_ret: - kfree(tx_buf); - - return ret; + return 0; } /*