From: Su Hui <suhui@nfschina.com>
To: stuyoder@gmail.com, laurentiu.tudor@nxp.com, dan.carpenter@linaro.org
Cc: Su Hui <suhui@nfschina.com>,
gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: [PATCH v2 2/2] bus: fsl-mc: using put_device() when add_device() failed in fsl_mc_device_add()
Date: Fri, 15 Nov 2024 10:32:07 +0800 [thread overview]
Message-ID: <20241115023206.3722933-3-suhui@nfschina.com> (raw)
In-Reply-To: <20241115023206.3722933-1-suhui@nfschina.com>
When device_add(&mc_dev->dev) failed, calling put_device() to let
'mc_dev->dev.release' free the resource rather than goto label
error_cleanup_dev. Otherwise, it can cause double free problem.
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/all/b767348e-d89c-416e-acea-1ebbff3bea20@stanley.mountain/
Fixes: 95b3523b723e ("staging: fsl-mc: add device release callback")
Signed-off-by: Su Hui <suhui@nfschina.com>
---
drivers/bus/fsl-mc/fsl-mc-bus.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c
index 319a081a29ef..09f8772fed8f 100644
--- a/drivers/bus/fsl-mc/fsl-mc-bus.c
+++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
@@ -895,7 +895,8 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
dev_err(parent_dev,
"device_add() failed for device %s: %d\n",
dev_name(&mc_dev->dev), error);
- goto error_cleanup_dev;
+ put_device(&mc_dev->dev);
+ return error;
}
dev_dbg(parent_dev, "added %s\n", dev_name(&mc_dev->dev));
--
2.30.2
next prev parent reply other threads:[~2024-11-15 2:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-15 2:32 [PATCH v2 0/2] bus: fsl-mc: Fix two double free problems " Su Hui
2024-11-15 2:32 ` [PATCH v2 1/2] bus: fsl-mc: Fix the double free " Su Hui
2024-11-15 2:32 ` Su Hui [this message]
2024-11-15 8:24 ` [PATCH v2 0/2] bus: fsl-mc: Fix two double free problems " 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=20241115023206.3722933-3-suhui@nfschina.com \
--to=suhui@nfschina.com \
--cc=dan.carpenter@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=laurentiu.tudor@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stuyoder@gmail.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
all inboxes | Powered by JetHome®