Subject: [PATCH net-next] devlink: Fix memleak in health diagnose callback

From: Moshe Shemesh <[email-masked]>
Date: Mon, 6 Feb 2023 17:56:16 +0200

The callback devlink_nl_cmd_health_reporter_diagnose_doit() miss
devlink_fmsg_free(), which leads to memory leak.

Fix it by adding devlink_fmsg_free().

Fixes: e994a75fb7f9 ("devlink: remove reporter reference counting")
Signed-off-by: Moshe Shemesh <[email-masked]>
Reviewed-by: Jiri Pirko <[email-masked]>
---
 net/devlink/leftover.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c
index 056d9ca14a3d..79bb8320fc3a 100644
--- a/net/devlink/leftover.c
+++ b/net/devlink/leftover.c
@@ -7866,18 +7866,22 @@ static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb,
 
 	err = devlink_fmsg_obj_nest_start(fmsg);
 	if (err)
-		return err;
+		goto out;
 
 	err = reporter->ops->diagnose(reporter, fmsg, info->extack);
 	if (err)
-		return err;
+		goto out;
 
 	err = devlink_fmsg_obj_nest_end(fmsg);
 	if (err)
-		return err;
+		goto out;
+
+	err = devlink_fmsg_snd(fmsg, info,
+			       DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE, 0);
 
-	return devlink_fmsg_snd(fmsg, info,
-				DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE, 0);
+out:
+	devlink_fmsg_free(fmsg);
+	return err;
 }
 
 static int
-- 
2.37.1