Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp969909yba; Sun, 31 Mar 2019 18:40:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJenpbWFVoH74BW9qO9Hp9WHnHAVMh8ky57zc6EKgdZKK4XiZHYpSddiYuvPKVtzEdiAyM X-Received: by 2002:a63:88c3:: with SMTP id l186mr58746431pgd.148.1554082840699; Sun, 31 Mar 2019 18:40:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554082840; cv=none; d=google.com; s=arc-20160816; b=sW8MMgwnDXjefvw4NmyiUDGCFwH7P8h+qT3JDBJjUhZQj1X/YvZIzkquFfN9ZwPhpD qwamr0+Kourpbg3m4QLCSaddrFO0Ufyyrr5AHU7ygX5Pt3i4/J1HR29Inuz6Lo1zpq3s JMdoKRbd63xgxsOtd6DzVGytLn+H63gsoyqFHD1oXmEyiU1HcyBUvNBwS7EeetsQxoh6 imJt/vsCa7zXEx0I9Cc1CGiHaSlfL5millCqBcJCAhNyjmuUPdRKrIHylestU+Fye4gq CatJUgQj+savKJcW1+Kar5lzco7LDRqT1wwK1P0jakPzTdVwb5WurI8arhLj407Cd9Ji sCyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=okXrFQLc/7SSsNsQBiv9KHYasuhyVgc6Es+Oo6hT81o=; b=MR3oI8yV+6Q4DUdwkyGb5ZjE2tIlhCMfvHWJxwpb2VYD5ifQ5Oz6KJUd5G5TIj3Kww Vv0pmFhrmgSetkabcwTtCLw+uCmN6waZThwTRsUpOUd/nIrKrNEsf1kIffyi3KErXUGn pGeOatFj1xTGB/NSXEWk7ly/gttGOxaNeJzPJ1rl7/0eWL+dIVg48vbwAqWfZPBtZC8S /kgWs15Hl+W41x5AqWHaONcDWbOgpcMe+NUs5QxFjBN8755tDKBYoaJTDYpfGHJ9oSpn r0vxDDRYCgEjSi8uzAtaKEXW/wqB/Uw54fFvRiagxVSFPXujA56OdH1SRtJtdI6uEtcb XH8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p6si7524246plo.4.2019.03.31.18.40.25; Sun, 31 Mar 2019 18:40:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731751AbfDABi2 (ORCPT + 99 others); Sun, 31 Mar 2019 21:38:28 -0400 Received: from mxhk.zte.com.cn ([63.217.80.70]:42128 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731692AbfDABiZ (ORCPT ); Sun, 31 Mar 2019 21:38:25 -0400 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 7AA7BAFB783FF5A707DC; Mon, 1 Apr 2019 09:38:22 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id x311cGG2061244; Mon, 1 Apr 2019 09:38:16 +0800 (GMT-8) (envelope-from wen.yang99@zte.com.cn) Received: from fox-host8.localdomain ([10.74.120.8]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2019040109382016-7035260 ; Mon, 1 Apr 2019 09:38:20 +0800 From: Wen Yang To: linux-kernel@vger.kernel.org Cc: wang.yi59@zte.com.cn, Wen Yang , "Rafael J. Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org Subject: [PATCH 3/7] cpufreq: kirkwood: fix possible object reference leak Date: Mon, 1 Apr 2019 09:37:50 +0800 Message-Id: <1554082674-2049-4-git-send-email-wen.yang99@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1554082674-2049-1-git-send-email-wen.yang99@zte.com.cn> References: <1554082674-2049-1-git-send-email-wen.yang99@zte.com.cn> X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2019-04-01 09:38:20, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2019-04-01 09:38:17, Serialize complete at 2019-04-01 09:38:17 X-MAIL: mse01.zte.com.cn x311cGG2061244 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The call to of_get_child_by_name returns a node pointer with refcount incremented thus it must be explicitly decremented after the last usage. Detected by coccinelle with the following warnings: ./drivers/cpufreq/kirkwood-cpufreq.c:127:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 118, but without a corresponding object release within this function. ./drivers/cpufreq/kirkwood-cpufreq.c:133:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 118, but without a corresponding object release within this function. and also do some cleanup: - of_node_put(np); - np = NULL; ... of_node_put(np); Signed-off-by: Wen Yang Cc: "Rafael J. Wysocki" Cc: Viresh Kumar Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/cpufreq/kirkwood-cpufreq.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/cpufreq/kirkwood-cpufreq.c b/drivers/cpufreq/kirkwood-cpufreq.c index c2dd43f..8d63a6dc 100644 --- a/drivers/cpufreq/kirkwood-cpufreq.c +++ b/drivers/cpufreq/kirkwood-cpufreq.c @@ -124,13 +124,14 @@ static int kirkwood_cpufreq_probe(struct platform_device *pdev) priv.cpu_clk = of_clk_get_by_name(np, "cpu_clk"); if (IS_ERR(priv.cpu_clk)) { dev_err(priv.dev, "Unable to get cpuclk\n"); - return PTR_ERR(priv.cpu_clk); + err = PTR_ERR(priv.cpu_clk); + goto out_node; } err = clk_prepare_enable(priv.cpu_clk); if (err) { dev_err(priv.dev, "Unable to prepare cpuclk\n"); - return err; + goto out_node; } kirkwood_freq_table[0].frequency = clk_get_rate(priv.cpu_clk) / 1000; @@ -161,20 +162,22 @@ static int kirkwood_cpufreq_probe(struct platform_device *pdev) goto out_ddr; } - of_node_put(np); - np = NULL; - err = cpufreq_register_driver(&kirkwood_cpufreq_driver); - if (!err) - return 0; + if (err) { + dev_err(priv.dev, "Failed to register cpufreq driver\n"); + goto out_powersave; + } - dev_err(priv.dev, "Failed to register cpufreq driver\n"); + of_node_put(np); + return 0; +out_powersave: clk_disable_unprepare(priv.powersave_clk); out_ddr: clk_disable_unprepare(priv.ddr_clk); out_cpu: clk_disable_unprepare(priv.cpu_clk); +out_node: of_node_put(np); return err; -- 2.9.5