]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: hns: fix device reference leaks
authorJohan Hovold <johan@kernel.org>
Thu, 3 Nov 2016 17:40:22 +0000 (18:40 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 7 Nov 2016 18:17:30 +0000 (13:17 -0500)
Make sure to drop the reference taken by class_find_device() in
hnae_get_handle() on errors and when later releasing the handle.

Fixes: 8aa11e41557b ("net: add Hisilicon Network Subsystem...")
Cc: Yisen Zhuang <yisen.zhuang@huawei.com>
Cc: Salil Mehta <salil.mehta@huawei.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns/hnae.c

index c54c6fac0d1de065cc891fe9103bba027c6f2df8..b6ed818f78fffe21ee2b4c385c7c6222bc5df9f3 100644 (file)
@@ -332,8 +332,10 @@ struct hnae_handle *hnae_get_handle(struct device *owner_dev,
                return ERR_PTR(-ENODEV);
 
        handle = dev->ops->get_handle(dev, port_id);
-       if (IS_ERR(handle))
+       if (IS_ERR(handle)) {
+               put_device(&dev->cls_dev);
                return handle;
+       }
 
        handle->dev = dev;
        handle->owner_dev = owner_dev;
@@ -356,6 +358,8 @@ out_when_init_queue:
        for (j = i - 1; j >= 0; j--)
                hnae_fini_queue(handle->qs[j]);
 
+       put_device(&dev->cls_dev);
+
        return ERR_PTR(-ENOMEM);
 }
 EXPORT_SYMBOL(hnae_get_handle);
@@ -377,6 +381,8 @@ void hnae_put_handle(struct hnae_handle *h)
                dev->ops->put_handle(h);
 
        module_put(dev->owner);
+
+       put_device(&dev->cls_dev);
 }
 EXPORT_SYMBOL(hnae_put_handle);