mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: linfordWu <linfordwu@163.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	linfordWu <linfordwu@163.com>
Subject: [PATCH] staging: vme_user: fix probe error path resource handling
Date: Sat, 31 Oct 2026 21:34:33 +0800	[thread overview]
Message-ID: <20261031133433.1826133-1-linfordwu@163.com> (raw)

The probe error paths free the current master or slave resource before
jumping to cleanup loops that free it again. They also pass NULL
resources to the VME release helpers when window allocation fails, and
pass a NULL buffer to vme_free_consistent() when buffer allocation
fails.

Let the common cleanup paths own all resource releases and guard the
resource and buffer pointers so each failure path only releases objects
that were allocated successfully.

Signed-off-by: linfordWu <linfordwu@163.com>
---
 drivers/staging/vme_user/vme_user.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/vme_user/vme_user.c b/drivers/staging/vme_user/vme_user.c
index a472a38ef61..980798ae622 100644
--- a/drivers/staging/vme_user/vme_user.c
+++ b/drivers/staging/vme_user/vme_user.c
@@ -616,7 +616,6 @@ static int vme_user_probe(struct vme_dev *vdev)
 			dev_warn(&vdev->dev,
 				 "Unable to allocate memory for buffer\n");
 			image[i].pci_buf = 0;
-			vme_slave_free(image[i].resource);
 			err = -ENOMEM;
 			goto err_slave;
 		}
@@ -641,7 +640,6 @@ static int vme_user_probe(struct vme_dev *vdev)
 		image[i].kern_buf = kmalloc(image[i].size_buf, GFP_KERNEL);
 		if (!image[i].kern_buf) {
 			err = -ENOMEM;
-			vme_master_free(image[i].resource);
 			goto err_master;
 		}
 	}
@@ -698,7 +696,8 @@ static int vme_user_probe(struct vme_dev *vdev)
 	while (i > MASTER_MINOR) {
 		i--;
 		kfree(image[i].kern_buf);
-		vme_master_free(image[i].resource);
+		if (image[i].resource)
+			vme_master_free(image[i].resource);
 	}
 
 	/*
@@ -708,9 +707,11 @@ static int vme_user_probe(struct vme_dev *vdev)
 err_slave:
 	while (i > SLAVE_MINOR) {
 		i--;
-		vme_free_consistent(image[i].resource, image[i].size_buf,
-				    image[i].kern_buf, image[i].pci_buf);
-		vme_slave_free(image[i].resource);
+		if (image[i].kern_buf)
+			vme_free_consistent(image[i].resource, image[i].size_buf,
+					    image[i].kern_buf, image[i].pci_buf);
+		if (image[i].resource)
+			vme_slave_free(image[i].resource);
 	}
 err_class:
 	cdev_del(vme_user_cdev);
-- 
2.43.0


             reply	other threads:[~2026-10-31 13:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31 13:34 linfordWu [this message]
2026-10-31 13:50 ` Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261031133433.1826133-1-linfordwu@163.com \
    --to=linfordwu@163.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®