All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH next] firmware: thead,th1520-aon: Fix use after free in th1520_aon_init()
@ 2025-03-15 10:04 ` Dan Carpenter
  0 siblings, 0 replies; 8+ messages in thread
From: Dan Carpenter @ 2025-03-15 10:04 UTC (permalink / raw)
  To: Michal Wilczynski
  Cc: Drew Fustini, Guo Ren, Fu Wei, Ulf Hansson, linux-riscv,
	linux-kernel, kernel-janitors

Record the error code before freeing "aon_chan" to avoid a
use after free.

Fixes: e4b3cbd840e5 ("firmware: thead: Add AON firmware protocol driver")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/firmware/thead,th1520-aon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/thead,th1520-aon.c b/drivers/firmware/thead,th1520-aon.c
index 4416e9bbf854..38f812ac9920 100644
--- a/drivers/firmware/thead,th1520-aon.c
+++ b/drivers/firmware/thead,th1520-aon.c
@@ -203,6 +203,7 @@ struct th1520_aon_chan *th1520_aon_init(struct device *dev)
 {
 	struct th1520_aon_chan *aon_chan;
 	struct mbox_client *cl;
+	int ret;
 
 	aon_chan = kzalloc(sizeof(*aon_chan), GFP_KERNEL);
 	if (!aon_chan)
@@ -217,8 +218,9 @@ struct th1520_aon_chan *th1520_aon_init(struct device *dev)
 	aon_chan->ch = mbox_request_channel_byname(cl, "aon");
 	if (IS_ERR(aon_chan->ch)) {
 		dev_err(dev, "Failed to request aon mbox chan\n");
+		ret = PTR_ERR(aon_chan->ch);
 		kfree(aon_chan);
-		return ERR_CAST(aon_chan->ch);
+		return ERR_PTR(ret);
 	}
 
 	mutex_init(&aon_chan->transaction_lock);
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-03-18 12:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-15 10:04 [PATCH next] firmware: thead,th1520-aon: Fix use after free in th1520_aon_init() Dan Carpenter
2025-03-15 10:04 ` Dan Carpenter
2025-03-16 12:05 ` Markus Elfring
2025-03-16 12:05   ` Markus Elfring
2025-03-16 14:20   ` Dan Carpenter
2025-03-16 14:20     ` Dan Carpenter
2025-03-18 12:14 ` Ulf Hansson
2025-03-18 12:14   ` Ulf Hansson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.