Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2925894iog; Mon, 27 Jun 2022 05:55:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vKlKGHdJRk2ydYPZQPLkRag+j7KjQOSvn63SCQpK/DGJP0tIFuqiGPZF2wPyKIpkpVe5ni X-Received: by 2002:a17:902:c944:b0:16a:3ed0:e60c with SMTP id i4-20020a170902c94400b0016a3ed0e60cmr15108138pla.51.1656334552838; Mon, 27 Jun 2022 05:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656334552; cv=none; d=google.com; s=arc-20160816; b=S25Lp781Tsp4OJdi7Izn/QarYWs2qoeJzqpJ+OfXa96lSC32lf3WQJDqyTqykZhK7Y JM6ZWLpwa9iExNNQbWUVpYDXuqpUJ3rPNHzafEb6OCoVDHAPclnE26jlWH3Tiu1EAskr +7Z/TiLrFIGxjPDgE2KYaQwfQgcAeUZ7dVuUn9ZnkmPVtcLWzgjTC7TyemTlF2+SLHli Ko7BC/AOZu4dsAFYnc+nNSVxpFjinOvWZzfg8r7yu+oV0TY0W55BQpOA5nksZxTwxwq8 LT0P8LNzfgJr+iVbAhgyb0CRucP03Fe52CRHw4UayQ5bRGYMImPkgqi4JRSPidovFwDi /RaA== 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=ugzuyZlrUKHmKSOqFtDCn2hA95vs/4FbbuQ4NbUq0DEqNQd8kw5KuEIwBPIikxsgpJ RD1YHp5EBjO6+RA2+oGOzosYb3ZYvZNCBLPYXp5Hups0ZnVUIm1WuGPbT+8PBT0fYOVw PGElTsDwin927IAfKvZT864mmZ3OiO0zKXr5Zil8EDvLOyNtWT+nwas3smc9xhrNZn9V gU75txpZEIOw/FyhabjcCxystIl58Vw5tpdCoGuxbcbwA+FqDkufjV8SAEpu0lp0hqdu vNRWlnW1+5cOpBweTLMGu69XuFXiGXEbMAmJgD8EVDm3S7GYQW7N0+rp4LQJkKMa901R rjGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TLXfOMcf; 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 n2-20020a63e042000000b003fc88542b01si11327603pgj.208.2022.06.27.05.55.38; Mon, 27 Jun 2022 05:55:52 -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=TLXfOMcf; 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 S237526AbiF0Lpd (ORCPT + 99 others); Mon, 27 Jun 2022 07:45:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237426AbiF0Lmu (ORCPT ); Mon, 27 Jun 2022 07:42:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CD13F64; Mon, 27 Jun 2022 04:37:43 -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 DC1F760C98; Mon, 27 Jun 2022 11:37:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D731BC3411D; Mon, 27 Jun 2022 11:37:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656329862; bh=fjO+gy8E13zpEMADm2t3CoBV0cHGMWdxR1twvteRKVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TLXfOMcf576RWs5HsHaqXN7cLiqe4xymkIuiYtbk1hLWSSKGPGcW8dDPwp3p6S5gn HmAIT/eDxAr/f+ddTpM3z/xG/U10ADgE4NPOHD9FSXVTNGngA4bARuoxWQuoKtZ/Di /ctcHKboED1q8jG2VcfTU1OzX3y175gKKe1D6g5E= 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.15 127/135] memory: samsung: exynos5422-dmc: Fix refcount leak in of_get_dram_timings Date: Mon, 27 Jun 2022 13:22:14 +0200 Message-Id: <20220627111941.838407231@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627111938.151743692@linuxfoundation.org> References: <20220627111938.151743692@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; }