Commit 2609d24a authored by Johan Hovold's avatar Johan Hovold Committed by Kleber Sacilotto de Souza

net: hns: fix device reference leaks

BugLink: https://bugs.launchpad.net/bugs/1878232

commit 2271150b 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: 6fe6611f ("net: add Hisilicon Network Subsystem...")
Cc: Yisen Zhuang <yisen.zhuang@huawei.com>
Cc: Salil Mehta <salil.mehta@huawei.com>
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarIan May <ian.may@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 459f3adf
...@@ -331,8 +331,10 @@ struct hnae_handle *hnae_get_handle(struct device *owner_dev, ...@@ -331,8 +331,10 @@ struct hnae_handle *hnae_get_handle(struct device *owner_dev,
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
handle = dev->ops->get_handle(dev, port_id); handle = dev->ops->get_handle(dev, port_id);
if (IS_ERR(handle)) if (IS_ERR(handle)) {
put_device(&dev->cls_dev);
return handle; return handle;
}
handle->dev = dev; handle->dev = dev;
handle->owner_dev = owner_dev; handle->owner_dev = owner_dev;
...@@ -355,6 +357,8 @@ struct hnae_handle *hnae_get_handle(struct device *owner_dev, ...@@ -355,6 +357,8 @@ struct hnae_handle *hnae_get_handle(struct device *owner_dev,
for (j = i - 1; j >= 0; j--) for (j = i - 1; j >= 0; j--)
hnae_fini_queue(handle->qs[j]); hnae_fini_queue(handle->qs[j]);
put_device(&dev->cls_dev);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
EXPORT_SYMBOL(hnae_get_handle); EXPORT_SYMBOL(hnae_get_handle);
...@@ -376,6 +380,8 @@ void hnae_put_handle(struct hnae_handle *h) ...@@ -376,6 +380,8 @@ void hnae_put_handle(struct hnae_handle *h)
dev->ops->put_handle(h); dev->ops->put_handle(h);
module_put(dev->owner); module_put(dev->owner);
put_device(&dev->cls_dev);
} }
EXPORT_SYMBOL(hnae_put_handle); EXPORT_SYMBOL(hnae_put_handle);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment