Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2704605pxj; Mon, 31 May 2021 08:40:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDTQCPKJlZsL+zs3ipJES2n3VMCt8zMqla2tP5EK2nwE6iVy6YtmhtOvFPiC6hqxobreGH X-Received: by 2002:a50:eb8f:: with SMTP id y15mr19161373edr.285.1622475613448; Mon, 31 May 2021 08:40:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622475613; cv=none; d=google.com; s=arc-20160816; b=mhNVkbrVGb42C0EjzDJgIaRSIvqbItYxsH0kknfEcUCxbPitJEq5KvgPunv+7kO59u SYG6m0zSgdZjzel4gutcolq6AzE/4bRmJzgOt0/n9Batk/FCSUyuGj1utqkmCHOAQ9F4 exvRQAfV1GDND0kjLuPA5VUh2feBZUrJgjwkAmgQSq7dQ0kdJvmQeJxTG7X2K+tgiaRC jG3TmAGRKDNggYEmQ4LvDPzY6sG29BOJNUfkJmi0nQ/eGuEsM3sO+Q0yWNhOczuSkHvU isFG8EHIJUi0zNdF5V2EB15F6eLv9zzIXjiV8JVnzknH4VLHbkoJXUjetHg2kKiQYCLg qnvw== 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=hx4soyESQH41S909cpeSmGB0BNnxwdA3dhtkRw4IUfw=; b=VTIo0bZFmwjFog+UaHb9wWwgcW7iHlNpbbEFdTmPeRQG5lB6tyasONFY5VmDLiHr1z w88uloaF4xnDmc34lbdRoxmB1PssALfO2HAJvni2nxxUmGWTHXTEdvYH/s+cNGpitdm5 MLh20p5TvkNR4qUQieE9l455LNwMKm7J4fb+CxwSgR4xBCDkjWXP0BMi6QrucFb6ihUb OZPvt3PH/9XhigW4ltWX0YmdQ9qCmGweKOFpLJOfL8eCYBAAsTFedKbzdmW+mvZsfeTr b/xP5WW2zuvy5rJaXOO7ELZEc6J8nuFnTcawgci7ttVTn/A5gsQORdwvlLfHTj/MpHPR hEVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Vq4z0POi; 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 b27si12959424ejc.676.2021.05.31.08.39.51; Mon, 31 May 2021 08:40:13 -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=Vq4z0POi; 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 S233126AbhEaPij (ORCPT + 99 others); Mon, 31 May 2021 11:38:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:48838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233860AbhEaOVb (ORCPT ); Mon, 31 May 2021 10:21:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 684416157F; Mon, 31 May 2021 13:44:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468696; bh=A/FcZTXtu170y4ACVQdGBr5hCnA/RLBK6oGlPg/svGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vq4z0POi4H84X/QqysSh2oF65Lw8LCppV2A6ivDPW/WpbdQhg5F6mLngfpqroK9qV 3ZFKjFwecUi9UWE7eZd8NToFod/0g1zRdjOA2vOFU6E5XCrnTLXhYrxQ1IcvuBtd6m 171WTiU0YnCWnBMk+sBrPctvEiZDqtwSIn89oq/w= 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.4 046/177] iio: adc: ad7124: Fix missbalanced regulator enable / disable on error. Date: Mon, 31 May 2021 15:13:23 +0200 Message-Id: <20210531130649.506977955@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@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 @@ -564,6 +564,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 spi_device_id *id; @@ -607,17 +612,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) @@ -643,11 +651,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; } @@ -656,17 +659,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; }