Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3278458pxj; Tue, 11 May 2021 00:22:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9jvJQ5bmTrpRQVxZcG531OHAweoZvNexfEIjHSkqbPGFqBCByNIb4WuaTIorMtTGcs7DM X-Received: by 2002:a05:6402:164e:: with SMTP id s14mr31266057edx.232.1620717724868; Tue, 11 May 2021 00:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620717724; cv=none; d=google.com; s=arc-20160816; b=erzlN6qsbeSYJjrhk7PsTl6jnp5tAolb/FBl0EBib38ugATgezObEXOaJssYfMymCt lsBvt+J8tXknpnIN+lDkRTIX6CX6bXViEW/cJt1csBjWY/qbbEWmKB64ohr6dzYwMN9C Mk9dQI1DZkWu9NYyDSk9ngkiOszuzFJto/Ks3KPUo7QEjqPytjgVUs/Fy1rcMK+kCESo r0LrTdSd5wCIPZ4x7bBsfwT5qzrNUko99/0EojkBLfS8tcP4NzMcogOc022KkYq89ZV0 uSW6In2PJGDMD28SdtcTMnZpqr8iNlBkX5o8+fGAXJqUEhCMPQGvDVW5l+PuFZ4l5Ik2 dv5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=URnNCU/Gt3uzfVjqFnT5ZArbKyWbTbXjKVLfJMYugCE=; b=tsz1fKno6SzbO8SVwogSp1iHdAjUFWlM7g/pHBDNRiIm1mR3VkanMBOH1NnYLcyJkq 9JkVn6reT/IwO+WzbPMXAmyQM5PSszlBQxzUTAdbG7lWGT8DwUS/x9Aawz9S1jgFAsgp xuz3htWC1no4NMSfGCBQya8D8kFA2dqa/ViXHm/Q9rUx2+4Dp+kSad6U4vg3r00pAxfg /MG4w5ZZOojvJfGOq3oGaGBl8WCYmR9yox2gjfCGZXOzJPzjwJX0uVpTtt1sZ32zO0dy wB6Wqd/N7GB1rp1CS2QwRuzlz5/qOGbZyrHqpX5L3TQ3MKJmxymKMOPJPOyT4rRRSHZm v9MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=JSOSsYmF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deviqon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d5si15018268edq.561.2021.05.11.00.21.40; Tue, 11 May 2021 00:22:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=JSOSsYmF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deviqon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229637AbhEKHTq (ORCPT + 99 others); Tue, 11 May 2021 03:19:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230248AbhEKHTn (ORCPT ); Tue, 11 May 2021 03:19:43 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 874FBC061574 for ; Tue, 11 May 2021 00:18:37 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id zg3so28257179ejb.8 for ; Tue, 11 May 2021 00:18:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=URnNCU/Gt3uzfVjqFnT5ZArbKyWbTbXjKVLfJMYugCE=; b=JSOSsYmFD5QmGgpDLNRQitF/l6W3zvsTNv8c9WmaXd2ytjXpPNKnrjA//1MXHMKdUE Azc38GcVttcldRR6C6uCuQd2x6ZjxIxzuxcSSJMhU8pbgnHZ9MGYrd9yUNMqow+IZagb LT9r9GzcLMwU6sFdCxUTMDbTO6uHpv39PGp4dg1sblqjLxDOaKUJavNbNu5+BIVvT8Y+ gWWx3jnc+18uzkjZNZSWQBLI8/KNV1W/iP5/NJfPk1vNytiHBIv47S7Ndkaca5c4uCRf XBdptlEmuOM1mbo/G2Uj6lolKHyn0b08u8QUgkE7bk8W7yaIMDVrWWDo+DvGeG8hb3Lm Zivw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=URnNCU/Gt3uzfVjqFnT5ZArbKyWbTbXjKVLfJMYugCE=; b=b/W55/nZdw5kkXbJPOnFhUG7IqkT3HAZdTw5BFcpriv/jZTfUFVqjbBhnS5fpy+VJm lCkSkgTKS5NCYEs6v4liNkhefdTP6aiI7gp3E9oE6DIhUgrKy6b0v1D9unGj5wU7wEHH xktEK0wVB2TjvvYtOBbJ28EkHu/JKOSH26ONCbJ1qIPhJ352vtFQpEN0uevlnl9YD2o3 AW6pJ0EFUFmb6qhqc+Nxsy4ZpZJ6sEwqFjo/mRcraH760b5gc4rDmrY+5BNKZZzYfglt gliHxfWl9wKr9sv5l0SuHyD4dxJHYds24HYE0BxowTqDvX7QTPyxdKJL78Q6GDAL3lX8 ujvQ== X-Gm-Message-State: AOAM530Le+athMaq6GRAhFscKOgkkXc1KpAmIpnvg4+y3ZygFW7/rlcf 5Zh9c4eEdro5p0oza9geBCV9bA== X-Received: by 2002:a17:906:1e0b:: with SMTP id g11mr29707544ejj.291.1620717516331; Tue, 11 May 2021 00:18:36 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id i6sm13871558eds.83.2021.05.11.00.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 00:18:36 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean , Alexandru Ardelean Subject: [PATCH v2 01/12] iio: adc: ad7124: Fix missbalanced regulator enable / disable on error. Date: Tue, 11 May 2021 10:18:20 +0300 Message-Id: <20210511071831.576145-2-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511071831.576145-1-aardelean@deviqon.com> References: <20210511071831.576145-1-aardelean@deviqon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jonathan Cameron If the devm_regulator_get() call succeeded but not the regulator_enable() then regulator_disable() would be called on a regulator that was not enabled. Fix this by moving regulator enabling / disabling over to devm_ management via devm_add_action_or_reset. Fixes: b3af341bbd96 ("iio: adc: Add ad7124 support") Reviewed-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7124.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index 9d3952b4674f..437116a07cf1 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -850,6 +850,11 @@ static int ad7124_setup(struct ad7124_state *st) return ret; } +static void ad7124_reg_disable(void *r) +{ + regulator_disable(r); +} + static int ad7124_probe(struct spi_device *spi) { const struct ad7124_chip_info *info; @@ -895,17 +900,20 @@ static int ad7124_probe(struct spi_device *spi) ret = regulator_enable(st->vref[i]); if (ret) return ret; + + ret = devm_add_action_or_reset(&spi->dev, ad7124_reg_disable, + st->vref[i]); + if (ret) + return ret; } st->mclk = devm_clk_get(&spi->dev, "mclk"); - if (IS_ERR(st->mclk)) { - ret = PTR_ERR(st->mclk); - goto error_regulator_disable; - } + if (IS_ERR(st->mclk)) + return PTR_ERR(st->mclk); ret = clk_prepare_enable(st->mclk); if (ret < 0) - goto error_regulator_disable; + return ret; ret = ad7124_soft_reset(st); if (ret < 0) @@ -935,11 +943,6 @@ static int ad7124_probe(struct spi_device *spi) ad_sd_cleanup_buffer_and_trigger(indio_dev); error_clk_disable_unprepare: clk_disable_unprepare(st->mclk); -error_regulator_disable: - for (i = ARRAY_SIZE(st->vref) - 1; i >= 0; i--) { - if (!IS_ERR_OR_NULL(st->vref[i])) - regulator_disable(st->vref[i]); - } return ret; } @@ -948,17 +951,11 @@ static int ad7124_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); struct ad7124_state *st = iio_priv(indio_dev); - int i; iio_device_unregister(indio_dev); ad_sd_cleanup_buffer_and_trigger(indio_dev); clk_disable_unprepare(st->mclk); - for (i = ARRAY_SIZE(st->vref) - 1; i >= 0; i--) { - if (!IS_ERR_OR_NULL(st->vref[i])) - regulator_disable(st->vref[i]); - } - return 0; } -- 2.31.1