From: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
To: Dawei Li <dawei.li@linux.dev>,
andersson@kernel.org, mathieu.poirier@linaro.org
Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org,
set_pte_at@outlook.com, zhongqiu.han@oss.qualcomm.com
Subject: Re: [PATCH v4 2/3] rpmsg: char: Rework of rpmsg_eptdev_add() and its callers
Date: Wed, 19 Nov 2025 21:03:04 +0800 [thread overview]
Message-ID: <8371403c-668e-48ed-9df6-5d4c6d04fc66@oss.qualcomm.com> (raw)
In-Reply-To: <20251118154107.3100-3-dawei.li@linux.dev>
On 11/18/2025 11:41 PM, Dawei Li wrote:
> 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")
Just for reference, it would be better if the commit message clearly
explained what is being fixed. Just like V3 2/3
https://lore.kernel.org/all/20251113153909.3789-3-dawei.li@linux.dev/
> Signed-off-by: Dawei Li <dawei.li@linux.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)
--
Thx and BRs,
Zhongqiu Han
next prev parent reply other threads:[~2025-11-19 13:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-18 15:41 [PATCH v4 0/3] Fixes and rework of rpmsg_eptdev_add() Dawei Li
2025-11-18 15:41 ` [PATCH v4 1/3] rpmsg: char: Fix WARN() in error path " Dawei Li
2025-11-19 4:07 ` Zhongqiu Han
2025-11-19 10:56 ` Dawei Li
2025-11-19 12:26 ` Zhongqiu Han
2025-11-19 17:14 ` Mathieu Poirier
2025-11-18 15:41 ` [PATCH v4 2/3] rpmsg: char: Rework of rpmsg_eptdev_add() and its callers Dawei Li
2025-11-19 13:03 ` Zhongqiu Han [this message]
2025-11-18 15:41 ` [PATCH v4 3/3] rpmsg: char: Merge cdev branches in rpmsg_eptdev_add() Dawei Li
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=8371403c-668e-48ed-9df6-5d4c6d04fc66@oss.qualcomm.com \
--to=zhongqiu.han@oss.qualcomm.com \
--cc=andersson@kernel.org \
--cc=dawei.li@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=set_pte_at@outlook.com \
/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