From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B08DC33C99 for ; Wed, 13 Nov 2019 23:21:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BCA84206D3 for ; Wed, 13 Nov 2019 23:21:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726489AbfKMXVn (ORCPT ); Wed, 13 Nov 2019 18:21:43 -0500 Received: from inva020.nxp.com ([92.121.34.13]:56004 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727059AbfKMXVm (ORCPT ); Wed, 13 Nov 2019 18:21:42 -0500 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id A1E051A03DB; Thu, 14 Nov 2019 00:21:40 +0100 (CET) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 940B61A0117; Thu, 14 Nov 2019 00:21:40 +0100 (CET) Received: from fsr-ub1864-112.ea.freescale.net (fsr-ub1864-112.ea.freescale.net [10.171.82.98]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id 245B8205D5; Thu, 14 Nov 2019 00:21:40 +0100 (CET) From: Leonard Crestez To: Chanwoo Choi , MyungJoo Ham Cc: Kyungmin Park , "Rafael J. Wysocki" , Matthias Kaehlcke , =?UTF-8?q?Artur=20=C5=9Awigo=C5=84?= , Georgi Djakov , Viresh Kumar , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com Subject: [PATCH 4/5] PM / devfreq: Don't use devm on parent device Date: Thu, 14 Nov 2019 01:21:34 +0200 Message-Id: <68ebb238c57c5a7f7c6f62860ef02b033e2e21be.1573686315.git.leonard.crestez@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In theory a driver can call devfreq_add_device, get an error in return and still probe succesfuly. If this happens the freq_table allocated by set_freq_table is effectively leaked. Now that device_initialize is called early inside devfreq_add_device we can use devm on devfreq->dev inside set_freq_table instead. Since that's always freed if devfreq_add_device fails there is no need to devm_kfree on any path. Signed-off-by: Leonard Crestez --- drivers/devfreq/devfreq.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index b38e98853fda..2a035374ae74 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -166,11 +166,11 @@ static int set_freq_table(struct devfreq *devfreq) count = dev_pm_opp_get_opp_count(devfreq->dev.parent); if (count <= 0) return -EINVAL; profile->max_state = count; - profile->freq_table = devm_kcalloc(devfreq->dev.parent, + profile->freq_table = devm_kcalloc(&devfreq->dev, profile->max_state, sizeof(*profile->freq_table), GFP_KERNEL); if (!profile->freq_table) { profile->max_state = 0; @@ -178,11 +178,10 @@ static int set_freq_table(struct devfreq *devfreq) } for (i = 0, freq = 0; i < profile->max_state; i++, freq++) { opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &freq); if (IS_ERR(opp)) { - devm_kfree(devfreq->dev.parent, profile->freq_table); profile->max_state = 0; return PTR_ERR(opp); } dev_pm_opp_put(opp); profile->freq_table[i] = freq; -- 2.17.1