Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2897522iog; Mon, 27 Jun 2022 05:19:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1utyd2HDa3SW9tXoXHN2IDPmhQR0XANJ3f6nMCexZYHW1i0GZMLWzXnWdXdUkHm8S9Nkntq X-Received: by 2002:a17:903:40cd:b0:16a:33e1:b52f with SMTP id t13-20020a17090340cd00b0016a33e1b52fmr14314718pld.58.1656332363667; Mon, 27 Jun 2022 05:19:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656332363; cv=none; d=google.com; s=arc-20160816; b=JWNMHMwqOq4qZxsiYewKjPs0T/bx0rqmjN69oOtHsFa7nA0PiR9ulBKW7965FPQb8n vgco228uS4auoHztP/WaDLIuiwBC7gvuvKq3iIOzDk3m7gOUeeYpKPzEy65yMFBn2Nzk ImTTGTjrzKaDsfls5zryapOiu5h78sgzhz8Hi+H/N41SK2JXDfYrKNrbEMb4BkhI+m1z gLQB8hRYTirr+XfJrGrqq5l1HYYk6jcfpMQW6SCd1DsYlpIfn39Y2bvl0n5P1MO9erEe rkmLUB9uB6F5Tu7jnIu2qf+QLZVKkBAvBgUaNI/q9Ca+kFvt6TRfc8vuUQ4E7ZXHnxdw Rayw== 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=EtmM8ZF6f52D8IqnRLCv2gq/wsqWmwwptAH9bjjLwDM=; b=xCz+zk/yijfpr/W3Or+aEwNWZ8IxC8mdqIUtEuN9qoTYQBgx4bhTpiPXHx9h7hBPDO MlzfHuyhnbDoHkELwDashEgZ9c1mLCNJ7OF730oPGd8xe0ULrwZLupq9A8xqJPqMJyzL WtT9pOu9aC2LRGv6s2qlTlkkBoV9TXZkzEfLDXBkQnIK475k4at1EJ8AJ0AuiOT1vHbm dWwlrUMm4QBtug0EZfK1gXjxW+0Gcr4mfb0I4/zb8BeSY7kcmycFsbyhxfWdzuWwZ5GL 4Q6Nl2BQPCqR0tbIJnrzHSlDy4IQNv/qD1DJUUV78drlTyGr3hie5yVSlIQY5ihHJ7V9 cvhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eVi7KYSu; 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 lk10-20020a17090b33ca00b001ed5b454a39si6532708pjb.139.2022.06.27.05.19.11; Mon, 27 Jun 2022 05:19:23 -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=eVi7KYSu; 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 S235349AbiF0L3K (ORCPT + 99 others); Mon, 27 Jun 2022 07:29:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235322AbiF0L2K (ORCPT ); Mon, 27 Jun 2022 07:28:10 -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 F20E9A189; Mon, 27 Jun 2022 04:27:19 -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 69402614A0; Mon, 27 Jun 2022 11:27:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68BC5C3411D; Mon, 27 Jun 2022 11:27:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656329238; bh=YfwcNSiIhwhdnf99HY/KHAoQytjC7vOUMwai1NvGiYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eVi7KYSurA/rH/l0ZmPAoXCtiZKoigkw+QOVruEFYtNrANMK4z1w9hMfjLppXaPfE dd6aniS+LEbeI06K8kJbluhqzpxBu4k5NCCYcM/iJdFXWKJp00jRhpq8PMYldLZdIL /9lwXYmXtR7EkYHfeGnhfhoS1Nhpi83Dk5UOuTbE= 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.10 097/102] memory: samsung: exynos5422-dmc: Fix refcount leak in of_get_dram_timings Date: Mon, 27 Jun 2022 13:21:48 +0200 Message-Id: <20220627111936.343926340@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627111933.455024953@linuxfoundation.org> References: <20220627111933.455024953@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 @@ -1192,33 +1192,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 */ @@ -1232,13 +1238,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; }