diff mbox series

[v2] PM: domains: Fix return value of API dev_pm_get_subsys_data()

Message ID 20241112-fix_dev_pm_get_subsys_data-v2-1-3774257ede73@quicinc.com (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series [v2] PM: domains: Fix return value of API dev_pm_get_subsys_data() | expand

Commit Message

Zijun Hu Nov. 12, 2024, 3:21 p.m. UTC
From: Zijun Hu <quic_zijuhu@quicinc.com>

dev_pm_get_subsys_data() has below 2 issues under condition
(@dev->power.subsys_data != NULL):

- it will do unnecessary kzalloc() and kfree().
- it will return -ENOMEM if the kzalloc() fails, that is wrong
  it should return 0 since the kzalloc() is not needed.

Fix by not doing kzalloc() and returning 0 for the condition.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
Changes in v2:
- Remove both stable and fix tag
- Correct commit message
- Link to v1: https://lore.kernel.org/r/20241010-fix_dev_pm_get_subsys_data-v1-1-2250e8f0051b@quicinc.com
---
 drivers/base/power/common.c | 8 ++++++++
 1 file changed, 8 insertions(+)


---
base-commit: 9bd133f05b1dca5ca4399a76d04d0f6f4d454e44
change-id: 20241010-fix_dev_pm_get_subsys_data-2478bb200fde

Best regards,
diff mbox series

Patch

diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
index cca2fd0a1aed..a3cec013092c 100644
--- a/drivers/base/power/common.c
+++ b/drivers/base/power/common.c
@@ -26,6 +26,14 @@  int dev_pm_get_subsys_data(struct device *dev)
 {
 	struct pm_subsys_data *psd;
 
+	spin_lock_irq(&dev->power.lock);
+	if (dev->power.subsys_data) {
+		dev->power.subsys_data->refcount++;
+		spin_unlock_irq(&dev->power.lock);
+		return 0;
+	}
+	spin_unlock_irq(&dev->power.lock);
+
 	psd = kzalloc(sizeof(*psd), GFP_KERNEL);
 	if (!psd)
 		return -ENOMEM;