smb3: Improve exception handling in allocate_mr_list()
authorMarkus Elfring <elfring@users.sourceforge.net>
Fri, 29 Dec 2023 19:43:12 +0000 (20:43 +0100)
committerSteve French <stfrench@microsoft.com>
Sun, 7 Jan 2024 21:46:06 +0000 (15:46 -0600)
The kfree() function was called in one case by
the allocate_mr_list() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.

Thus use another label.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/smbdirect.c

index 94df9eec3d8d1c240d6b4573c7fe1884ef99fdd4..d74e829de51c225a94f8221f03712f9826c030d7 100644 (file)
@@ -2136,7 +2136,7 @@ static int allocate_mr_list(struct smbd_connection *info)
        for (i = 0; i < info->responder_resources * 2; i++) {
                smbdirect_mr = kzalloc(sizeof(*smbdirect_mr), GFP_KERNEL);
                if (!smbdirect_mr)
-                       goto out;
+                       goto cleanup_entries;
                smbdirect_mr->mr = ib_alloc_mr(info->pd, info->mr_type,
                                        info->max_frmr_depth);
                if (IS_ERR(smbdirect_mr->mr)) {
@@ -2162,7 +2162,7 @@ static int allocate_mr_list(struct smbd_connection *info)
 
 out:
        kfree(smbdirect_mr);
-
+cleanup_entries:
        list_for_each_entry_safe(smbdirect_mr, tmp, &info->mr_list, list) {
                list_del(&smbdirect_mr->list);
                ib_dereg_mr(smbdirect_mr->mr);