Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp515227rdb; Tue, 23 Jan 2024 06:39:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IEo88kT/pFa7bBiFy9S8jnBCC8343UktaYM3xThthjcRi8x+zwGkGrJj8GzclzwXFoxU19F X-Received: by 2002:a17:90a:d315:b0:290:685b:7b1f with SMTP id p21-20020a17090ad31500b00290685b7b1fmr2770151pju.46.1706020763433; Tue, 23 Jan 2024 06:39:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706020763; cv=pass; d=google.com; s=arc-20160816; b=sVK8wjJVfpNxoTf35yfTXxYYboOMNgK638YvkhCMcpHrak7KBBisfW18gafbrklGe4 Fu9vbqhxfNrNDQd8q6SGyeQ0mIL0+z+/VNoOu7Dra4H9Z8S6iTVO2+UFRDz0m6ppbpSu b54H2hhMRja0Afz/hmmtWgqmE3L/3NI+zTJNablD4ycVEgWRyoUrKuiTTOM2kagJAN0Y Qe4+EX0sdEs7DvzNih3m952lRn4lD+Y0wfFS4jSCobcez79s7WO9D9LfYgaYF4e7O9UE E7mz+ioljwmyvahn+2Ht6wrfYjBCRzEfUbgtXQnZSEN2OddmFsLqCphr2oZNBwgqoLxw w+xA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=WOE09cQw18mGzukoI/a3Ir2egN+CAwTh+Jgs3xeKW1k=; fh=9aCTWzhdHmTATz92ptPknh05eXqxgTaEVA9XqyMfwgc=; b=YcmAj1fl/0U1S4GCYr0t4CaEi4bQcoQE/xSJQWjc+uF0NSzgYk+HPLNVgD4oAAy+Mg MXMFwUvfkgnfRxXwyG5wYeEssRZwbR7L8fIVTTREVhYEN/MZgGIoCop7Nbrwg8iItF3K A8FDwZUe57DqVhnF4Xc18XerQniw7CWhqjEIqb+BWAhpaONlDCQLPWFKc9301qU3PvO8 EED6UvAZiBJj8aBpK7L7ZM6YCCfWX8oO9uiVWhPQbaLlEA8MNA8Rc//8FsDO7R9fb9l4 /jHU0wOd6N1dHJH4mmHQKMqkBomv123s/giGBMnyMS7XGTOYGoJ22ch1Kl1dhhYMfdIR yxxw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=wSR6GGTG; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-35425-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35425-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x6-20020a170902ec8600b001d4e1edaf59si10162596plg.61.2024.01.23.06.39.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 06:39:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35425-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=wSR6GGTG; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-35425-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35425-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E31FFB24322 for ; Tue, 23 Jan 2024 14:10:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 034DF5F845; Tue, 23 Jan 2024 14:09:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="wSR6GGTG" Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92D055D8E2; Tue, 23 Jan 2024 14:09:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.249 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706018980; cv=none; b=Eb+wXMOydszX40pkGIC9KvVuL42kNhOdAj+C3Kqw4gz8j/aHCdg1OmgOvm0i9uRQAy5rNFxmVDH5uZATaCIBcpf5vC1Rfko67Q0tWfcO81jZexC7jG6lDT5GPZb4scdy4C0rolqkOmdnpdetpZsUco8oELzM3YKJrgKLUwkCnhE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706018980; c=relaxed/simple; bh=SxuTBORfGF5xuK7WaufdbTkcdXRpMj62tgVmhO2eMZk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fi4Ux+S5Hkg4n10Np5hMVmxxzpVOPQZhQ5SLzssAe4Ql6x2BrxAK/cDVhMphqDHqc23KuEicEy2Yzhj6VLbmdKXiw9twr2VGOqKYyZmoGWA2YrJIdlVItXoNrbVGEOfUMV5NZ/exT+fm5JACtCp3W4O5uWrsEvQTFJoRG3H3s64= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=wSR6GGTG; arc=none smtp.client-ip=198.47.23.249 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 40NE9KCH051462; Tue, 23 Jan 2024 08:09:20 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1706018960; bh=WOE09cQw18mGzukoI/a3Ir2egN+CAwTh+Jgs3xeKW1k=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=wSR6GGTG/DtYAb0xxfn2+UYvmLq5BYeOUZPAE6kChLfOEV6gxyDNh+4TnZilzVqFT bUgrneOT5tDSlSKAPA5IswAgSmNmL7RZ+SKAObmDltfzSzea/7UNE3SKAls1377A0M HRRlDQGRcOH1aesN+AXVONR7a06n1oAJmpgdNhwg= Received: from DFLE109.ent.ti.com (dfle109.ent.ti.com [10.64.6.30]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 40NE9KvJ003092 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 23 Jan 2024 08:09:20 -0600 Received: from DFLE107.ent.ti.com (10.64.6.28) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Tue, 23 Jan 2024 08:09:19 -0600 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE107.ent.ti.com (10.64.6.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Tue, 23 Jan 2024 08:09:19 -0600 Received: from lelvsmtp6.itg.ti.com ([10.249.42.149]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 40NE9Iut034990; Tue, 23 Jan 2024 08:09:19 -0600 From: Andrew Davis To: Jonathan Cameron , Lars-Peter Clausen , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= CC: , , Andrew Davis Subject: [PATCH 3/4] iio: health: afe4404: Use devm action helper for regulator disable Date: Tue, 23 Jan 2024 08:09:17 -0600 Message-ID: <20240123140918.215818-3-afd@ti.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240123140918.215818-1-afd@ti.com> References: <20240123140918.215818-1-afd@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Use a device lifecycle managed action for regulator disable function. This helps prevent mistakes like unregistering out of order in cleanup functions and forgetting to unregister on error paths. Signed-off-by: Andrew Davis --- drivers/iio/health/afe4404.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/iio/health/afe4404.c b/drivers/iio/health/afe4404.c index ede1e82013118..75a513a92242c 100644 --- a/drivers/iio/health/afe4404.c +++ b/drivers/iio/health/afe4404.c @@ -349,6 +349,13 @@ static irqreturn_t afe4404_trigger_handler(int irq, void *private) return IRQ_HANDLED; } +static void afe4404_regulator_disable(void *data) +{ + struct regulator *regulator = data; + + regulator_disable(regulator); +} + /* Default timings from data-sheet */ #define AFE4404_TIMING_PAIRS \ { AFE440X_PRPCOUNT, 39999 }, \ @@ -502,19 +509,24 @@ static int afe4404_probe(struct i2c_client *client) dev_err(afe->dev, "Unable to enable regulator\n"); return ret; } + ret = devm_add_action_or_reset(afe->dev, afe4404_regulator_disable, afe->regulator); + if (ret) { + dev_err(afe->dev, "Unable to enable regulator\n"); + return ret; + } ret = regmap_write(afe->regmap, AFE440X_CONTROL0, AFE440X_CONTROL0_SW_RESET); if (ret) { dev_err(afe->dev, "Unable to reset device\n"); - goto disable_reg; + return ret; } ret = regmap_multi_reg_write(afe->regmap, afe4404_reg_sequences, ARRAY_SIZE(afe4404_reg_sequences)); if (ret) { dev_err(afe->dev, "Unable to set register defaults\n"); - goto disable_reg; + return ret; } indio_dev->modes = INDIO_DIRECT_MODE; @@ -530,8 +542,7 @@ static int afe4404_probe(struct i2c_client *client) iio_device_id(indio_dev)); if (!afe->trig) { dev_err(afe->dev, "Unable to allocate IIO trigger\n"); - ret = -ENOMEM; - goto disable_reg; + return -ENOMEM; } iio_trigger_set_drvdata(afe->trig, indio_dev); @@ -539,7 +550,7 @@ static int afe4404_probe(struct i2c_client *client) ret = iio_trigger_register(afe->trig); if (ret) { dev_err(afe->dev, "Unable to register IIO trigger\n"); - goto disable_reg; + return ret; } ret = devm_request_threaded_irq(afe->dev, afe->irq, @@ -549,7 +560,7 @@ static int afe4404_probe(struct i2c_client *client) afe->trig); if (ret) { dev_err(afe->dev, "Unable to request IRQ\n"); - goto disable_reg; + return ret; } } @@ -573,8 +584,6 @@ static int afe4404_probe(struct i2c_client *client) unregister_trigger: if (afe->irq > 0) iio_trigger_unregister(afe->trig); -disable_reg: - regulator_disable(afe->regulator); return ret; } @@ -591,10 +600,6 @@ static void afe4404_remove(struct i2c_client *client) if (afe->irq > 0) iio_trigger_unregister(afe->trig); - - ret = regulator_disable(afe->regulator); - if (ret) - dev_err(afe->dev, "Unable to disable regulator\n"); } static const struct i2c_device_id afe4404_ids[] = { -- 2.39.2