Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp382424pxb; Wed, 3 Mar 2021 05:50:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbcLGSGAMoVo1ZYEmWtueGBBxdscyBK2uabBob9sB4uCFQObWskCRG9KWPHorY+zMx973N X-Received: by 2002:a17:906:e2d4:: with SMTP id gr20mr3477609ejb.432.1614779413752; Wed, 03 Mar 2021 05:50:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614779413; cv=none; d=google.com; s=arc-20160816; b=b4AOnoUv37i+wAOVISMXN4JXRbxfgd9Ozr3iMp6O3KTvVPOQoZHfck/dJ5utugvFty ZbYpBOIh2zKBKEz92NTGs3MSyIeNPzrEbHVM9MgD5NoPwP55YZtXHaLhHHt4mRZKqgYw Vhw1mZ4ybER1xoSJwRWCuy+zoUtizvHm+4Omn2wS1OfwYJ08qIgORCVbWAqRhQiuWIfB xG8WBJg75F5hZJoqP54/zqp8WUpPJOssYvAYobVKhG37Yht5tKfMQZmj1RGwOL/rgMBD nTyL/84sXxYeAs0SvVu6ZU1dqxkNdpILrbmjPww3WeFdIsQXj65lHf37pWmnctCgeSrA lEHg== 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=T9/K0S85qID4yj6wZrj6Ti7EHPuzwdF3oviC6xwYTzA=; b=mnsBDcU+d8eFnFLQsHZ1N15fv830PZ0fs0F6FCpF26utfEgc0Dg1joVjwF+GiHEzeL hAToFX3ImQ346c5e20L+e7ku8PPtLJkasL7F7hhB9JQ5DRQtSWeXQTxEQWKPiAxzyWhR HI5G9CfXkeKdo1Ck2Dl4JoMBi/Beb/zBjYWrd6vDEzZEHWdOx9CKpl/KAph1FQTaFqDB heC4UOTn2JiyxdWlPfrxZvwG7ITjL6I+UTu5wh+K7vqbbkP977dCIKNbjb7X/k2kVBh1 LCsndSkRZHF1sMm3Ux7CnzzDfW0ilJwsQj8XDc841eemixcY9jUtfUxRz7/0DRk7vYlU iIHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bbp88d+a; 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 p17si6034938ejr.388.2021.03.03.05.49.32; Wed, 03 Mar 2021 05:50:13 -0800 (PST) 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=bbp88d+a; 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 S242563AbhCAT6p (ORCPT + 99 others); Mon, 1 Mar 2021 14:58:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:55744 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236652AbhCAQ6b (ORCPT ); Mon, 1 Mar 2021 11:58:31 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id CC05264DE8; Mon, 1 Mar 2021 16:37:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614616623; bh=CWi+XpQQMlRwddXt0ntRHIpxYRl+O2snV1ZSwFvDal0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bbp88d+abQlngDYum72UFYXEyUrgEbrJuRV1bUwxpCGPm1TG66+Xwl7TyB03hpOm2 n8gFNUMfOyqNRbOe0LUyyWKqcnckH1ZxsgBvq3+PMv0i35MI7JVPtdHMiXe+Sr6PbX sUA8W+mNZmGlKgAl/oDTGeNPa3DNRPSjlzfwK/zs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe JAILLET , Viresh Kumar , Sasha Levin Subject: [PATCH 4.19 039/247] cpufreq: brcmstb-avs-cpufreq: Free resources in error path Date: Mon, 1 Mar 2021 17:10:59 +0100 Message-Id: <20210301161033.595842430@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@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: Christophe JAILLET [ Upstream commit 05f456286fd489558c72a4711d22a5612c965685 ] If 'cpufreq_register_driver()' fails, we must release the resources allocated in 'brcm_avs_prepare_init()' as already done in the remove function. To do that, introduce a new function 'brcm_avs_prepare_uninit()' in order to avoid code duplication. This also makes the code more readable (IMHO). Fixes: de322e085995 ("cpufreq: brcmstb-avs-cpufreq: AVS CPUfreq driver for Broadcom STB SoCs") Signed-off-by: Christophe JAILLET [ Viresh: Updated Subject ] Signed-off-by: Viresh Kumar Signed-off-by: Sasha Levin --- drivers/cpufreq/brcmstb-avs-cpufreq.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c index 77b0e5d0fb134..1514c9846c5d5 100644 --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c @@ -566,6 +566,16 @@ unmap_base: return ret; } +static void brcm_avs_prepare_uninit(struct platform_device *pdev) +{ + struct private_data *priv; + + priv = platform_get_drvdata(pdev); + + iounmap(priv->avs_intr_base); + iounmap(priv->base); +} + static int brcm_avs_cpufreq_init(struct cpufreq_policy *policy) { struct cpufreq_frequency_table *freq_table; @@ -701,21 +711,22 @@ static int brcm_avs_cpufreq_probe(struct platform_device *pdev) brcm_avs_driver.driver_data = pdev; - return cpufreq_register_driver(&brcm_avs_driver); + ret = cpufreq_register_driver(&brcm_avs_driver); + if (ret) + brcm_avs_prepare_uninit(pdev); + + return ret; } static int brcm_avs_cpufreq_remove(struct platform_device *pdev) { - struct private_data *priv; int ret; ret = cpufreq_unregister_driver(&brcm_avs_driver); if (ret) return ret; - priv = platform_get_drvdata(pdev); - iounmap(priv->base); - iounmap(priv->avs_intr_base); + brcm_avs_prepare_uninit(pdev); return 0; } -- 2.27.0