Skip to contentSkip to conversation

smb3: Improve exception handling in allocate_mr_list()

PATCH Applied Markus Elfring 2 participants 2 messages Dec 30, 2023 – Jan 5, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 smb3: Improve exception handling in allocate_mr_list()

From: Markus Elfring <[email protected]>
Date: Fri, 29 Dec 2023 20:43:12 +0100

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.

---
 fs/smb/client/smbdirect.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/smb/client/smbdirect.c +2 -2
index 94df9eec3d8d..d74e829de51c 100644
@@ -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);

--
2.43.0

Applied
#1 lore raw

merged into cifs-2.6.git for-next

Quoted 42 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 29 Dec 2023 20:43:12 +0100

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.

---
 fs/smb/client/smbdirect.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/smb/client/smbdirect.c +2 -3
index 94df9eec3d8d..d74e829de51c 100644
@@ -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);
--

2.43.0

Signature · 3 lines
Thanks,

Steve