firmware: thead,th1520-aon: Fix use after free in th1520_aon_init()
authorDan Carpenter <dan.carpenter@linaro.org>
Sat, 15 Mar 2025 10:04:24 +0000 (13:04 +0300)
committerUlf Hansson <ulf.hansson@linaro.org>
Tue, 18 Mar 2025 12:09:00 +0000 (13:09 +0100)
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>
Link: https://lore.kernel.org/r/f19be994-d355-48a6-ab45-d0f7e5955daf@stanley.mountain
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/firmware/thead,th1520-aon.c

index 4416e9bbf854ce0ad2d04e7d11eb5d2667a2372f..38f812ac9920e36ec16e058f81cec2ca05d67c25 100644 (file)
@@ -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);