From: Coiby Xu <[email protected]>
devlink_health_reporter_create may fail. In that case, do the cleanup
work.
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Coiby Xu <[email protected]>
---
drivers/staging/qlge/qlge_devlink.c | 10 +++++++---
drivers/staging/qlge/qlge_devlink.h | 2 +-
drivers/staging/qlge/qlge_main.c | 8 +++++++-
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/qlge/qlge_devlink.c b/drivers/staging/qlge/qlge_devlink.c
index 86834d96cebf..0ab02d6d3817 100644
--- a/drivers/staging/qlge/qlge_devlink.c
+++ b/drivers/staging/qlge/qlge_devlink.c
@@ -148,16 +148,20 @@ static const struct devlink_health_reporter_ops qlge_reporter_ops = {
.dump = qlge_reporter_coredump,
};
-void qlge_health_create_reporters(struct qlge_adapter *priv)
+long qlge_health_create_reporters(struct qlge_adapter *priv)
{
struct devlink *devlink;
+ long err = 0;
devlink = priv_to_devlink(priv);
priv->reporter =
devlink_health_reporter_create(devlink, &qlge_reporter_ops,
0, priv);
- if (IS_ERR(priv->reporter))
+ if (IS_ERR(priv->reporter)) {
+ err = PTR_ERR(priv->reporter);
netdev_warn(priv->ndev,
"Failed to create reporter, err = %ld\n",
- PTR_ERR(priv->reporter));
+ err);
+ }
+ return err;
}
diff --git a/drivers/staging/qlge/qlge_devlink.h b/drivers/staging/qlge/qlge_devlink.h
index 19078e1ac694..94538e923f2f 100644
--- a/drivers/staging/qlge/qlge_devlink.h
+++ b/drivers/staging/qlge/qlge_devlink.h
@@ -4,6 +4,6 @@
#include <net/devlink.h>
-void qlge_health_create_reporters(struct qlge_adapter *priv);
+long qlge_health_create_reporters(struct qlge_adapter *priv);
#endif /* QLGE_DEVLINK_H */
diff --git a/drivers/staging/qlge/qlge_main.c b/drivers/staging/qlge/qlge_main.c
index 5516be3af898..59d1ec580696 100644
--- a/drivers/staging/qlge/qlge_main.c
+++ b/drivers/staging/qlge/qlge_main.c
@@ -4620,7 +4620,11 @@ static int qlge_probe(struct pci_dev *pdev,
if (err)
goto netdev_free;
- qlge_health_create_reporters(qdev);
+ err = qlge_health_create_reporters(qdev);
+
+ if (err)
+ goto devlink_unregister;
+
/* Start up the timer to trigger EEH if
* the bus goes dead
*/
@@ -4632,6 +4636,8 @@ static int qlge_probe(struct pci_dev *pdev,
cards_found++;
return 0;
+devlink_unregister:
+ devlink_unregister(devlink);
netdev_free:
free_netdev(ndev);
devlink_free:
--
2.31.0