arch/sh/drivers/dma/dma-sysfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
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
> If device_register() fails, call put_device() to drop the device > reference. Also, call device_unregister() if device_create_file() > fails. See also once more: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc1#n659 You propose to complete the exception handling for two cases. Is there a need to indicate such a detail in the summary phrase accordingly? Regards, Markus
Hi Markus, On Sat, 2025-12-20 at 14:56 +0100, Markus Elfring wrote: > > If device_register() fails, call put_device() to drop the device > > reference. Also, call device_unregister() if device_create_file() > > fails. > > See also once more: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc1#n659 > > > You propose to complete the exception handling for two cases. > Is there a need to indicate such a detail in the summary phrase accordingly? Maybe I'm completely missing something here, but I find the description short and reasonable. As the SH maintainer, I haven't started reviewing these patches themselves yet, I definitely interested to understand what the problem is. Thanks, Adrian -- .''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
© 2016 - 2026 Red Hat, Inc.