From patchwork Thu Mar 27 19:59:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmVuY2UgQ3PDs2vDoXM=?= X-Patchwork-Id: 14031409 Received: from fw2.prolan.hu (fw2.prolan.hu [193.68.50.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BF0214AD3F; Thu, 27 Mar 2025 19:59:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.68.50.107 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743105591; cv=none; b=dgxIffPnq1zjK34ZgXA8WmUK+qRkUJio9+LxTE5ouTE0boM82O0dibvKUcokEmUyGXpUnXH/+DXewMLzS1vbKkCOApRTRkxTSvfzoswOdF3RNKlMNHFFgsc6kGmYRSLPSdHA61i9TvVugX/noAs9Woi5Xf/L0XMppf/OqC2wrGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743105591; c=relaxed/simple; bh=1BXguGZr/Wg1Ht8tzff1nRRhYEjT88oQSWz5Kz7gSYE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OxZ4z4nwv8wf2AbeyfGgy/OmYP/A5pdk6BlvZHoOMfoAyj7x/5g8dQcifwxpF/iGx0g+ELe0YrlVu5PsY785lUpzB58pmCjWMI3/+kysGdMOPDRF0+rvhz1JA9cgMR/6D5GTvFClhrSijWD4iD8ZpTDS0o/iJVVWaLGwKhr5zzY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=prolan.hu; spf=pass smtp.mailfrom=prolan.hu; dkim=pass (4096-bit key) header.d=prolan.hu header.i=@prolan.hu header.b=lj+EgHPO; arc=none smtp.client-ip=193.68.50.107 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=prolan.hu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=prolan.hu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=prolan.hu header.i=@prolan.hu header.b="lj+EgHPO" Received: from proxmox-mailgw.intranet.prolan.hu (localhost.localdomain [127.0.0.1]) by proxmox-mailgw.intranet.prolan.hu (Proxmox) with ESMTP id 2B198A0796; Thu, 27 Mar 2025 20:59:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prolan.hu; h=cc :cc:content-transfer-encoding:content-type:content-type:date :from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=mail; bh=at+hNP+zJasqRLUlhhQ8 KK364acevQO5hKQ1zN6QvNA=; b=lj+EgHPOyKfKZVPYf+z9mdJsS28/nWckJgC2 A+Pt9LrM4ID7jPKtYvpO+DDx2pLi//FzizvT5aVChU6f8/YTosj/aP29DbQkpIwV 14UtSrdRMyeww4P5EJAZo6TFsoKXnhkKuoP+kkyAKHgJDA09ij3OT+nTcEKD0z/h QikfCFuaBd2gIgH2KWSlC52xy5G7Us0Ms3NwaIcOkFeNKUeZAExZwUzaJXt/7FN4 1ANGvSDSvTenWPCsDZrrj+7cv9Ohkebpf14bncWH4VwuJs+VWQsFzc3OwALu2LNU 6YjiU/hl4CT15mhBciSPWhkewIEwZ3g8VgvHalNSCJB4bzocYbue7vL8qXlt/mMP AcB74PPmSsiUqOLO7vBdZ0yobJ5feMChB+aosxHOlOOKD333wOycH5U5lZ3IXFnK 8nwpK3IzPKDvVSCRfMM0TRAe3bWRty8ueTZnLAu8nVVSMNooVk6rewh0Ve4mpG9F HUX92NS6XKvczdQ4ExYhSv/Ygh8dr+QwRyOuUFtjDBa4POcgN1yYgcUTM0gzIgPC Q+A63JyURGcmlPPf/bFyqOJZLSFgef8DGrBwx5AhDnoSmrniJRSiGts9eWWnokNV 57AmMKascKHPsI05TeKInSPh+TzhpKYDRihRQQ1XqGkfNw87VYFi5LAoW/LmN/W3 HPIY+uk= From: =?utf-8?b?QmVuY2UgQ3PDs2vDoXM=?= To: , , =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= , "Varshini Rajendran" , Tudor Ambarus , Mark Brown , , CC: "Rafael J. Wysocki" , Len Brown , Pavel Machek , Greg Kroah-Hartman , Danilo Krummrich , Alexander Dahl , "Nicolas Ferre" , Alexandre Belloni , Claudiu Beznea , Pavel Machek Subject: [PATCH v6 1/2] pm: runtime: Add new devm functions Date: Thu, 27 Mar 2025 20:59:26 +0100 Message-ID: <20250327195928.680771-3-csokas.bence@prolan.hu> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250327195928.680771-2-csokas.bence@prolan.hu> References: <20250327195928.680771-2-csokas.bence@prolan.hu> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ESET-AS: R=OK;S=0;OP=CALC;TIME=1743105584;VERSION=7987;MC=800905746;ID=112015;TRN=0;CRV=0;IPC=;SP=0;SIPS=0;PI=3;F=0 X-ESET-Antispam: OK X-EsetResult: clean, is OK X-EsetId: 37303A2980D948526C776A Add `devm_pm_runtime_set_active_enabled()` and `devm_pm_runtime_get_noresume()` for simplifying common cases in drivers. Signed-off-by: Bence Csókás --- drivers/base/power/runtime.c | 44 ++++++++++++++++++++++++++++++++++++ include/linux/pm_runtime.h | 4 ++++ 2 files changed, 48 insertions(+) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 0e127b0329c0..205a4f8828b0 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1568,6 +1568,32 @@ void pm_runtime_enable(struct device *dev) } EXPORT_SYMBOL_GPL(pm_runtime_enable); +static void pm_runtime_set_suspended_action(void *data) +{ + pm_runtime_set_suspended(data); +} + +/** + * devm_pm_runtime_set_active_enabled - set_active version of devm_pm_runtime_enable. + * + * @dev: Device to handle. + */ +int devm_pm_runtime_set_active_enabled(struct device *dev) +{ + int err; + + err = pm_runtime_set_active(dev); + if (err) + return err; + + err = devm_add_action_or_reset(dev, pm_runtime_set_suspended_action, dev); + if (err) + return err; + + return devm_pm_runtime_enable(dev); +} +EXPORT_SYMBOL_GPL(devm_pm_runtime_set_active_enabled); + static void pm_runtime_disable_action(void *data) { pm_runtime_dont_use_autosuspend(data); @@ -1590,6 +1616,24 @@ int devm_pm_runtime_enable(struct device *dev) } EXPORT_SYMBOL_GPL(devm_pm_runtime_enable); +static void pm_runtime_put_noidle_action(void *data) +{ + pm_runtime_put_noidle(data); +} + +/** + * devm_pm_runtime_get_noresume - devres-enabled version of pm_runtime_get_noresume. + * + * @dev: Device to handle. + */ +int devm_pm_runtime_get_noresume(struct device *dev) +{ + pm_runtime_get_noresume(dev); + + return devm_add_action_or_reset(dev, pm_runtime_put_noidle_action, dev); +} +EXPORT_SYMBOL_GPL(devm_pm_runtime_get_noresume); + /** * pm_runtime_forbid - Block runtime PM of a device. * @dev: Device to handle. diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h index 7fb5a459847e..756b842dcd30 100644 --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -96,7 +96,9 @@ extern void pm_runtime_new_link(struct device *dev); extern void pm_runtime_drop_link(struct device_link *link); extern void pm_runtime_release_supplier(struct device_link *link); +int devm_pm_runtime_set_active_enabled(struct device *dev); extern int devm_pm_runtime_enable(struct device *dev); +int devm_pm_runtime_get_noresume(struct device *dev); /** * pm_suspend_ignore_children - Set runtime PM behavior regarding children. @@ -294,7 +296,9 @@ static inline bool pm_runtime_blocked(struct device *dev) { return true; } static inline void pm_runtime_allow(struct device *dev) {} static inline void pm_runtime_forbid(struct device *dev) {} +static inline int devm_pm_runtime_set_active_enabled(struct device *dev) { return 0; } static inline int devm_pm_runtime_enable(struct device *dev) { return 0; } +static inline int devm_pm_runtime_get_noresume(struct device *dev) { return 0; } static inline void pm_suspend_ignore_children(struct device *dev, bool enable) {} static inline void pm_runtime_get_noresume(struct device *dev) {} From patchwork Thu Mar 27 19:59:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmVuY2UgQ3PDs2vDoXM=?= X-Patchwork-Id: 14031408 Received: from fw2.prolan.hu (fw2.prolan.hu [193.68.50.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A2E417A31E; Thu, 27 Mar 2025 19:59:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.68.50.107 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743105589; cv=none; b=XH4X+r53e9SOJwbpfpjMmeixI+ztpyX1QnVWZw6WnSE8G4clm0Lo4fude2q/h1G10iowzxkBR22MwxMA6HpLLxB1uDRNXUlD+diZdRQw03tMq/5QziKW/9AQlYdog9dFjoeAPWe65ZVq8BaNnEzx/sSoAEWXWu77IuEL556sYAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743105589; c=relaxed/simple; bh=ZEXW2O7h5RH6Mp/gFSotZYIhjX5T0tvJ/uNjX7f0reM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VQlpLZ00Z/SutC9AM8DyGD+tu78JXu9Io9NUE00AXi2gzSJiDEAZ5X+kdpCWBdJLb3PyHzW0FsBBKeGcHFUcTVUhTSJ0AD+AAeRfNHUkxaLWhbG7WDSVWwFErAmYLTm3G6C3y8QzVOguqo6v6X8lLWXhoyF5m4vB42vrThKvwfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=prolan.hu; spf=pass smtp.mailfrom=prolan.hu; dkim=pass (4096-bit key) header.d=prolan.hu header.i=@prolan.hu header.b=lplCpauW; arc=none smtp.client-ip=193.68.50.107 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=prolan.hu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=prolan.hu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=prolan.hu header.i=@prolan.hu header.b="lplCpauW" Received: from proxmox-mailgw.intranet.prolan.hu (localhost.localdomain [127.0.0.1]) by proxmox-mailgw.intranet.prolan.hu (Proxmox) with ESMTP id 15B8EA07C8; Thu, 27 Mar 2025 20:59:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prolan.hu; h=cc :cc:content-transfer-encoding:content-type:content-type:date :from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=mail; bh=ntL/r97AdlpWnW+HECsF a4zjnJTd1uAw3/3VEUgoZkU=; b=lplCpauWoEdxdgEUgrZgRfCLiG3oZbsXyuzX rW8iUImqNjJUM3ZlwmOkB05ge+6ElpbGLTLD3bRI7xOVAvzctSNuQycbGdqy0u/Z ui6ltSXmpjl9R1o+pafc8bFcvCTTtiEG4UQEMH7HYpok5z8nNn+jS8gTTjsat5TN MLTcr1sHoh2jBL1HgPxfAhBEwwKxs1J3xGyOV2pasa2Ph33lt52iVRljGXq5Osuh W24+UAyb0vQcWUZ7EOQGz9g2r2pwbzJGKO5dFHJcgKJ/Ypz+Ah61ejtxQZxq7YUr tsC7z/L28oelzo/Iu35HdmEZje39GBmS0jGNOxClynvqs9u11M7Znel1gdvH9oPB f/Wne1sx25yUQroUp7X9OSYiVZYj12iGIpaf98l3Qw+ZRPufQL8zD47NY8nYvAu3 Mg6XhZeYL3Bd93HA3VFTqxlcAmKpO4VQGqwPHcYm9n4UDghq1xWB5aqLLbYH+s/c 8GnzBBMQTvrAobd+zQvl7wgS+wktiBn8mK8u0qGCmpFMY7ocGf6peC1qvlbZ0ro5 pVzg0XjnIbfoBR68PAQz2H84Bv3cVxN1ekeySRAVGMRgpkElD2uijd0Qa+KvJSIr ZjCt5XLJzVI9h4LXWUqv1e0qATvNS7oQCekKDyubfGXmjrxFGUrqI1FNKsUEhTR6 7JOBnmQ= From: =?utf-8?b?QmVuY2UgQ3PDs2vDoXM=?= To: , , =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= , "Varshini Rajendran" , Tudor Ambarus , Mark Brown , , CC: "Rafael J. Wysocki" , Len Brown , Pavel Machek , Greg Kroah-Hartman , Danilo Krummrich , Alexander Dahl , "Nicolas Ferre" , Alexandre Belloni , Claudiu Beznea Subject: [PATCH v6 2/2] spi: atmel-quadspi: Fix unbalanced pm_runtime by using devm_ API Date: Thu, 27 Mar 2025 20:59:27 +0100 Message-ID: <20250327195928.680771-4-csokas.bence@prolan.hu> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250327195928.680771-2-csokas.bence@prolan.hu> References: <20250327195928.680771-2-csokas.bence@prolan.hu> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ESET-AS: R=OK;S=0;OP=CALC;TIME=1743105585;VERSION=7987;MC=2725881566;ID=112016;TRN=0;CRV=0;IPC=;SP=0;SIPS=0;PI=3;F=0 X-ESET-Antispam: OK X-EsetResult: clean, is OK X-EsetId: 37303A2980D948526C776A Fix unbalanced PM in error path of `atmel_qspi_probe()` by using `devm_pm_runtime_*()` functions. Reported-by: Alexander Dahl Closes: https://lore.kernel.org/linux-spi/20250110-paycheck-irregular-bcddab1276c7@thorsis.com/ Fixes: 5af42209a4d2 ("spi: atmel-quadspi: Add support for sama7g5 QSPI") Signed-off-by: Bence Csókás --- drivers/spi/atmel-quadspi.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c index 244ac0106862..e7b61dc4ce67 100644 --- a/drivers/spi/atmel-quadspi.c +++ b/drivers/spi/atmel-quadspi.c @@ -1436,22 +1436,17 @@ static int atmel_qspi_probe(struct platform_device *pdev) pm_runtime_set_autosuspend_delay(&pdev->dev, 500); pm_runtime_use_autosuspend(&pdev->dev); - pm_runtime_set_active(&pdev->dev); - pm_runtime_enable(&pdev->dev); - pm_runtime_get_noresume(&pdev->dev); + devm_pm_runtime_set_active_enabled(&pdev->dev); + devm_pm_runtime_get_noresume(&pdev->dev); err = atmel_qspi_init(aq); if (err) goto dma_release; err = spi_register_controller(ctrl); - if (err) { - pm_runtime_put_noidle(&pdev->dev); - pm_runtime_disable(&pdev->dev); - pm_runtime_set_suspended(&pdev->dev); - pm_runtime_dont_use_autosuspend(&pdev->dev); + if (err) goto dma_release; - } + pm_runtime_mark_last_busy(&pdev->dev); pm_runtime_put_autosuspend(&pdev->dev); @@ -1530,10 +1525,6 @@ static void atmel_qspi_remove(struct platform_device *pdev) */ dev_warn(&pdev->dev, "Failed to resume device on remove\n"); } - - pm_runtime_disable(&pdev->dev); - pm_runtime_dont_use_autosuspend(&pdev->dev); - pm_runtime_put_noidle(&pdev->dev); } static int __maybe_unused atmel_qspi_suspend(struct device *dev)