Re: [PATCH] sh: dma: Add missing IS_ERR test

From: Geert Uytterhoeven
Date: Sat Jun 08 2019 - 08:31:20 EST


Hi Rolf,

Thanks for your patch!

On Fri, Jun 7, 2019 at 2:04 PM Rolf Evers-Fischer
<embedded24@xxxxxxxxxxxxxxxx> wrote:
> get_dma_channel may return ERR_PTR, so a check is added.

It may also return NULL...

> --- a/arch/sh/drivers/dma/dma-api.c
> +++ b/arch/sh/drivers/dma/dma-api.c
> @@ -94,7 +94,7 @@ int get_dma_residue(unsigned int chan)
> struct dma_info *info = get_dma_info(chan);
> struct dma_channel *channel = get_dma_channel(chan);
>
> - if (info->ops->get_residue)
> + if (!IS_ERR(channel) && (info->ops->get_residue))
> return info->ops->get_residue(channel);

... in which case .get_residue() may crash, as some implementations
dereference the passed channel pointer.

Hence !IS_ERR_OR_NULL()?

I didn't check the other callers.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds