[PATCH] firmware: samsung: acpm: Don't use pdev after putting it in acpm_get_by_node()

Suyuan Wang via B4 Relay posted 1 patch 9 hours ago
drivers/firmware/samsung/exynos-acpm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] firmware: samsung: acpm: Don't use pdev after putting it in acpm_get_by_node()
Posted by Suyuan Wang via B4 Relay 9 hours ago
From: Suyuan Wang <stevewong@hust.edu.cn>

When device_link_add() fails, acpm_get_by_node() drops the reference to
the ACPM platform device and only then reads its driver to drop the
module reference:

	platform_device_put(pdev);
	module_put(pdev->dev.driver->owner);

The reference from of_find_device_by_node() is what keeps pdev around
here, so pdev must not be used after the put.

Drop the module reference before the device reference, as
acpm_handle_put() already does.

Found with a static analysis tool and checked by hand.

Fixes: a88927b534ba ("firmware: add Exynos ACPM protocol driver")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Compile tested on arm64 (W=1). I don't have the hardware.
---
 drivers/firmware/samsung/exynos-acpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/firmware/samsung/exynos-acpm.c b/drivers/firmware/samsung/exynos-acpm.c
index a575caf871b9..15d2f708b0c7 100644
--- a/drivers/firmware/samsung/exynos-acpm.c
+++ b/drivers/firmware/samsung/exynos-acpm.c
@@ -816,8 +816,8 @@ static struct acpm_handle *acpm_get_by_node(struct device *dev,
 		dev_err(&pdev->dev,
 			"Failed to create device link to consumer %s.\n",
 			dev_name(dev));
-		platform_device_put(pdev);
 		module_put(pdev->dev.driver->owner);
+		platform_device_put(pdev);
 		return ERR_PTR(-EINVAL);
 	}