Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH] pinctrl: qcom: sc8180x: gracefully handle missing IO memory resource
@ 2023-05-13 11:35 Krzysztof Kozlowski
  2023-05-15  1:38 ` Bjorn Andersson
  2023-05-16 13:26 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2023-05-13 11:35 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Linus Walleij,
	linux-arm-msm, linux-gpio, linux-kernel
  Cc: Krzysztof Kozlowski

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>
---
 drivers/pinctrl/qcom/pinctrl-sc8180x.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/qcom/pinctrl-sc8180x.c b/drivers/pinctrl/qcom/pinctrl-sc8180x.c
index 704a99d2f93c..2fabec096aae 100644
--- a/drivers/pinctrl/qcom/pinctrl-sc8180x.c
+++ b/drivers/pinctrl/qcom/pinctrl-sc8180x.c
@@ -1630,7 +1630,8 @@ static const struct msm_pinctrl_soc_data sc8180x_acpi_pinctrl = {
 static int sc8180x_pinctrl_add_tile_resources(struct platform_device *pdev)
 {
 	int nres_num = pdev->num_resources + ARRAY_SIZE(sc8180x_tiles) - 1;
-	struct resource *mres, *nres, *res;
+	struct resource *mres = NULL;
+	struct resource *nres, *res;
 	int i, ret;
 
 	/*
@@ -1657,6 +1658,9 @@ static int sc8180x_pinctrl_add_tile_resources(struct platform_device *pdev)
 			*res++ = *r;
 	}
 
+	if (!mres)
+		return -EINVAL;
+
 	/* Append tile memory resources */
 	for (i = 0; i < ARRAY_SIZE(sc8180x_tiles); i++, res++) {
 		const struct tile_info *info = &sc8180x_tile_info[i];
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: qcom: sc8180x: gracefully handle missing IO memory resource
  2023-05-13 11:35 [PATCH] pinctrl: qcom: sc8180x: gracefully handle missing IO memory resource Krzysztof Kozlowski
@ 2023-05-15  1:38 ` Bjorn Andersson
  2023-05-16 13:26 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Andersson @ 2023-05-15  1:38 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Andy Gross, Konrad Dybcio, Linus Walleij, linux-arm-msm,
	linux-gpio, linux-kernel

On Sat, May 13, 2023 at 01:35:10PM +0200, Krzysztof Kozlowski wrote:
> 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>

> ---
>  drivers/pinctrl/qcom/pinctrl-sc8180x.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pinctrl/qcom/pinctrl-sc8180x.c b/drivers/pinctrl/qcom/pinctrl-sc8180x.c
> index 704a99d2f93c..2fabec096aae 100644
> --- a/drivers/pinctrl/qcom/pinctrl-sc8180x.c
> +++ b/drivers/pinctrl/qcom/pinctrl-sc8180x.c
> @@ -1630,7 +1630,8 @@ static const struct msm_pinctrl_soc_data sc8180x_acpi_pinctrl = {
>  static int sc8180x_pinctrl_add_tile_resources(struct platform_device *pdev)
>  {
>  	int nres_num = pdev->num_resources + ARRAY_SIZE(sc8180x_tiles) - 1;
> -	struct resource *mres, *nres, *res;
> +	struct resource *mres = NULL;
> +	struct resource *nres, *res;
>  	int i, ret;
>  
>  	/*
> @@ -1657,6 +1658,9 @@ static int sc8180x_pinctrl_add_tile_resources(struct platform_device *pdev)
>  			*res++ = *r;
>  	}
>  
> +	if (!mres)
> +		return -EINVAL;
> +
>  	/* Append tile memory resources */
>  	for (i = 0; i < ARRAY_SIZE(sc8180x_tiles); i++, res++) {
>  		const struct tile_info *info = &sc8180x_tile_info[i];
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: qcom: sc8180x: gracefully handle missing IO memory resource
  2023-05-13 11:35 [PATCH] pinctrl: qcom: sc8180x: gracefully handle missing IO memory resource Krzysztof Kozlowski
  2023-05-15  1:38 ` Bjorn Andersson
@ 2023-05-16 13:26 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2023-05-16 13:26 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, linux-arm-msm,
	linux-gpio, linux-kernel

On Sat, May 13, 2023 at 1:35 PM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:

> 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>

Patch applied as non-urgent fix.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-16 13:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-13 11:35 [PATCH] pinctrl: qcom: sc8180x: gracefully handle missing IO memory resource Krzysztof Kozlowski
2023-05-15  1:38 ` Bjorn Andersson
2023-05-16 13:26 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox