From: Jing Xiangfeng <jingxiangf...@huawei.com>

[ Upstream commit 85094c05eeb47d195a74a25366a2db066f1c9d47 ]

rio_mport_add_riodev() misses to call put_device() when the device already
exists.  Add the missed function call to fix it.

Fixes: e8de370188d0 ("rapidio: add mport char device driver")
Signed-off-by: Jing Xiangfeng <jingxiangf...@huawei.com>
Signed-off-by: Andrew Morton <a...@linux-foundation.org>
Reviewed-by: Dan Carpenter <dan.carpen...@oracle.com>
Cc: Matt Porter <mpor...@kernel.crashing.org>
Cc: Alexandre Bounine <alex.b...@gmail.com>
Cc: Gustavo A. R. Silva <gustavo...@kernel.org>
Cc: John Hubbard <jhubb...@nvidia.com>
Cc: Kees Cook <keesc...@chromium.org>
Cc: Madhuparna Bhowmik <madhuparnabhowmi...@gmail.com>
Link: https://lkml.kernel.org/r/20200922072525.42330-1-jingxiangf...@huawei.com
Signed-off-by: Linus Torvalds <torva...@linux-foundation.org>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
 drivers/rapidio/devices/rio_mport_cdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/rapidio/devices/rio_mport_cdev.c 
b/drivers/rapidio/devices/rio_mport_cdev.c
index 163b6c72501d6..94331d999d273 100644
--- a/drivers/rapidio/devices/rio_mport_cdev.c
+++ b/drivers/rapidio/devices/rio_mport_cdev.c
@@ -1680,6 +1680,7 @@ static int rio_mport_add_riodev(struct mport_cdev_priv 
*priv,
        struct rio_dev *rdev;
        struct rio_switch *rswitch = NULL;
        struct rio_mport *mport;
+       struct device *dev;
        size_t size;
        u32 rval;
        u32 swpinfo = 0;
@@ -1694,8 +1695,10 @@ static int rio_mport_add_riodev(struct mport_cdev_priv 
*priv,
        rmcd_debug(RDEV, "name:%s ct:0x%x did:0x%x hc:0x%x", dev_info.name,
                   dev_info.comptag, dev_info.destid, dev_info.hopcount);
 
-       if (bus_find_device_by_name(&rio_bus_type, NULL, dev_info.name)) {
+       dev = bus_find_device_by_name(&rio_bus_type, NULL, dev_info.name);
+       if (dev) {
                rmcd_debug(RDEV, "device %s already exists", dev_info.name);
+               put_device(dev);
                return -EEXIST;
        }
 
-- 
2.25.1



Reply via email to