Re: [PATCH 1/3] mmc: meson-gx: Handle errors from optional IRQ lookup

[email protected]
Newsgroups org.infradead.lists.linux-amlogic
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Uninitialized variable usage in `meson_mmc_probe()`: `cd_irq` is passed to `mmc_gpio_set_cd_irq()` without being initialized when the optional IRQ is not present.
--

--- Patch [1]: [PATCH 1/3] mmc: meson-gx: Handle errors from optional IRQ lookup ---
commit 050320309b9f222bb3f134cc08b3a48c3a62f6c8
Author: bui duc phuc <[email protected]>

mmc: meson-gx: Handle errors from optional IRQ lookup

This commit updates the optional IRQ lookup in meson_mmc_probe() to
properly propagate errors other than -ENXIO. It also assigns the fetched
IRQ to cd_irq only if a valid positive number is returned.

> diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c
> --- a/drivers/mmc/host/meson-gx-mmc.c
> +++ b/drivers/mmc/host/meson-gx-mmc.c
> @@ -1185,7 +1185,11 @@ static int meson_mmc_probe(struct platform_device *pdev)
>  	if (host->irq < 0)
>  		return host->irq;
>  
> -	cd_irq = platform_get_irq_optional(pdev, 1);
> +	ret = platform_get_irq_optional(pdev, 1);
> +	if (ret < 0 && ret != -ENXIO)
> +		return ret;
> +	if (ret > 0)
> +		cd_irq = ret;
>  	mmc_gpio_set_cd_irq(mmc, cd_irq);

[Severity: High]
Does this code pass an uninitialized variable to mmc_gpio_set_cd_irq()
when the optional IRQ is not present?

If platform_get_irq_optional() returns -ENXIO, the assignment to cd_irq
is skipped. The uninitialized cd_irq variable is then passed to
mmc_gpio_set_cd_irq().

If the uninitialized stack value happens to be >= 0, mmc_gpio_set_cd_irq()
will accept it and overwrite the card-detect IRQ configuration with an
invalid or random IRQ number.

Could cd_irq be initialized to a negative value when it is declared?

>  
>  	host->pinctrl = devm_pinctrl_get(&pdev->dev);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.