From patchwork Thu Apr 6 20:12:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 13204079 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E0309C7618D for ; Thu, 6 Apr 2023 20:14:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Cc:References:To:From: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+k6gSqtuWonA99IY+InC34lAxV96N7bc0gaAufhzFOo=; b=p8uvEAp0BdP/Xs XeW6QHEO8t3xeiEBfa4yIx+eMzKCWPUMZrJU2jKhAAU1V9M5kfCujJAS34+T42n/ShQMhkY488B8D L9rtUob2EkNo5/RL2ITxCpezb9LXey+DcntEG65LdgAvVE88Ky3agFaMzKBOb64ueu3aMvpQjQSjY nGDk0YEDhNXetFwzEks83dFxqBk3GA/XSEtTma7qcTdskPrtPiWTR5VPrVsTTL1GSv4ll9/CsKFda Hw/i28Xz/sKggasCyeoFtp+TxUfzxNFcU9K2sslrNOGBECJFK1uTBJ7XlTmAsKBBGiv/b6rlXXmSw bwhNVrKq4LCvLDB6lMzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pkVzB-008UeP-1P; Thu, 06 Apr 2023 20:13:33 +0000 Received: from mout.web.de ([212.227.15.4]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pkVyp-008UbZ-2A for linux-arm-kernel@lists.infradead.org; Thu, 06 Apr 2023 20:13:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680811983; i=markus.elfring@web.de; bh=lCyzkQM8fmATzWhZ/tEMak18vAfp/98FN5R/RegYVzE=; h=X-UI-Sender-Class:Date:Subject:From:To:References:Cc:In-Reply-To; b=tecFnqPt/I/dzCwkm/H5RYYCKIov4UCTkIzER3YXZ9s2TByw5ch3ZDfe5RU8EZqVV lgX3/dNbUQPypEBMNB3hm81AJRAFl1QFgigvqPxtsrB5dEnoKBxbSoKs25GHfeLSmD 97Uqd71z/R6yDspAf29fsWugciPukni2ffau9Ilx6AOxPGqiyMUu0g5M+aWUw2JCSV QQQwe+RfummwVHx9Vk8aDxuAPD3PiaJJXSE4mc6bM6TEotpLaCEXUYppI97y/1Eq+1 XsnVbddiI7i8COV9u8zpL4AuOGyRyNGdgLE8oEIxc4AL3uP+ER7plh3ky/zV+m45n6 8Hlx2kFwem3dw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.90.83]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MBjIG-1pYNxz0c6W-00CEDO; Thu, 06 Apr 2023 22:13:03 +0200 Message-ID: Date: Thu, 6 Apr 2023 22:12:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: [PATCH] remoteproc: imx_dsp_rproc: Improve exception handling in imx_dsp_rproc_mbox_alloc() From: Markus Elfring To: kernel-janitors@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com, kernel@pengutronix.de, Bjorn Andersson , Fabio Estevam , Mathieu Poirier , Sascha Hauer , Shawn Guo References: <8f785de5-ebe2-edd9-2155-f440acacc643@web.de> Content-Language: en-GB Cc: cocci@inria.fr, LKML In-Reply-To: <8f785de5-ebe2-edd9-2155-f440acacc643@web.de> X-Provags-ID: V03:K1:sX5p4BLuPV4di+aEjXWQd0O1GDpQNMM3XDnN58NHlUkgGFbrBn0 EXc2QYm+ytljy7Z6cp+IrTBOvdieRHXQC/BK/125UfqCQyocEbxYE0vGHirjgQKSi/Vd785 WxzorggylchNdCZzSlouyvAsOPwxrIBKYSUoncp4q8DLCceIVY2SoXMKszkQH4ghZd6XCCf 6GRMWSZtBuF+jV2cd0GNg== UI-OutboundReport: notjunk:1;M01:P0:WCNp9R+38Dw=;i3BS3WD6LfR5v0Ak1gJmoXkz9Fc B0uhTVnNQ1i2QfudOf7fsbAKFelzbT8geYZDPfMcbSrJdlzd2c5HFWc4V/nZrSAEAJMDRZnXz Ab2VWe15nmKHrXtoGQhMoyhWjJtvHHIBfi++0lXbqS8CMq4Esk9i9clL5veWDRkeyhMrN2jqN 0MBufzFu1mR+p0nxI+ooJejPdKufw3VzizTeDjFFqFLE7qmMXZcEq/U4scL/Js51gEIJTcyAt ukxvhJN1jZof5s+LPObUOCKc+rfbki5NNbZcQjw+79szp+wqsL9YznBzNI5N40V0fYxG/jUBh bxNFvLa0E2ul3wcDTC4LuL2TGy0myH55VVFfLw6PJAPbloXxu8G4dwyX6KhftqWBH+4Eq34SC LJG/6EJLQ/zYnaPsb36fqG8JemqmehmbGWmDRR9azoYEbjtV8Fns0E+iYNbAA9RGiq3wez3lu xx31A4OmWlak7qjz7Dk0S6YVSHyRlzGu3v2Ti3M8GMZOQJh+YA05/CvxY1KgzjtsWeJk/L78d Q3UcNNBWn6UZYP46CYVWhUbQ8PqpplKsn0xi5471zSTode6R+/4vslkrBqfyV91N0kX5xGjyS Uta96IJ+gP2QipiF+dj22E7felMcl4HekwJM1vqp9slzRK1G7fLgkBPCeXQOFJG1KpqbR1rBZ rCVb8mPtGJtNtbuR2cD00DLH7LXVwPnXb45i7k7i0C4AENe5/eKxtrRyOt84+oJ/Fo0hArW6+ jJx2aWBU2XliKCfjnk+Wfp2+idKkV3WnAy7oZt6jkbUrhzZrKsn9Y6DU+e/q5n+LIa+qwCWYC DI8sWUVveCypDUWzkMCVYHKuxHbYC5czF2WA3YDEfpOS6TQQVLO3M5Z9CWWgirRQ9lKCrV/GJ GVPDKdZyNGgJydYmA821sJ5iVoIxhbd3CI+RSj8q9t8A23WOc9AuTAq6+ X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230406_131312_178975_85EA1390 X-CRM114-Status: GOOD ( 11.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Date: Thu, 6 Apr 2023 22:00:24 +0200 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 --- drivers/remoteproc/imx_dsp_rproc.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) -- 2.40.0 diff --git a/drivers/remoteproc/imx_dsp_rproc.c b/drivers/remoteproc/imx_dsp_rproc.c index 21759d9e5b7b..a8ad15ef1da0 100644 --- a/drivers/remoteproc/imx_dsp_rproc.c +++ b/drivers/remoteproc/imx_dsp_rproc.c @@ -530,7 +530,7 @@ static int imx_dsp_rproc_mbox_alloc(struct imx_dsp_rproc *priv) ret = PTR_ERR(priv->tx_ch); dev_dbg(cl->dev, "failed to request tx mailbox channel: %d\n", ret); - goto err_out; + return ret; } /* Channel for receiving message */ @@ -539,7 +539,7 @@ static int imx_dsp_rproc_mbox_alloc(struct imx_dsp_rproc *priv) ret = PTR_ERR(priv->rx_ch); dev_dbg(cl->dev, "failed to request rx mailbox channel: %d\n", ret); - goto err_out; + goto free_channel_tx; } cl = &priv->cl_rxdb; @@ -555,19 +555,15 @@ static int imx_dsp_rproc_mbox_alloc(struct imx_dsp_rproc *priv) ret = PTR_ERR(priv->rxdb_ch); dev_dbg(cl->dev, "failed to request mbox chan rxdb, ret %d\n", ret); - goto err_out; + goto free_channel_rx; } return 0; -err_out: - if (!IS_ERR(priv->tx_ch)) - mbox_free_channel(priv->tx_ch); - if (!IS_ERR(priv->rx_ch)) - mbox_free_channel(priv->rx_ch); - if (!IS_ERR(priv->rxdb_ch)) - mbox_free_channel(priv->rxdb_ch); - +free_channel_rx: + mbox_free_channel(priv->rx_ch); +free_channel_tx: + mbox_free_channel(priv->tx_ch); return ret; }