Skip to content

Commit 5de6ef4

Browse files
elfringmathieupoirier
authored andcommitted
remoteproc: imx_dsp_rproc: Improve exception handling in imx_dsp_rproc_mbox_alloc()
The label “err_out” was used to jump to another pointer check despite of the detail in the implementation of the function “imx_dsp_rproc_mbox_alloc” that it was determined already that the corresponding variable contained an error pointer because of a failed call of the function “mbox_request_channel_byname”. Thus perform the following adjustments: 1. Return directly after a call of the function “mbox_request_channel_byname” failed for the input parameter “tx”. 2. Use more appropriate labels instead. 3. Reorder jump targets at the end. 4. Omit a function call and three extra checks. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Link: https://lore.kernel.org/r/d0e18bb1-afc4-8b6f-bb1c-b74b3bad908e@web.de Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
1 parent 3a87fc6 commit 5de6ef4

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

drivers/remoteproc/imx_dsp_rproc.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ static int imx_dsp_rproc_mbox_alloc(struct imx_dsp_rproc *priv)
530530
ret = PTR_ERR(priv->tx_ch);
531531
dev_dbg(cl->dev, "failed to request tx mailbox channel: %d\n",
532532
ret);
533-
goto err_out;
533+
return ret;
534534
}
535535

536536
/* Channel for receiving message */
@@ -539,7 +539,7 @@ static int imx_dsp_rproc_mbox_alloc(struct imx_dsp_rproc *priv)
539539
ret = PTR_ERR(priv->rx_ch);
540540
dev_dbg(cl->dev, "failed to request rx mailbox channel: %d\n",
541541
ret);
542-
goto err_out;
542+
goto free_channel_tx;
543543
}
544544

545545
cl = &priv->cl_rxdb;
@@ -555,19 +555,15 @@ static int imx_dsp_rproc_mbox_alloc(struct imx_dsp_rproc *priv)
555555
ret = PTR_ERR(priv->rxdb_ch);
556556
dev_dbg(cl->dev, "failed to request mbox chan rxdb, ret %d\n",
557557
ret);
558-
goto err_out;
558+
goto free_channel_rx;
559559
}
560560

561561
return 0;
562562

563-
err_out:
564-
if (!IS_ERR(priv->tx_ch))
565-
mbox_free_channel(priv->tx_ch);
566-
if (!IS_ERR(priv->rx_ch))
567-
mbox_free_channel(priv->rx_ch);
568-
if (!IS_ERR(priv->rxdb_ch))
569-
mbox_free_channel(priv->rxdb_ch);
570-
563+
free_channel_rx:
564+
mbox_free_channel(priv->rx_ch);
565+
free_channel_tx:
566+
mbox_free_channel(priv->tx_ch);
571567
return ret;
572568
}
573569

0 commit comments

Comments
 (0)