net: hns: fix device reference leaks

commit 2271150bfb814b72ec57ae2fdf66e39da2eafafd upstream.

Make sure to drop the reference taken by class_find_device() in
hnae_get_handle() on errors and when later releasing the handle.

Fixes: 6fe6611ff275 ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Johan Hovold 2016-11-03 18:40:22 +01:00 committed by Greg Kroah-Hartman
parent b5ec0bdc57
commit 6c0c7c62ca

View File

@ -331,8 +331,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;
@ -355,6 +357,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);
@ -376,6 +380,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);