[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20251118154107.3100-3-dawei.li@linux.dev>
Date: Tue, 18 Nov 2025 23:41:06 +0800
From: Dawei Li <dawei.li@...ux.dev>
To: andersson@...nel.org,
mathieu.poirier@...aro.org
Cc: linux-remoteproc@...r.kernel.org,
linux-kernel@...r.kernel.org,
dawei.li@...ux.dev,
set_pte_at@...look.com
Subject: [PATCH v4 2/3] rpmsg: char: Rework of rpmsg_eptdev_add() and its callers
For every caller of rpmsg_eptdev_add(), eptdev is allocated in
rpmsg_eptdev_alloc(). Resource should be freed where it's allocated,
In this case, eptdev should be freed in caller of rpmsg_eptdev_add() rather
than rpmsg_eptdev_add() itself.
Move the error handling from rpmsg_eptdev_add() to its callers.
Fixes: 2410558f5f11 ("rpmsg: char: Implement eptdev based on anonymous inode")
Signed-off-by: Dawei Li <dawei.li@...ux.dev>
---
drivers/rpmsg/rpmsg_char.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c
index 373b627581e8..56371899212f 100644
--- a/drivers/rpmsg/rpmsg_char.c
+++ b/drivers/rpmsg/rpmsg_char.c
@@ -470,7 +470,7 @@ static int rpmsg_eptdev_add(struct rpmsg_eptdev *eptdev,
if (cdev) {
ret = ida_alloc_max(&rpmsg_minor_ida, RPMSG_DEV_MAX - 1, GFP_KERNEL);
if (ret < 0)
- goto free_eptdev;
+ return ret;
dev->devt = MKDEV(MAJOR(rpmsg_major), ret);
}
@@ -478,7 +478,7 @@ static int rpmsg_eptdev_add(struct rpmsg_eptdev *eptdev,
/* Anonymous inode device still need device name for dev_err() and friends */
ret = ida_alloc(&rpmsg_ept_ida, GFP_KERNEL);
if (ret < 0)
- goto free_eptdev;
+ return ret;
dev->id = ret;
dev_set_name(dev, "rpmsg%d", ret);
@@ -486,15 +486,8 @@ static int rpmsg_eptdev_add(struct rpmsg_eptdev *eptdev,
if (cdev) {
ret = cdev_device_add(&eptdev->cdev, &eptdev->dev);
- if (ret)
- goto free_eptdev;
}
- return ret;
-
-free_eptdev:
- put_device(dev);
-
return ret;
}
@@ -507,12 +500,17 @@ int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent
struct rpmsg_channel_info chinfo)
{
struct rpmsg_eptdev *eptdev;
+ int ret;
eptdev = rpmsg_chrdev_eptdev_alloc(rpdev, parent);
if (IS_ERR(eptdev))
return PTR_ERR(eptdev);
- return rpmsg_chrdev_eptdev_add(eptdev, chinfo);
+ ret = rpmsg_chrdev_eptdev_add(eptdev, chinfo);
+ if (ret)
+ put_device(&eptdev->dev);
+
+ return ret;
}
EXPORT_SYMBOL(rpmsg_chrdev_eptdev_create);
@@ -544,6 +542,7 @@ int rpmsg_anonymous_eptdev_create(struct rpmsg_device *rpdev, struct device *par
ret = rpmsg_eptdev_add(eptdev, chinfo, false);
if (ret) {
dev_err(&eptdev->dev, "failed to add %s\n", eptdev->chinfo.name);
+ put_device(&eptdev->dev);
return ret;
}
@@ -571,6 +570,7 @@ static int rpmsg_chrdev_probe(struct rpmsg_device *rpdev)
struct rpmsg_channel_info chinfo;
struct rpmsg_eptdev *eptdev;
struct device *dev = &rpdev->dev;
+ int ret;
memcpy(chinfo.name, rpdev->id.name, RPMSG_NAME_SIZE);
chinfo.src = rpdev->src;
@@ -589,7 +589,11 @@ static int rpmsg_chrdev_probe(struct rpmsg_device *rpdev)
*/
eptdev->default_ept->priv = eptdev;
- return rpmsg_chrdev_eptdev_add(eptdev, chinfo);
+ ret = rpmsg_chrdev_eptdev_add(eptdev, chinfo);
+ if (ret)
+ put_device(&eptdev->dev);
+
+ return ret;
}
static void rpmsg_chrdev_remove(struct rpmsg_device *rpdev)
--
2.25.1
Powered by blists - more mailing lists