Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2654955pxj; Mon, 31 May 2021 07:30:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywj4HfArk9o5LxYfImaWNqglKf9FsDYVlm9vRUsOXI9MiTe5z4v/q40uIJUaJBfTh98P87 X-Received: by 2002:a17:906:1e15:: with SMTP id g21mr23038207ejj.241.1622471439662; Mon, 31 May 2021 07:30:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622471439; cv=none; d=google.com; s=arc-20160816; b=axxnUBO8IzGDk+nN6Loe7AcYzyeJWCYXO2A+6dg01ncpq3IZRFeMUfAv83FcPqPkfj WvZPhbSriWuWrn6sMJwCWRNDOA/3AB0Jy4FtGrSNXFFIhYXmHHrRvu0agMI4ziUroztQ i4Tp8D8Qw9mRDlszAtyoNGVIP93QNOhyOP4kdCuvEWdf+vbAbgn7kvKqGeNaJqefO77K 8fEFoLKJzE0k4pdcUWNo6UPtZkw19fESrbuGyRuRPqEIh8dlKo9+zIKxyVVNExntfmQW uE8MYmW1MTtjD56R7q6Ody6G0yZ6bbH8rY+eSKW97LMhrcWOQu5LAiqUDaCLo7h8opVL aAjw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=r9bNMEuq1Cwtdj3sIJFDHZbJRx6x3CrHd0fQs0cmaKg=; b=JRCSiY/HRlbSo1xs0NUMFiD2LDKszHu0XE069XYYv3iWeYhcclJDRfHGZU+p3seE0c ilE3HSCJTbNTgHe5h9/on9YIRL4u6zSj0HSXrUXrz4/t0oB/1cNlRqrei9oKZ0LSit2R WltjAJvpe+R/WVZ7HC6Z9DvFI5oAL69G5nrEgeA9dNXBpRFBLCt8SXGcBmbfY9+pPwye 1UH1Me0qSbv7f7hnk2y86PrH3b7YpKAckAy8rAQix++nmj/lYa4Azt5C092l+/z0XADR +Fs8FAU5g/pPkcVt2AWY44ejKdEaIB9hr9nBlI42rsSdQgajfkXPKF5wIDxAt8TvqHo9 onGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g6338VXt; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j16si16510405edj.401.2021.05.31.07.30.17; Mon, 31 May 2021 07:30:39 -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=@linuxfoundation.org header.s=korg header.b=g6338VXt; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232547AbhEaO1b (ORCPT + 99 others); Mon, 31 May 2021 10:27:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:55372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232517AbhEaNvr (ORCPT ); Mon, 31 May 2021 09:51:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 33C8A61876; Mon, 31 May 2021 13:32:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622467959; bh=XNc7gbAIvDHuE840Jlwhk0t4yaSnPloCG7GiueXbCrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g6338VXt2IV1WI78mJ2umvR4GdVfjl5Z2FwtM4rvipHHuDh1ZLRuGGzQfiUXPWmS5 l95ktHRQ6HcmEctII3JkP3pnRcCwh2bQbxYQUd/55fLks1e1/yJ2j2cEpt3YEBitwP 4ymsFzE/iL2261F1sWSjBniNZxEKYbcDXqmCDJXk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean , Stable@vger.kernel.org Subject: [PATCH 5.10 064/252] iio: adc: ad7124: Fix missbalanced regulator enable / disable on error. Date: Mon, 31 May 2021 15:12:09 +0200 Message-Id: <20210531130700.165962249@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jonathan Cameron commit 4573472315f0fa461330545ff2aa2f6da0b1ae76 upstream. 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. Alexandru's sign-off here because he pulled Jonathan's patch into a larger set which Jonathan then applied. Fixes: b3af341bbd96 ("iio: adc: Add ad7124 support") Reviewed-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron Signed-off-by: Alexandru Ardelean Cc: Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/ad7124.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -707,6 +707,11 @@ static int ad7124_setup(struct ad7124_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; @@ -752,17 +757,20 @@ static int ad7124_probe(struct spi_devic 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) @@ -792,11 +800,6 @@ error_remove_trigger: 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; } @@ -805,17 +808,11 @@ static int ad7124_remove(struct spi_devi { 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; }