mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sh: dma-sysfs: add missing put_device() in dma_create_sysfs_files()
@ 2025-12-20  6:28 Haoxiang Li
  2025-12-20 13:56 ` Markus Elfring
  0 siblings, 1 reply; 3+ messages in thread
From: Haoxiang Li @ 2025-12-20  6:28 UTC (permalink / raw)
  To: ysato, dalias, glaubitz, kay.sievers, gregkh
  Cc: linux-sh, linux-kernel, Haoxiang Li, stable

If device_register() fails, call put_device() to drop the device
reference. Also, call device_unregister() if device_create_file()
fails.

Found by code review.

Fixes: dc6876a288cc ("sh: dma - convert sysdev_class to a regular subsystem")
Cc: stable@vger.kernel.org
Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
---
 arch/sh/drivers/dma/dma-sysfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/sh/drivers/dma/dma-sysfs.c b/arch/sh/drivers/dma/dma-sysfs.c
index 9f666280d80c..5695fd0a0cd7 100644
--- a/arch/sh/drivers/dma/dma-sysfs.c
+++ b/arch/sh/drivers/dma/dma-sysfs.c
@@ -134,8 +134,10 @@ int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
 	dev->bus = &dma_subsys;
 
 	ret = device_register(dev);
-	if (ret)
+	if (ret) {
+		put_device(dev);
 		return ret;
+	}
 
 	ret |= device_create_file(dev, &dev_attr_dev_id);
 	ret |= device_create_file(dev, &dev_attr_count);
@@ -145,6 +147,7 @@ int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
 
 	if (unlikely(ret)) {
 		dev_err(&info->pdev->dev, "Failed creating attrs\n");
+		device_unregister(dev);
 		return ret;
 	}
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-20 14:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-20  6:28 [PATCH] sh: dma-sysfs: add missing put_device() in dma_create_sysfs_files() Haoxiang Li
2025-12-20 13:56 ` Markus Elfring
2025-12-20 14:11   ` John Paul Adrian Glaubitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®