From patchwork Wed Nov 13 23:21:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Crestez X-Patchwork-Id: 11242877 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 50675138C for ; Wed, 13 Nov 2019 23:22:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3B7A8206D3 for ; Wed, 13 Nov 2019 23:22:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="YMDciayV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B7A8206D3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=dmkSQOWRGroj6HogIqjU9CrTLulOaK0r3zG3+1iu+L8=; b=YMDciayVcyTC5J4KXr3st4og/z OJIvW9iKpbwh5BFM/N5MVT2Xwcotxw6irTlG5H4hq/Vcy5VFWSTUttdGOz6qiw2j2fLwULUgD7IMh QEsPPSaChIg43C8nqmF0IatnA1X6QhNSGX+qeDOApSn6YWJIqT/phEYj5C8Y6oXCOH74q/ht2rE+u Pbj6eoPdJxZDEkQgNrgtIwUE5i3kKk91EXz7aJoLy5VhtaVW306ov5EkUr0p92dxdArTO/7IrLquZ JvJKzR/KYk6eyA+wwopfd8e0/jEWNAhIBf/12dKkfKQph9FlaNraamzYyPrxa2Yqsvmud939+t1Rq 6I/EjN/Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iV1yN-00007k-Oi; Wed, 13 Nov 2019 23:22:51 +0000 Received: from inva020.nxp.com ([92.121.34.13]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iV1xG-0007QZ-RD for linux-arm-kernel@lists.infradead.org; Wed, 13 Nov 2019 23:21:45 +0000 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 19D301A03DE; Thu, 14 Nov 2019 00:21:39 +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 0AB331A0A8B; Thu, 14 Nov 2019 00:21:39 +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 8D9BB205D5; Thu, 14 Nov 2019 00:21:38 +0100 (CET) From: Leonard Crestez To: Chanwoo Choi , MyungJoo Ham Subject: [PATCH 1/5] PM / devfreq: Don't fail devfreq_dev_release if not in list Date: Thu, 14 Nov 2019 01:21:31 +0200 Message-Id: <85684020f25ce186e3383d6bd67a15c54f930316.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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191113_152143_033994_63D356E2 X-CRM114-Status: GOOD ( 12.51 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [92.121.34.13 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?QXJ0dXIgxZp3aWdvxYQ=?= , linux-pm@vger.kernel.org, Viresh Kumar , "Rafael J. Wysocki" , Kyungmin Park , Matthias Kaehlcke , linux-imx@nxp.com, Georgi Djakov , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Right now devfreq_dev_release will print a warning and abort the rest of the cleanup if the devfreq instance is not part of the global devfreq_list. But this is a valid scenario, for example it can happen if the governor can't be found or on any other init error that happens after device_register. Initialize devfreq->node to an empty list head in devfreq_add_device so that list_del becomes a safe noop inside devfreq_dev_release and we can continue the rest of the cleanup. Signed-off-by: Leonard Crestez Reviewed-by: Matthias Kaehlcke Reviewed-by: Chanwoo Choi --- drivers/devfreq/devfreq.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 94fb8e821e12..27af1b95fd23 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -635,15 +635,10 @@ static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type, static void devfreq_dev_release(struct device *dev) { struct devfreq *devfreq = to_devfreq(dev); mutex_lock(&devfreq_list_lock); - if (IS_ERR(find_device_devfreq(devfreq->dev.parent))) { - mutex_unlock(&devfreq_list_lock); - dev_warn(&devfreq->dev, "releasing devfreq which doesn't exist\n"); - return; - } list_del(&devfreq->node); mutex_unlock(&devfreq_list_lock); if (devfreq->profile->exit) devfreq->profile->exit(devfreq->dev.parent); @@ -694,10 +689,11 @@ struct devfreq *devfreq_add_device(struct device *dev, mutex_init(&devfreq->lock); mutex_lock(&devfreq->lock); devfreq->dev.parent = dev; devfreq->dev.class = devfreq_class; devfreq->dev.release = devfreq_dev_release; + INIT_LIST_HEAD(&devfreq->node); devfreq->profile = profile; strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN); devfreq->previous_freq = profile->initial_freq; devfreq->last_status.current_frequency = profile->initial_freq; devfreq->data = data; From patchwork Wed Nov 13 23:21:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Crestez X-Patchwork-Id: 11242871 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 35F56138C for ; Wed, 13 Nov 2019 23:22:31 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0253420643 for ; Wed, 13 Nov 2019 23:22:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="sNUnkW1T" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0253420643 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Yh9+TjTWAbJ+E1PPoDSj+hvsiutLJvO5EpZIYkqB3Wk=; b=sNUnkW1TTQvqlZX2MeBEzChinp hSFsKiHRRjWU39aEKEgJULuhoLBncTMAKVtTKY44STAnw6hTUwtC/JWjYGDLwyBEKotZtaB1Kkq/y jllax5EtLwniXuhC743R7ChRPMfYh5S+5gS1UvVAxcn7etOfdOUvQ4An/cDAL/WEPkWexko6eWGqe nUQTrIbkb1NgSHtvKMszOfI6alKICY0yTxR01ugQ4TONAXaE+fiPDmPowGd6taWQ0cvXKOssdf2Pl olpjsyQUzKjOihqdIyA0PA+gB7N1c6OZdpyVc617lfckibQrqKxpOX3Kn8XKxiaEOSONlhSlFxMAG 3ht/83qA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iV1xx-00084P-7Y; Wed, 13 Nov 2019 23:22:25 +0000 Received: from inva020.nxp.com ([92.121.34.13]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iV1xH-0007Qw-AE for linux-arm-kernel@lists.infradead.org; Wed, 13 Nov 2019 23:21:45 +0000 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 968A81A0A90; Thu, 14 Nov 2019 00:21:39 +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 88E851A0A8B; Thu, 14 Nov 2019 00:21:39 +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 19E2D205D5; Thu, 14 Nov 2019 00:21:39 +0100 (CET) From: Leonard Crestez To: Chanwoo Choi , MyungJoo Ham Subject: [PATCH 2/5] PM / devfreq: Split device_register usage Date: Thu, 14 Nov 2019 01:21:32 +0200 Message-Id: <85ccf6afe5db556c610ce2b47ccc38132b6671f6.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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191113_152143_491052_BDEF1165 X-CRM114-Status: GOOD ( 11.23 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [92.121.34.13 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?QXJ0dXIgxZp3aWdvxYQ=?= , linux-pm@vger.kernel.org, Viresh Kumar , "Rafael J. Wysocki" , Kyungmin Park , Matthias Kaehlcke , linux-imx@nxp.com, Georgi Djakov , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Splitting device_register into device_initialize and device_add allows devm-based allocations to be performed before device_add. It also simplifies error paths in devfreq_add_device: just call put_device instead of duplicating parts of devfreq_dev_release. Signed-off-by: Leonard Crestez --- drivers/devfreq/devfreq.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 27af1b95fd23..b89a82382536 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -689,10 +689,11 @@ struct devfreq *devfreq_add_device(struct device *dev, mutex_init(&devfreq->lock); mutex_lock(&devfreq->lock); devfreq->dev.parent = dev; devfreq->dev.class = devfreq_class; devfreq->dev.release = devfreq_dev_release; + device_initialize(&devfreq->dev); INIT_LIST_HEAD(&devfreq->node); devfreq->profile = profile; strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN); devfreq->previous_freq = profile->initial_freq; devfreq->last_status.current_frequency = profile->initial_freq; @@ -726,15 +727,14 @@ struct devfreq *devfreq_add_device(struct device *dev, devfreq->suspend_freq = dev_pm_opp_get_suspend_opp_freq(dev); atomic_set(&devfreq->suspend_count, 0); dev_set_name(&devfreq->dev, "devfreq%d", atomic_inc_return(&devfreq_no)); - err = device_register(&devfreq->dev); + err = device_add(&devfreq->dev); if (err) { mutex_unlock(&devfreq->lock); - put_device(&devfreq->dev); - goto err_out; + goto err_dev; } devfreq->trans_table = devm_kzalloc(&devfreq->dev, array3_size(sizeof(unsigned int), devfreq->profile->max_state, @@ -789,13 +789,13 @@ struct devfreq *devfreq_add_device(struct device *dev, err_init: mutex_unlock(&devfreq_list_lock); err_devfreq: devfreq_remove_device(devfreq); - devfreq = NULL; + return ERR_PTR(err); err_dev: - kfree(devfreq); + put_device(&devfreq->dev); err_out: return ERR_PTR(err); } EXPORT_SYMBOL(devfreq_add_device); From patchwork Wed Nov 13 23:21:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Crestez X-Patchwork-Id: 11242873 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 638C61393 for ; Wed, 13 Nov 2019 23:22:41 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4E30220643 for ; Wed, 13 Nov 2019 23:22:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MHtIAnuM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E30220643 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=iZR1tCWhbChci4vUmyPUdxpsjTa6weAjoqn5ws0q0Ak=; b=MHtIAnuMjMmEweulBDDJgek75b OmshuzYYXw/6+3fqDU9J2gHGA/KVixnAfEB3llKLCCvnF7BSgTWJDo7H8ws6mNkxWBxs9r08B0Zdf BG3/Afg+euHLoln4dfcjclztawtjtKadskgW8eW16eSRFmqY99V0K5kVJ2BK+vNbw1pEnhPwsEBIq p/SUSpol/Y95T4EkZZ8GV9x2q6F2tmi58w/S7PqYIuELYjJG2uemaj/wzYftGbnnJMO0sqZidjt4e w2pHY9scAz9Xuo724vYnt2Mn0cbGZXNGHbvK5d7o0KSKFlTxR9upcrHSklsiVbZZB2xvdcH41lRKW mqXQb/mQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iV1yB-0008Ka-Kr; Wed, 13 Nov 2019 23:22:39 +0000 Received: from inva021.nxp.com ([92.121.34.21]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iV1xH-0007R4-8l for linux-arm-kernel@lists.infradead.org; Wed, 13 Nov 2019 23:21:45 +0000 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 2399D2001EB; 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 inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 15F8D200139; 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 98314205D5; Thu, 14 Nov 2019 00:21:39 +0100 (CET) From: Leonard Crestez To: Chanwoo Choi , MyungJoo Ham Subject: [PATCH 3/5] PM / devfreq: Move more initialization before registration Date: Thu, 14 Nov 2019 01:21:33 +0200 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191113_152143_443768_22B5D2DE X-CRM114-Status: GOOD ( 10.51 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [92.121.34.21 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?QXJ0dXIgxZp3aWdvxYQ=?= , linux-pm@vger.kernel.org, Viresh Kumar , "Rafael J. Wysocki" , Kyungmin Park , Matthias Kaehlcke , linux-imx@nxp.com, Georgi Djakov , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org In general it is a better to initialize an object before making it accessible externally (through device_add). This simplifies the code and makes it possible to avoid locking the partially initialized object. Signed-off-by: Leonard Crestez Reviewed-by: Matthias Kaehlcke --- drivers/devfreq/devfreq.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index b89a82382536..b38e98853fda 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -725,43 +725,43 @@ struct devfreq *devfreq_add_device(struct device *dev, devfreq->max_freq = devfreq->scaling_max_freq; devfreq->suspend_freq = dev_pm_opp_get_suspend_opp_freq(dev); atomic_set(&devfreq->suspend_count, 0); - dev_set_name(&devfreq->dev, "devfreq%d", - atomic_inc_return(&devfreq_no)); - err = device_add(&devfreq->dev); - if (err) { - mutex_unlock(&devfreq->lock); - goto err_dev; - } - devfreq->trans_table = devm_kzalloc(&devfreq->dev, array3_size(sizeof(unsigned int), devfreq->profile->max_state, devfreq->profile->max_state), GFP_KERNEL); if (!devfreq->trans_table) { mutex_unlock(&devfreq->lock); err = -ENOMEM; - goto err_devfreq; + goto err_dev; } devfreq->time_in_state = devm_kcalloc(&devfreq->dev, devfreq->profile->max_state, sizeof(unsigned long), GFP_KERNEL); if (!devfreq->time_in_state) { mutex_unlock(&devfreq->lock); err = -ENOMEM; - goto err_devfreq; + goto err_dev; } devfreq->last_stat_updated = jiffies; srcu_init_notifier_head(&devfreq->transition_notifier_list); + dev_set_name(&devfreq->dev, "devfreq%d", + atomic_inc_return(&devfreq_no)); + err = device_add(&devfreq->dev); + if (err) { + mutex_unlock(&devfreq->lock); + goto err_dev; + } + mutex_unlock(&devfreq->lock); mutex_lock(&devfreq_list_lock); governor = try_then_request_governor(devfreq->governor_name); @@ -787,11 +787,10 @@ struct devfreq *devfreq_add_device(struct device *dev, return devfreq; err_init: mutex_unlock(&devfreq_list_lock); -err_devfreq: devfreq_remove_device(devfreq); return ERR_PTR(err); err_dev: put_device(&devfreq->dev); err_out: From patchwork Wed Nov 13 23:21:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Crestez X-Patchwork-Id: 11242869 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7897F1393 for ; Wed, 13 Nov 2019 23:22:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6411C20643 for ; Wed, 13 Nov 2019 23:22:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="T/8Hfgvj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6411C20643 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=sR+2UUhtzvehImuOcgfnm038ljf69OpMO3iwFlvu4Q4=; b=T/8HfgvjzhavB1RYcTqSh8kbgm g0K+CfLhZIzmhU5gk244EwNzUN0QlXf5fjaMXpBqnsXc1oY8zJ7t2/wiDEl8ePr2GVTRCSm4/+GK0 DJ8yoaMl9kxOriHaBB3MVLMT/VRBleH0FeeKGkDFAwCLxBHzNhPU/frXcwZ7B0FwgskS6dZP+DVKz l55ke6A5YTIfJeOP8FWn494TGR2aMA/4l9M8ze07m2+IHLMkOHbWT+YL3lnrvNtfV7ABSCkd2ICUD mw5cA3RL8tPmw6/x6ZTvuACO83iZ0MpxJqkwmqxSVXzaKWYGTWJ0pZaknmBlZzDOrTXzYpYcXL5Kn ytIPgJKw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iV1xj-0007q2-QB; Wed, 13 Nov 2019 23:22:11 +0000 Received: from inva020.nxp.com ([92.121.34.13]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iV1xH-0007R5-NB for linux-arm-kernel@lists.infradead.org; Wed, 13 Nov 2019 23:21:45 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191113_152143_890857_217D5DB1 X-CRM114-Status: GOOD ( 12.65 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [92.121.34.13 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?QXJ0dXIgxZp3aWdvxYQ=?= , linux-pm@vger.kernel.org, Viresh Kumar , "Rafael J. Wysocki" , Kyungmin Park , Matthias Kaehlcke , linux-imx@nxp.com, Georgi Djakov , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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; From patchwork Wed Nov 13 23:21:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Crestez X-Patchwork-Id: 11242867 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 791CF1393 for ; Wed, 13 Nov 2019 23:22:03 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 57970206EF for ; Wed, 13 Nov 2019 23:22:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Cbw+4LqW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 57970206EF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=mVfiWJ2xO/zvGzymWlnE3yRNBEJWUn8jWVTGU7WbnQs=; b=Cbw+4LqWb/qsUwthRJD0Wi6gDE 4rd9GYeZaM3JzK4zxdK9TQgrQaGFrAEcAlth31G2hgKlQHxH2JBTVMgTracbncMo8zpc+1Rc059FR xOk/0Y+H+H4ExUgLxDCyJQGNijaF3WSZWiqzaBTI2vVitzZ+DQROC/xa2to71WB3q8Uw06eRmlWUB RS4uXVf4wCqYGAoddvsXmjL/cY9L8//Jr6TLK/vuA7adS7esm1aWgQFQQRZ6Io8/qdJt8y1qJKr0E GKn+RpGhU5YgndQrJqSvlWNbU/bqCqILkd2MuwzZIrJexGgNDA2YNNwxaTqOjq2oM1lucTibJCySu rndYSfAQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iV1xW-0007cd-MD; Wed, 13 Nov 2019 23:21:58 +0000 Received: from inva020.nxp.com ([92.121.34.13]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iV1xG-0007RA-CW for linux-arm-kernel@lists.infradead.org; Wed, 13 Nov 2019 23:21:44 +0000 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 2DC611A0A85; Thu, 14 Nov 2019 00:21:41 +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 203581A0117; Thu, 14 Nov 2019 00:21:41 +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 A3E6D205D5; Thu, 14 Nov 2019 00:21:40 +0100 (CET) From: Leonard Crestez To: Chanwoo Choi , MyungJoo Ham Subject: [PATCH 5/5] PM / devfreq: Don't take lock in devfreq_add_device Date: Thu, 14 Nov 2019 01:21:35 +0200 Message-Id: <683876312e5657ad5405f826d5ab8f09d521883d.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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191113_152142_699689_9CBC6FE2 X-CRM114-Status: UNSURE ( 9.74 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [92.121.34.13 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?QXJ0dXIgxZp3aWdvxYQ=?= , linux-pm@vger.kernel.org, Viresh Kumar , "Rafael J. Wysocki" , Kyungmin Park , Matthias Kaehlcke , linux-imx@nxp.com, Georgi Djakov , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org A device usually doesn't need to lock itself during initialization because it is not yet reachable from other threads. This simplifies the code and helps avoid recursive lock warnings. Signed-off-by: Leonard Crestez Reviewed-by: Matthias Kaehlcke Reviewed-by: Chanwoo Choi --- drivers/devfreq/devfreq.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 2a035374ae74..e1ce57902391 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -684,11 +684,10 @@ struct devfreq *devfreq_add_device(struct device *dev, err = -ENOMEM; goto err_out; } mutex_init(&devfreq->lock); - mutex_lock(&devfreq->lock); devfreq->dev.parent = dev; devfreq->dev.class = devfreq_class; devfreq->dev.release = devfreq_dev_release; device_initialize(&devfreq->dev); INIT_LIST_HEAD(&devfreq->node); @@ -698,28 +697,24 @@ struct devfreq *devfreq_add_device(struct device *dev, devfreq->last_status.current_frequency = profile->initial_freq; devfreq->data = data; devfreq->nb.notifier_call = devfreq_notifier_call; if (!devfreq->profile->max_state && !devfreq->profile->freq_table) { - mutex_unlock(&devfreq->lock); err = set_freq_table(devfreq); if (err < 0) goto err_dev; - mutex_lock(&devfreq->lock); } devfreq->scaling_min_freq = find_available_min_freq(devfreq); if (!devfreq->scaling_min_freq) { - mutex_unlock(&devfreq->lock); err = -EINVAL; goto err_dev; } devfreq->min_freq = devfreq->scaling_min_freq; devfreq->scaling_max_freq = find_available_max_freq(devfreq); if (!devfreq->scaling_max_freq) { - mutex_unlock(&devfreq->lock); err = -EINVAL; goto err_dev; } devfreq->max_freq = devfreq->scaling_max_freq; @@ -730,21 +725,19 @@ struct devfreq *devfreq_add_device(struct device *dev, array3_size(sizeof(unsigned int), devfreq->profile->max_state, devfreq->profile->max_state), GFP_KERNEL); if (!devfreq->trans_table) { - mutex_unlock(&devfreq->lock); err = -ENOMEM; goto err_dev; } devfreq->time_in_state = devm_kcalloc(&devfreq->dev, devfreq->profile->max_state, sizeof(unsigned long), GFP_KERNEL); if (!devfreq->time_in_state) { - mutex_unlock(&devfreq->lock); err = -ENOMEM; goto err_dev; } devfreq->last_stat_updated = jiffies; @@ -752,16 +745,12 @@ struct devfreq *devfreq_add_device(struct device *dev, srcu_init_notifier_head(&devfreq->transition_notifier_list); dev_set_name(&devfreq->dev, "devfreq%d", atomic_inc_return(&devfreq_no)); err = device_add(&devfreq->dev); - if (err) { - mutex_unlock(&devfreq->lock); + if (err) goto err_dev; - } - - mutex_unlock(&devfreq->lock); mutex_lock(&devfreq_list_lock); governor = try_then_request_governor(devfreq->governor_name); if (IS_ERR(governor)) {