From patchwork Mon May 31 13:12:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 450509 Delivered-To: patch@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp887286jao; Mon, 31 May 2021 07:38:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJ74xTzcQRqtr9gDRsR18tMT+7w2nVgGyjd2WmyBD+1lRNl9028IW5sPv2cTuJAfwxH4br X-Received: by 2002:a05:6e02:13ad:: with SMTP id h13mr17665716ilo.169.1622471934388; Mon, 31 May 2021 07:38:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622471934; cv=none; d=google.com; s=arc-20160816; b=MQzk3auZIYXBt7OX+K8p+KjxflOSpu+EeEIg2w9lVGH+mH7MIV+a7nSAccIW94dDwa w2pnzUOSCFv7sX7Rt2KfuHGPVmozutkf+IrZWQc/tT1pqzUGfczn9obsRcjI7x09498Z /6QlHqn4x9rPRlox2V575ufgARDrg8lBjAiKgc+TsXnryIkwPeMWPSv7tn9LUgk3cZvL KVjBXmMjN5cNLEcZjR9SXMOEjO6mSQMtaafVlMs23L8lqXGS7VsZdyhHyzLStVFV0l7s EP1+b0p2iJMt8nbyP1MjGwSbJpJ36MxLqfdHj8HDFR4ac6g/7Z8X6ASUVG7JtwUQtgpl hsvA== 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=RjO9b7N5GY7BamMM+VwfXrBTgO1OvckqYlMrveHDntRirL11d33DXVK6m1HtQJ/It9 ZUzzZo7Xi01FpIT9PPmKWLdC0/vmq08OD4tURA2EdFq4lSrtZhJjdzQaarFoQjTIlYf3 uNetQQ8svvu6xXGyNsm8ZJvIdqjospvq4WxyNQxPoYvdIaJCnD6rL3hJTt3Gb7ysTZps 89y2NTFI0NuBoyVKB8o8X1VkaN7ig1COoYy9f+jJhSpeoHhHAEv1Hn7BGNFmVTKFmeGT usAwT/ic3lccQucide68p2rqUJzpa5GlcuE5Swm6swJjrT79tcy1JfciJvCFjTPPCTp7 LCMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fHl+SfJq; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 x5si16471919ilu.87.2021.05.31.07.38.54; Mon, 31 May 2021 07:38:54 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=fHl+SfJq; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S233879AbhEaOka (ORCPT + 12 others); Mon, 31 May 2021 10:40:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:33236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233963AbhEaOhi (ORCPT ); Mon, 31 May 2021 10:37:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E0DB161C59; Mon, 31 May 2021 13:52:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469126; bh=XNc7gbAIvDHuE840Jlwhk0t4yaSnPloCG7GiueXbCrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fHl+SfJq56fChkLk56bOFVVtCxjUCIZuXWTN6txDQhqbbP/LFytDaAiNv5DP5TGoG 6sybG/ToavZ0xJtu+XsOEfef6ZfPuHaGlbXyQLoykWLgXgDKFa8TUE3C7V8gArEX7S smEkvNMnB60Md394p0xakYJfQQt30x1VhzAm2fGU= 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.12 079/296] iio: adc: ad7124: Fix missbalanced regulator enable / disable on error. Date: Mon, 31 May 2021 15:12:14 +0200 Message-Id: <20210531130706.513142831@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@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; }