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

remoteproc: k3: Correctly release some resources allocated in k3_rproc_request_mbox()

If an error occurs after a successful k3_rproc_request_mbox() call,
mbox_free_channel() should be called to avoid a leak.

Such a call is missing in the error handling path of k3_dsp_rproc_probe().
It is also missing both in the error handling path of k3_m4_rproc_probe()
and in the (in-existent) corresponding remove function.

Switch to managed resources to avoid these leaks and simplify the code.
Remove the now unneeded mbox_free_channel().

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Beleswar Padhi <b-padhi@ti.com>
Tested-by: Beleswar Padhi <b-padhi@ti.com>
Link: https://lore.kernel.org/r/df853ede72e9972c464415990b196289680e6acb.1756065142.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>

authored by

Christophe JAILLET and committed by
Mathieu Poirier
24339619 3df0bee9

+12 -4
+12
drivers/remoteproc/ti_k3_common.c
··· 155 155 } 156 156 EXPORT_SYMBOL_GPL(k3_rproc_release); 157 157 158 + static void k3_rproc_free_channel(void *data) 159 + { 160 + struct k3_rproc *kproc = data; 161 + 162 + mbox_free_channel(kproc->mbox); 163 + } 164 + 158 165 int k3_rproc_request_mbox(struct rproc *rproc) 159 166 { 160 167 struct k3_rproc *kproc = rproc->priv; 161 168 struct mbox_client *client = &kproc->client; 162 169 struct device *dev = kproc->dev; 170 + int ret; 163 171 164 172 client->dev = dev; 165 173 client->tx_done = NULL; ··· 179 171 if (IS_ERR(kproc->mbox)) 180 172 return dev_err_probe(dev, PTR_ERR(kproc->mbox), 181 173 "mbox_request_channel failed\n"); 174 + 175 + ret = devm_add_action_or_reset(dev, k3_rproc_free_channel, kproc); 176 + if (ret) 177 + return ret; 182 178 183 179 return 0; 184 180 }
-2
drivers/remoteproc/ti_k3_dsp_remoteproc.c
··· 175 175 if (ret) 176 176 dev_err(dev, "failed to detach proc (%pe)\n", ERR_PTR(ret)); 177 177 } 178 - 179 - mbox_free_channel(kproc->mbox); 180 178 } 181 179 182 180 static const struct k3_rproc_mem_data c66_mems[] = {
-2
drivers/remoteproc/ti_k3_r5_remoteproc.c
··· 1206 1206 return; 1207 1207 } 1208 1208 } 1209 - 1210 - mbox_free_channel(kproc->mbox); 1211 1209 } 1212 1210 } 1213 1211