Re: [PATCH v3] spi: ppc4xx: handle irq_of_parse_and_map() errors

lee.lockhey
2024-08-18T22:02:42Z

Hello, Mark

On Mon, 22 Jul 2024 at 22:19, Ma Ke <make24@iscas.ac.cn> wrote:
>
> Zero and negative number is not a valid IRQ for in-kernel code and the
> irq_of_parse_and_map() function returns zero on error. So this check for
> valid IRQs should only accept values > 0.
>
> Fixes: 44dab88e7cc9 ("spi: add spi_ppc4xx driver")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
> Changes in v3:
> - removed Cc stable line as suggestions.
> Changes in v2:
> - added Cc stable line;
> - added Fixes line.
> ---
> drivers/spi/spi-ppc4xx.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/spi/spi-ppc4xx.c b/drivers/spi/spi-ppc4xx.c
> index 01fdecbf132d..599c29a31269 100644
> --- a/drivers/spi/spi-ppc4xx.c
> +++ b/drivers/spi/spi-ppc4xx.c
> @@ -416,6 +416,9 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)
> if (hw->irqnum <= 0)
> goto free_host;
>

The repeated addition of code here is indeed confusing. :-)

> + if (hw->irqnum <= 0)
> + goto free_host;
> +

I noticed that this patch has been merged into the spi repository for-next tree:
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git/commit/?id=f1011ba20b83da3ee70dcb4a6d9d282a718916fa
and there is also a related patch:
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git/commit/?id=7781f1d120fec8624fc654eda900fc8748262082

The return type of the 'irq_of_parse_and_map' function is 'unsigned
int', here we use an 'int' type variable 'irq' to receive the interrupt number,
this might not be very accurate.

Would it be better to change the type of the 'irqnum' variable? and do
not need to check if 'irqnum' is negative, like this:

if (!hw->irqnum) {
dev_err(dev, "no IRQ resource\n");
ret = -EINVAL;
goto free_host;
}

> ret = request_irq(hw->irqnum, spi_ppc4xx_int,
> 0, "spi_ppc4xx_of", (void *)hw);
> if (ret) {
> --
> 2.25.1
>
>

Regards,
Luoxi