diff mbox series

[v2] mmc: sh_mmcif: Check for null res pointer

Message ID 20220119120006.1426964-1-jiasheng@iscas.ac.cn (mailing list archive)
State New, archived
Headers show
Series [v2] mmc: sh_mmcif: Check for null res pointer | expand

Commit Message

Jiasheng Jiang Jan. 19, 2022, noon UTC
If there is no suitable resource, platform_get_resource() will return
NULL.
Therefore in order to avoid the dereference of the NULL pointer, it
should be better to check the 'res'.

Fixes: df0cc57e057f ("Linux 5.16")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
Changelog

v1 -> v2

* Change 1. Change the fixes tag to v5.16.
---
 drivers/mmc/host/sh_mmcif.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Ulf Hansson Jan. 21, 2022, 2:32 p.m. UTC | #1
On Wed, 19 Jan 2022 at 13:00, Jiasheng Jiang <jiasheng@iscas.ac.cn> wrote:
>
> If there is no suitable resource, platform_get_resource() will return
> NULL.
> Therefore in order to avoid the dereference of the NULL pointer, it
> should be better to check the 'res'.
>
> Fixes: df0cc57e057f ("Linux 5.16")

I have changed this to:
Cc: stable@vger.kernel.org # v5.16+

> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>

Applied for fixes, thanks!

Kind regards
Uffe


> ---
> Changelog
>
> v1 -> v2
>
> * Change 1. Change the fixes tag to v5.16.
> ---
>  drivers/mmc/host/sh_mmcif.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
> index e5e457037235..45dfa3b0be9c 100644
> --- a/drivers/mmc/host/sh_mmcif.c
> +++ b/drivers/mmc/host/sh_mmcif.c
> @@ -405,6 +405,9 @@ static int sh_mmcif_dma_slave_config(struct sh_mmcif_host *host,
>         struct dma_slave_config cfg = { 0, };
>
>         res = platform_get_resource(host->pd, IORESOURCE_MEM, 0);
> +       if (!res)
> +               return -EINVAL;
> +
>         cfg.direction = direction;
>
>         if (direction == DMA_DEV_TO_MEM) {
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
index e5e457037235..45dfa3b0be9c 100644
--- a/drivers/mmc/host/sh_mmcif.c
+++ b/drivers/mmc/host/sh_mmcif.c
@@ -405,6 +405,9 @@  static int sh_mmcif_dma_slave_config(struct sh_mmcif_host *host,
 	struct dma_slave_config cfg = { 0, };
 
 	res = platform_get_resource(host->pd, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
+
 	cfg.direction = direction;
 
 	if (direction == DMA_DEV_TO_MEM) {