* [PATCH 0/2] sh: use put_device() instead of kfree()
@ 2018-03-07 11:03 Arvind Yadav
2018-03-07 11:03 ` [PATCH 1/2] sh: maple: " Arvind Yadav
2018-03-07 11:03 ` [PATCH 2/2] sh: superhyway: use put_device() if device_register fail Arvind Yadav
0 siblings, 2 replies; 3+ messages in thread
From: Arvind Yadav @ 2018-03-07 11:03 UTC (permalink / raw)
To: ysato, dalias; +Cc: linux-kernel, linux-sh
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.
Arvind Yadav (2):
[PATCH 1/2] sh: maple: use put_device() instead of kfree()
[PATCH 2/2] sh: superhyway: use put_device() if device_register fail
drivers/sh/maple/maple.c | 3 ++-
drivers/sh/superhyway/superhyway.c | 11 +++++++++--
2 files changed, 11 insertions(+), 3 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] sh: maple: use put_device() instead of kfree()
2018-03-07 11:03 [PATCH 0/2] sh: use put_device() instead of kfree() Arvind Yadav
@ 2018-03-07 11:03 ` Arvind Yadav
2018-03-07 11:03 ` [PATCH 2/2] sh: superhyway: use put_device() if device_register fail Arvind Yadav
1 sibling, 0 replies; 3+ messages in thread
From: Arvind Yadav @ 2018-03-07 11:03 UTC (permalink / raw)
To: ysato, dalias; +Cc: linux-kernel, linux-sh
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.
Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
---
drivers/sh/maple/maple.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/sh/maple/maple.c b/drivers/sh/maple/maple.c
index 7525039..28674fe 100644
--- a/drivers/sh/maple/maple.c
+++ b/drivers/sh/maple/maple.c
@@ -393,7 +393,7 @@ static void maple_attach_driver(struct maple_device *mdev)
dev_warn(&mdev->dev, "could not register device at"
" (%d, %d), with error 0x%X\n", mdev->unit,
mdev->port, error);
- maple_free_dev(mdev);
+ put_device(&mdev->dev);
mdev = NULL;
return;
}
@@ -886,6 +886,7 @@ static int __init maple_bus_init(void)
cleanup:
printk(KERN_ERR "Maple bus registration failed\n");
+ put_device(&maple_bus);
return retval;
}
/* Push init to later to ensure hardware gets detected */
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] sh: superhyway: use put_device() if device_register fail
2018-03-07 11:03 [PATCH 0/2] sh: use put_device() instead of kfree() Arvind Yadav
2018-03-07 11:03 ` [PATCH 1/2] sh: maple: " Arvind Yadav
@ 2018-03-07 11:03 ` Arvind Yadav
1 sibling, 0 replies; 3+ messages in thread
From: Arvind Yadav @ 2018-03-07 11:03 UTC (permalink / raw)
To: ysato, dalias; +Cc: linux-kernel, linux-sh
if device_register() returned an error! Always use put_device()
to give up the reference initialized.
Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
---
drivers/sh/superhyway/superhyway.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/sh/superhyway/superhyway.c b/drivers/sh/superhyway/superhyway.c
index 348836b..98922e7 100644
--- a/drivers/sh/superhyway/superhyway.c
+++ b/drivers/sh/superhyway/superhyway.c
@@ -54,6 +54,7 @@ int superhyway_add_device(unsigned long base, struct superhyway_device *sdev,
struct superhyway_bus *bus)
{
struct superhyway_device *dev = sdev;
+ int ret;
if (!dev) {
dev = kzalloc(sizeof(struct superhyway_device), GFP_KERNEL);
@@ -87,7 +88,11 @@ int superhyway_add_device(unsigned long base, struct superhyway_device *sdev,
superhyway_devices++;
- return device_register(&dev->dev);
+ ret = device_register(&dev->dev);
+ if (ret)
+ put_device(&dev->dev);
+
+ return ret;
}
int superhyway_add_devices(struct superhyway_bus *bus,
@@ -110,8 +115,10 @@ static int __init superhyway_init(void)
int ret;
ret = device_register(&superhyway_bus_device);
- if (unlikely(ret))
+ if (unlikely(ret)) {
+ put_device(&superhyway_bus_device);
return ret;
+ }
for (bus = superhyway_channels; bus->ops; bus++)
ret |= superhyway_scan_bus(bus);
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-03-07 11:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-07 11:03 [PATCH 0/2] sh: use put_device() instead of kfree() Arvind Yadav
2018-03-07 11:03 ` [PATCH 1/2] sh: maple: " Arvind Yadav
2018-03-07 11:03 ` [PATCH 2/2] sh: superhyway: use put_device() if device_register fail Arvind Yadav
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).