devlink: Fix memleak in health diagnose callback
authorMoshe Shemesh <moshe@nvidia.com>
Mon, 6 Feb 2023 15:56:16 +0000 (17:56 +0200)
committerJakub Kicinski <kuba@kernel.org>
Wed, 8 Feb 2023 04:21:33 +0000 (20:21 -0800)
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 <moshe@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Link: https://lore.kernel.org/r/1675698976-45993-1-git-send-email-moshe@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/devlink/leftover.c

index 97d30ea98b004c47d74bd1fecfbfb5d4eeb91007..9d637360334045dc4fa42855c6bca2c432639b8a 100644 (file)
@@ -6626,18 +6626,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