Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2907125iog; Mon, 27 Jun 2022 05:31:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uOirBJGCw4kqhO2NM5lOHRtSxdsMiJh34izvLCGLzt3tMXqKoJtezmPPNVPZckZv9xzJlK X-Received: by 2002:a17:907:2d22:b0:726:34e6:52f6 with SMTP id gs34-20020a1709072d2200b0072634e652f6mr12064203ejc.371.1656333109120; Mon, 27 Jun 2022 05:31:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656333109; cv=none; d=google.com; s=arc-20160816; b=fZPud8Xv906/XzmU08YPVlTOIYlsqcIEuGlGiTMES8hEKUCnpu2Z+OQPut+lMiQUTe XWqQZsrcQFCYB6QORTcRKAH4CCLEoMAHxkMv6kaZNO0g4puMTRzg1tcJraMpRxf3yvc2 PA7WR0BAA/b5IsnkHhuf9SZvUZrf66rlwG/A1Y3x8OPqwCQVU4nrGxUVIwLYwoU8kr82 A7rlDep0OPfDq9p/we6EG0Bv5Jvz5YP0gEhdBMINcS/8xbrl3smIjtVWJMDcPRE1vVHd NkNMAxg0lgtewrKc52kCbE1QwbX6tX/OFr9cB9XcbgLcWVEDMnbcrDuzGbL6Su7NghGE OGMQ== 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=2gYWfF/UmAQ8emK2xwhyfujJcaKcSHrZyHNy5nP4eNE=; b=Ku6UctbK2l69oRz8UKFIHsLDVR7IKde2J7l14tBFk2UtmBthsIEmX0fZ3Y630jpwPH NSL2vyXX5prKC2XZmNBb6EmCz7cORjWz3PdZyVJxLv4g/Mv+P5hAT53nBfyN5UOKJWnG k06KrNehBF6JkDZy1B/POG7yl7OylXVE1lEXTv61f4vQIeCLZdXcmTlkaQuacu2JbRUf 8pSGamnyWnrgBkrvT7TWiBDQ5CHTe9kxD7+v2HZLbwFL5DbNkFSWOvcGD7DyoqKsKEgg XFXcie3Yy7MZnO7X9icCOu6TmZM18pEBzBGyg+/RdtzRDoRoNMjIYgFJoOKyOmveRniC 4fnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0K8q1l0U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd39-20020a1709076e2700b0070dcedd6ca2si7368588ejc.713.2022.06.27.05.31.24; Mon, 27 Jun 2022 05:31:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0K8q1l0U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S239519AbiF0MAA (ORCPT + 99 others); Mon, 27 Jun 2022 08:00:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238860AbiF0Lwo (ORCPT ); Mon, 27 Jun 2022 07:52:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BE38DED6; Mon, 27 Jun 2022 04:46:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0FD0461187; Mon, 27 Jun 2022 11:46:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BDDBC3411D; Mon, 27 Jun 2022 11:46:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656330364; bh=fjO+gy8E13zpEMADm2t3CoBV0cHGMWdxR1twvteRKVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0K8q1l0UGZeMC1pbacQUzyTiJhu9ApLg0yZLkehrNgV46S5Ocjn6gp4ZVroZBfHUQ MHihUnnuOzUyXOJUYZY1hTfgjwlpT262d3lDdRWzADYH7hRVhrtC0mBaRFC5CzJJFS 04YsL0xAFbW+ji1COC+TE42i31CxBy6Mc5SomfFk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miaoqian Lin , Lukasz Luba , Krzysztof Kozlowski Subject: [PATCH 5.18 171/181] memory: samsung: exynos5422-dmc: Fix refcount leak in of_get_dram_timings Date: Mon, 27 Jun 2022 13:22:24 +0200 Message-Id: <20220627111949.644119087@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627111944.553492442@linuxfoundation.org> References: <20220627111944.553492442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miaoqian Lin commit 1332661e09304b7b8e84e5edc11811ba08d12abe upstream. of_parse_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. This function doesn't call of_node_put() in some error paths. To unify the structure, Add put_node label and goto it on errors. Fixes: 6e7674c3c6df ("memory: Add DMC driver for Exynos5422") Signed-off-by: Miaoqian Lin Reviewed-by: Lukasz Luba Link: https://lore.kernel.org/r/20220602041721.64348-1-linmq006@gmail.com Signed-off-by: Krzysztof Kozlowski Signed-off-by: Greg Kroah-Hartman --- drivers/memory/samsung/exynos5422-dmc.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) --- a/drivers/memory/samsung/exynos5422-dmc.c +++ b/drivers/memory/samsung/exynos5422-dmc.c @@ -1187,33 +1187,39 @@ static int of_get_dram_timings(struct ex dmc->timing_row = devm_kmalloc_array(dmc->dev, TIMING_COUNT, sizeof(u32), GFP_KERNEL); - if (!dmc->timing_row) - return -ENOMEM; + if (!dmc->timing_row) { + ret = -ENOMEM; + goto put_node; + } dmc->timing_data = devm_kmalloc_array(dmc->dev, TIMING_COUNT, sizeof(u32), GFP_KERNEL); - if (!dmc->timing_data) - return -ENOMEM; + if (!dmc->timing_data) { + ret = -ENOMEM; + goto put_node; + } dmc->timing_power = devm_kmalloc_array(dmc->dev, TIMING_COUNT, sizeof(u32), GFP_KERNEL); - if (!dmc->timing_power) - return -ENOMEM; + if (!dmc->timing_power) { + ret = -ENOMEM; + goto put_node; + } dmc->timings = of_lpddr3_get_ddr_timings(np_ddr, dmc->dev, DDR_TYPE_LPDDR3, &dmc->timings_arr_size); if (!dmc->timings) { - of_node_put(np_ddr); dev_warn(dmc->dev, "could not get timings from DT\n"); - return -EINVAL; + ret = -EINVAL; + goto put_node; } dmc->min_tck = of_lpddr3_get_min_tck(np_ddr, dmc->dev); if (!dmc->min_tck) { - of_node_put(np_ddr); dev_warn(dmc->dev, "could not get tck from DT\n"); - return -EINVAL; + ret = -EINVAL; + goto put_node; } /* Sorted array of OPPs with frequency ascending */ @@ -1227,13 +1233,14 @@ static int of_get_dram_timings(struct ex clk_period_ps); } - of_node_put(np_ddr); /* Take the highest frequency's timings as 'bypass' */ dmc->bypass_timing_row = dmc->timing_row[idx - 1]; dmc->bypass_timing_data = dmc->timing_data[idx - 1]; dmc->bypass_timing_power = dmc->timing_power[idx - 1]; +put_node: + of_node_put(np_ddr); return ret; }