lkml.org 
[lkml]   [2018]   [Mar]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] sh: superhyway: use put_device() if device_register fail
Date
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
\
 
 \ /
  Last update: 2018-03-07 12:04    [W:0.027 / U:0.164 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site