Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firmware: thead,th1520-aon: Fix use after free in th1520_aon_init()

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>

authored by

Dan Carpenter and committed by
Ulf Hansson
ae85dabc 6cf5db71

+3 -1
+3 -1
drivers/firmware/thead,th1520-aon.c
··· 203 203 { 204 204 struct th1520_aon_chan *aon_chan; 205 205 struct mbox_client *cl; 206 + int ret; 206 207 207 208 aon_chan = kzalloc(sizeof(*aon_chan), GFP_KERNEL); 208 209 if (!aon_chan) ··· 218 217 aon_chan->ch = mbox_request_channel_byname(cl, "aon"); 219 218 if (IS_ERR(aon_chan->ch)) { 220 219 dev_err(dev, "Failed to request aon mbox chan\n"); 220 + ret = PTR_ERR(aon_chan->ch); 221 221 kfree(aon_chan); 222 - return ERR_CAST(aon_chan->ch); 222 + return ERR_PTR(ret); 223 223 } 224 224 225 225 mutex_init(&aon_chan->transaction_lock);