Skip to content

Commit

Permalink
net: hns: fix device reference leaks
Browse files Browse the repository at this point in the history
Make sure to drop the reference taken by class_find_device() in
hnae_get_handle() on errors and when later releasing the handle.

Fixes: 6fe6611 ("net: add Hisilicon Network Subsystem...")
Cc: Yisen Zhuang <[email protected]>
Cc: Salil Mehta <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
jhovold authored and davem330 committed Nov 7, 2016
1 parent 6bed011 commit 2271150
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion drivers/net/ethernet/hisilicon/hns/hnae.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -356,6 +358,8 @@ struct hnae_handle *hnae_get_handle(struct device *owner_dev,
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);
Expand All @@ -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);

Expand Down

0 comments on commit 2271150

Please sign in to comment.