Linux-OMAP Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] ARM: OMAP: Fix use of possibly uninitialized irq variable
@ 2021-04-01 16:11 Maciej Falkowski
  2021-04-01 16:45 ` Nathan Chancellor
  2021-04-01 19:05 ` Nick Desaulniers
  0 siblings, 2 replies; 3+ messages in thread
From: Maciej Falkowski @ 2021-04-01 16:11 UTC (permalink / raw)
  To: khilman, aaro.koskinen, tony, linux
  Cc: linux-omap, linux-arm-kernel, linux-kernel, clang-built-linux,
	maciej.falkowski9

The current control flow of IRQ number assignment to `irq` variable
allows a request of IRQ of unspecified value,
generating a warning under Clang compilation with omap1_defconfig on linux-next:

arch/arm/mach-omap1/pm.c:656:11: warning: variable 'irq' is used uninitialized whenever
'if' condition is false [-Wsometimes-uninitialized]
        else if (cpu_is_omap16xx())
                 ^~~~~~~~~~~~~~~~~
./arch/arm/mach-omap1/include/mach/soc.h:123:30: note: expanded from macro 'cpu_is_omap16xx'
                                        ^~~~~~~~~~~~~
arch/arm/mach-omap1/pm.c:658:18: note: uninitialized use occurs here
        if (request_irq(irq, omap_wakeup_interrupt, 0, "peripheral wakeup",
                        ^~~
arch/arm/mach-omap1/pm.c:656:7: note: remove the 'if' if its condition is always true
        else if (cpu_is_omap16xx())
             ^~~~~~~~~~~~~~~~~~~~~~
arch/arm/mach-omap1/pm.c:611:9: note: initialize the variable 'irq' to silence this warning
        int irq;
               ^
                = 0
1 warning generated.

The patch provides a default value to the `irq` variable
along with a validity check.

Signed-off-by: Maciej Falkowski <maciej.falkowski9@gmail.com>
Link: https://github.com/ClangBuiltLinux/linux/issues/1324
---
 arch/arm/mach-omap1/pm.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-omap1/pm.c b/arch/arm/mach-omap1/pm.c
index 2c1e2b32b9b3..a745d64d4699 100644
--- a/arch/arm/mach-omap1/pm.c
+++ b/arch/arm/mach-omap1/pm.c
@@ -655,9 +655,13 @@ static int __init omap_pm_init(void)
 		irq = INT_7XX_WAKE_UP_REQ;
 	else if (cpu_is_omap16xx())
 		irq = INT_1610_WAKE_UP_REQ;
-	if (request_irq(irq, omap_wakeup_interrupt, 0, "peripheral wakeup",
-			NULL))
-		pr_err("Failed to request irq %d (peripheral wakeup)\n", irq);
+	else
+		irq = -1;
+
+	if (irq >= 0) {
+		if (request_irq(irq, omap_wakeup_interrupt, 0, "peripheral wakeup", NULL))
+			pr_err("Failed to request irq %d (peripheral wakeup)\n", irq);
+	}
 
 	/* Program new power ramp-up time
 	 * (0 for most boards since we don't lower voltage when in deep sleep)
-- 
2.26.3


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

* Re: [PATCH] ARM: OMAP: Fix use of possibly uninitialized irq variable
  2021-04-01 16:11 [PATCH] ARM: OMAP: Fix use of possibly uninitialized irq variable Maciej Falkowski
@ 2021-04-01 16:45 ` Nathan Chancellor
  2021-04-01 19:05 ` Nick Desaulniers
  1 sibling, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2021-04-01 16:45 UTC (permalink / raw)
  To: Maciej Falkowski
  Cc: khilman, aaro.koskinen, tony, linux, linux-omap,
	linux-arm-kernel, linux-kernel, clang-built-linux

On Thu, Apr 01, 2021 at 06:11:27PM +0200, Maciej Falkowski wrote:
> The current control flow of IRQ number assignment to `irq` variable
> allows a request of IRQ of unspecified value,
> generating a warning under Clang compilation with omap1_defconfig on linux-next:
> 
> arch/arm/mach-omap1/pm.c:656:11: warning: variable 'irq' is used uninitialized whenever
> 'if' condition is false [-Wsometimes-uninitialized]
>         else if (cpu_is_omap16xx())
>                  ^~~~~~~~~~~~~~~~~
> ./arch/arm/mach-omap1/include/mach/soc.h:123:30: note: expanded from macro 'cpu_is_omap16xx'
>                                         ^~~~~~~~~~~~~
> arch/arm/mach-omap1/pm.c:658:18: note: uninitialized use occurs here
>         if (request_irq(irq, omap_wakeup_interrupt, 0, "peripheral wakeup",
>                         ^~~
> arch/arm/mach-omap1/pm.c:656:7: note: remove the 'if' if its condition is always true
>         else if (cpu_is_omap16xx())
>              ^~~~~~~~~~~~~~~~~~~~~~
> arch/arm/mach-omap1/pm.c:611:9: note: initialize the variable 'irq' to silence this warning
>         int irq;
>                ^
>                 = 0
> 1 warning generated.
> 
> The patch provides a default value to the `irq` variable
> along with a validity check.
> 

Might be worth a fixes tag:

Fixes: b75ca5217743 ("ARM: OMAP: replace setup_irq() by request_irq()")

> Signed-off-by: Maciej Falkowski <maciej.falkowski9@gmail.com>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1324

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  arch/arm/mach-omap1/pm.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm/mach-omap1/pm.c b/arch/arm/mach-omap1/pm.c
> index 2c1e2b32b9b3..a745d64d4699 100644
> --- a/arch/arm/mach-omap1/pm.c
> +++ b/arch/arm/mach-omap1/pm.c
> @@ -655,9 +655,13 @@ static int __init omap_pm_init(void)
>  		irq = INT_7XX_WAKE_UP_REQ;
>  	else if (cpu_is_omap16xx())
>  		irq = INT_1610_WAKE_UP_REQ;
> -	if (request_irq(irq, omap_wakeup_interrupt, 0, "peripheral wakeup",
> -			NULL))
> -		pr_err("Failed to request irq %d (peripheral wakeup)\n", irq);
> +	else
> +		irq = -1;
> +
> +	if (irq >= 0) {
> +		if (request_irq(irq, omap_wakeup_interrupt, 0, "peripheral wakeup", NULL))
> +			pr_err("Failed to request irq %d (peripheral wakeup)\n", irq);
> +	}
>  
>  	/* Program new power ramp-up time
>  	 * (0 for most boards since we don't lower voltage when in deep sleep)
> -- 
> 2.26.3
> 

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

* Re: [PATCH] ARM: OMAP: Fix use of possibly uninitialized irq variable
  2021-04-01 16:11 [PATCH] ARM: OMAP: Fix use of possibly uninitialized irq variable Maciej Falkowski
  2021-04-01 16:45 ` Nathan Chancellor
@ 2021-04-01 19:05 ` Nick Desaulniers
  1 sibling, 0 replies; 3+ messages in thread
From: Nick Desaulniers @ 2021-04-01 19:05 UTC (permalink / raw)
  To: Maciej Falkowski
  Cc: khilman, aaro.koskinen, tony, Russell King, linux-omap,
	Linux ARM, LKML, clang-built-linux

On Thu, Apr 1, 2021 at 9:12 AM Maciej Falkowski
<maciej.falkowski9@gmail.com> wrote:
>
> The current control flow of IRQ number assignment to `irq` variable
> allows a request of IRQ of unspecified value,
> generating a warning under Clang compilation with omap1_defconfig on linux-next:
>
> arch/arm/mach-omap1/pm.c:656:11: warning: variable 'irq' is used uninitialized whenever
> 'if' condition is false [-Wsometimes-uninitialized]
>         else if (cpu_is_omap16xx())
>                  ^~~~~~~~~~~~~~~~~
> ./arch/arm/mach-omap1/include/mach/soc.h:123:30: note: expanded from macro 'cpu_is_omap16xx'
>                                         ^~~~~~~~~~~~~
> arch/arm/mach-omap1/pm.c:658:18: note: uninitialized use occurs here
>         if (request_irq(irq, omap_wakeup_interrupt, 0, "peripheral wakeup",
>                         ^~~
> arch/arm/mach-omap1/pm.c:656:7: note: remove the 'if' if its condition is always true
>         else if (cpu_is_omap16xx())
>              ^~~~~~~~~~~~~~~~~~~~~~
> arch/arm/mach-omap1/pm.c:611:9: note: initialize the variable 'irq' to silence this warning
>         int irq;
>                ^
>                 = 0
> 1 warning generated.

Ooh, yeah if cpu_is_omap15xx() then irq is unused uninitialized; I
don't see any INT_1610_WAKE_UP_REQ-equlivalent for
INT_15XX_WAKE_UP_REQ.

Ok, LGTM.

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

I agree with Nathan on the Fixes tag.

>
> The patch provides a default value to the `irq` variable
> along with a validity check.
>
> Signed-off-by: Maciej Falkowski <maciej.falkowski9@gmail.com>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1324
> ---
>  arch/arm/mach-omap1/pm.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm/mach-omap1/pm.c b/arch/arm/mach-omap1/pm.c
> index 2c1e2b32b9b3..a745d64d4699 100644
> --- a/arch/arm/mach-omap1/pm.c
> +++ b/arch/arm/mach-omap1/pm.c
> @@ -655,9 +655,13 @@ static int __init omap_pm_init(void)
>                 irq = INT_7XX_WAKE_UP_REQ;
>         else if (cpu_is_omap16xx())
>                 irq = INT_1610_WAKE_UP_REQ;
> -       if (request_irq(irq, omap_wakeup_interrupt, 0, "peripheral wakeup",
> -                       NULL))
> -               pr_err("Failed to request irq %d (peripheral wakeup)\n", irq);
> +       else
> +               irq = -1;
> +
> +       if (irq >= 0) {
> +               if (request_irq(irq, omap_wakeup_interrupt, 0, "peripheral wakeup", NULL))
> +                       pr_err("Failed to request irq %d (peripheral wakeup)\n", irq);
> +       }
>
>         /* Program new power ramp-up time
>          * (0 for most boards since we don't lower voltage when in deep sleep)
> --
-- 
Thanks,
~Nick Desaulniers

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-01 16:11 [PATCH] ARM: OMAP: Fix use of possibly uninitialized irq variable Maciej Falkowski
2021-04-01 16:45 ` Nathan Chancellor
2021-04-01 19:05 ` Nick Desaulniers

Linux-OMAP Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-omap/0 linux-omap/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-omap linux-omap/ https://lore.kernel.org/linux-omap \
		linux-omap@vger.kernel.org
	public-inbox-index linux-omap

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-omap


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git