Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl: qcom: sc8180x: gracefully handle missing IO memory resource

If device was probed with incorrect DT or ACPI tables, the IO memory
resource would be missing and driver would derefernce NULL pointer in
sc8180x_pinctrl_add_tile_resources(). Add simplep check if IO memory
resource was provided to silence Smatch warning:

drivers/pinctrl/qcom/pinctrl-sc8180x.c:1664 sc8180x_pinctrl_add_tile_resources() error: potentially dereferencing uninitialized 'mres'.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Bjorn Andersson <andersson@kernel.org>
Link: https://lore.kernel.org/r/20230513113510.177666-1-krzysztof.kozlowski@linaro.org
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Krzysztof Kozlowski and committed by
Linus Walleij
070a10d6 6a16d1a5

+5 -1
+5 -1
drivers/pinctrl/qcom/pinctrl-sc8180x.c
··· 1622 1622 static int sc8180x_pinctrl_add_tile_resources(struct platform_device *pdev) 1623 1623 { 1624 1624 int nres_num = pdev->num_resources + ARRAY_SIZE(sc8180x_tiles) - 1; 1625 - struct resource *mres, *nres, *res; 1625 + struct resource *mres = NULL; 1626 + struct resource *nres, *res; 1626 1627 int i, ret; 1627 1628 1628 1629 /* ··· 1649 1648 else 1650 1649 *res++ = *r; 1651 1650 } 1651 + 1652 + if (!mres) 1653 + return -EINVAL; 1652 1654 1653 1655 /* Append tile memory resources */ 1654 1656 for (i = 0; i < ARRAY_SIZE(sc8180x_tiles); i++, res++) {