diff mbox series

ASoC: sh: rz-ssi: Improve error handling in rz_ssi_dma_request function

Message ID 20210814134106.14275-1-biju.das.jz@bp.renesas.com
State Superseded
Headers show
Series ASoC: sh: rz-ssi: Improve error handling in rz_ssi_dma_request function | expand

Commit Message

Biju Das Aug. 14, 2021, 1:41 p.m. UTC
The rz_ssi_dma_request function only checks the NULL condition for
the value returned by the dma_request_chan function, but this function
can also return an error. If it happens, the subsequent function call to
rz_ssi_dma_slave_config can lead to a kernel crash.

This patch fixes the issue by checking both error and NULL condition
returned by dma_request_chan.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
 sound/soc/sh/rz-ssi.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Biju Das Aug. 15, 2021, 6:58 a.m. UTC | #1
Hi All,

I have send v2. So please drop this patch.

Cheers,
Biju

> -----Original Message-----
> From: Biju Das <biju.das.jz@bp.renesas.com>
> Sent: 14 August 2021 14:41
> To: Jaroslav Kysela <perex@perex.cz>; Takashi Iwai <tiwai@suse.com>
> Cc: Biju Das <biju.das.jz@bp.renesas.com>; Liam Girdwood
> <lgirdwood@gmail.com>; Mark Brown <broonie@kernel.org>; Prabhakar Mahadev
> Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>; alsa-devel@alsa-
> project.org; Geert Uytterhoeven <geert+renesas@glider.be>; Chris Paterson
> <Chris.Paterson2@renesas.com>; Biju Das <biju.das@bp.renesas.com>; linux-
> renesas-soc@vger.kernel.org
> Subject: [PATCH] ASoC: sh: rz-ssi: Improve error handling in
> rz_ssi_dma_request function
> 
> The rz_ssi_dma_request function only checks the NULL condition for the
> value returned by the dma_request_chan function, but this function can
> also return an error. If it happens, the subsequent function call to
> rz_ssi_dma_slave_config can lead to a kernel crash.
> 
> This patch fixes the issue by checking both error and NULL condition
> returned by dma_request_chan.
> 
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
>  sound/soc/sh/rz-ssi.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c index
> ea8d33ede5d2..3867e2efd3e0 100644
> --- a/sound/soc/sh/rz-ssi.c
> +++ b/sound/soc/sh/rz-ssi.c
> @@ -676,11 +676,19 @@ static void rz_ssi_release_dma_channels(struct
> rz_ssi_priv *ssi)  static int rz_ssi_dma_request(struct rz_ssi_priv *ssi,
> struct device *dev)  {
>  	ssi->playback.dma_ch = dma_request_chan(dev, "tx");
> +	if (IS_ERR_OR_NULL(ssi->playback.dma_ch))
> +		ssi->playback.dma_ch = NULL;
> +
>  	ssi->capture.dma_ch = dma_request_chan(dev, "rx");
> +	if (IS_ERR_OR_NULL(ssi->capture.dma_ch))
> +		ssi->capture.dma_ch = NULL;
> +
>  	if (!ssi->playback.dma_ch && !ssi->capture.dma_ch) {
>  		ssi->playback.dma_ch = dma_request_chan(dev, "rt");
> -		if (!ssi->playback.dma_ch)
> +		if (IS_ERR_OR_NULL(ssi->playback.dma_ch)) {
> +			ssi->playback.dma_ch = NULL;
>  			goto no_dma;
> +		}
> 
>  		ssi->dma_rt = true;
>  	}
> --
> 2.17.1
diff mbox series

Patch

diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c
index ea8d33ede5d2..3867e2efd3e0 100644
--- a/sound/soc/sh/rz-ssi.c
+++ b/sound/soc/sh/rz-ssi.c
@@ -676,11 +676,19 @@  static void rz_ssi_release_dma_channels(struct rz_ssi_priv *ssi)
 static int rz_ssi_dma_request(struct rz_ssi_priv *ssi, struct device *dev)
 {
 	ssi->playback.dma_ch = dma_request_chan(dev, "tx");
+	if (IS_ERR_OR_NULL(ssi->playback.dma_ch))
+		ssi->playback.dma_ch = NULL;
+
 	ssi->capture.dma_ch = dma_request_chan(dev, "rx");
+	if (IS_ERR_OR_NULL(ssi->capture.dma_ch))
+		ssi->capture.dma_ch = NULL;
+
 	if (!ssi->playback.dma_ch && !ssi->capture.dma_ch) {
 		ssi->playback.dma_ch = dma_request_chan(dev, "rt");
-		if (!ssi->playback.dma_ch)
+		if (IS_ERR_OR_NULL(ssi->playback.dma_ch)) {
+			ssi->playback.dma_ch = NULL;
 			goto no_dma;
+		}
 
 		ssi->dma_rt = true;
 	}