gpio: aspeed: fix compile testing warning
Subsystems (2)
PATCH 1/1 gpio: aspeed: fix compile testing warning
Gcc cannot always see that BUG_ON(1) is guaranteed to not return, so we get a warning message in some configurations:
drivers/gpio/gpio-aspeed.c: In function 'bank_reg':drivers/gpio/gpio-aspeed.c:244:1: error: control reaches end of non-void function [-Werror=return-type]
Using a plain BUG() is easier here and avoids the problem.
--- drivers/gpio/gpio-aspeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-aspeed.c +1 -1
@@ -240,7 +240,7 @@ static inline void __iomem *bank_reg(struct aspeed_gpio *gpio,case reg_cmdsrc1:return gpio->base + bank->cmdsrc_regs +GPIO_CMDSRC_1 ; } -BUG_ON (1 ); +BUG (); }#define GPIO_BANK (x) ((x) >> 5)
Signature · 1 line
2.9.0
Quoted 20 lines · CEST Arnd Bergmann
Gcc cannot always see that
BUG_ON(1)is guaranteed to not return, so we get a warning message in some configurations:
drivers/gpio/gpio-aspeed.c: In function 'bank_reg':drivers/gpio/gpio-aspeed.c:244:1: error: control reaches end of non-void function [-Werror=return-type]Using a plain
BUG()is easier here and avoids the problem.Fixes 44ddf559d579 ("gpio: aspeed: Rework register type accessors")Signed-off-by Arnd Bergmann <[email protected]>--- drivers/gpio/gpio-aspeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpio/gpio-aspeed.c +0
-0
drivers/gpio/gpio-aspeed.c static inline void __iomem *bank_reg(struct aspeed_gpio · line 246
Quoted 8 lines
drivers/gpio/gpio-aspeed.c +1
-1@@ -240,7 +240,7 @@ static inline void __iomem *bank_reg(struct aspeed_gpio *gpio, case reg_cmdsrc1:return gpio->base + bank->cmdsrc_regs +GPIO_CMDSRC_1 ; } -BUG_ON (1 ); +BUG (); }#define GPIO_BANK (x) ((x) >> 5)
Is the semantic of BUG() (and BUG_ON as well) to never return? If so, then just an idea: Is it possible to add some macro magic in BUG_ON(x) to fail compiling if x is compile-constant? Giving a hint the passed condition always fails, which indicates a problem, at least to me.
Quoted 5 lines
From a short search I found this in
drivers/gpu/vga/vgaarb.cL630-633:if (vgadev_find(pdev) != NULL) { BUG_ON(1); goto fail; }
You can't fail with a BUG_ON(1) and try to do some error handling after that.
Best regards,
Alexander
Quoted 28 lines · Alexander Stein
Quoted 27 lines · CEST Arnd Bergmann
Gcc cannot always see that
BUG_ON(1)is guaranteed to not return, so we get a warning message in some configurations:
drivers/gpio/gpio-aspeed.c: In function 'bank_reg':drivers/gpio/gpio-aspeed.c:244:1: error: control reaches end of non-void function [-Werror=return-type]Using a plain
BUG()is easier here and avoids the problem.Fixes 44ddf559d579 ("gpio: aspeed: Rework register type accessors")Signed-off-by Arnd Bergmann <[email protected]>--- drivers/gpio/gpio-aspeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpio/gpio-aspeed.c +1
-1@@ -240,7 +240,7 @@ static inline void __iomem *bank_reg(struct aspeed_gpio *gpio, case reg_cmdsrc1:return gpio->base + bank->cmdsrc_regs +GPIO_CMDSRC_1 ; } -BUG_ON (1 ); +BUG (); }
Quoted 3 lines
drivers/gpio/gpio-aspeed.c static inline void __iomem *bank_reg(struct aspeed_gpio *gpio, · line 246
Quoted 1 line
drivers/gpio/gpio-aspeed.c +0
-0#define GPIO_BANK (x) ((x) >> 5)Is the semantic of
BUG()(andBUG_ONas well) to never return?
On most architectures and configurations yes, but not on some of the minor architectures if CONFIG_BUG is disabled.
Quoted 4 lines
If so, then
just an idea: Is it possible to add some macro magic inBUG_ON(x)to fail compiling if x is compile-constant? Giving a hint the passed condition always fails, which indicates a problem, at least to me.
Not sure, that might not work well in cases where it's a compile-time constant in some configurations but variable in others.
Quoted 6 lines
From a short search I found this in
drivers/gpu/vga/vgaarb.cL630-633:Quoted 4 lines
if (vgadev_find(pdev) != NULL) { BUG_ON(1); goto fail; }You can't fail with a
BUG_ON(1)and try to do some error handling after that.
Right.
Traditionally when CONFIG_BUG was disabled, we would have continued here, so that could have been intentional, but in any case a WARN_ON() would have been more appropriate here.
Arnd
Quoted 10 lines · Arnd Bergmann
Gcc cannot always see that
BUG_ON(1)is guaranteed to not return, so we get a warning message in some configurations:
drivers/gpio/gpio-aspeed.c: In function 'bank_reg':drivers/gpio/gpio-aspeed.c:244:1: error: control reaches end of non-void function [-Werror=return-type]Using a plain
BUG()is easier here and avoids the problem.Fixes 44ddf559d579 ("gpio: aspeed: Rework register type accessors")Signed-off-by Arnd Bergmann <[email protected]>
Linus, can you plonk that on top of the patches in that topic branch you created ?
Quoted 17 lines
--- drivers/gpio/gpio-aspeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpio/gpio-aspeed.c +1
-1@@ -240,7 +240,7 @@ static inline void __iomem *bank_reg(struct aspeed_gpio *gpio,case reg_cmdsrc1:return gpio->base + bank->cmdsrc_regs +GPIO_CMDSRC_1 ; } -BUG_ON (1 ); +BUG (); }#define GPIO_BANK (x) ((x) >> 5)
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Arnd Bergmann
Gcc cannot always see that
BUG_ON(1)is guaranteed to not return, so we get a warning message in some configurations:
drivers/gpio/gpio-aspeed.c: In function 'bank_reg':drivers/gpio/gpio-aspeed.c:244:1: error: control reaches end of non-void function [-Werror=return-type]Using a plain
BUG()is easier here and avoids the problem.
Quoted 7 lines
Quoted 2 lines
Fixes 44ddf559d579 ("gpio: aspeed: Rework register type accessors")Signed-off-by Arnd Bergmann <[email protected]>Linus, can you plonk that on top of the patches in that topic branch you created ?
I put it on top of my devel branch where I merged in the topic branch.
As it's a fringe thing anyways I don't think we need to recreate the topic branch for this.
Yours,
Linus Walleij
Quoted 10 lines · Arnd Bergmann
Gcc cannot always see that
BUG_ON(1)is guaranteed to not return, so we get a warning message in some configurations:
drivers/gpio/gpio-aspeed.c: In function 'bank_reg':drivers/gpio/gpio-aspeed.c:244:1: error: control reaches end of non-void function [-Werror=return-type]Using a plain
BUG()is easier here and avoids the problem.Fixes 44ddf559d579 ("gpio: aspeed: Rework register type accessors")Signed-off-by Arnd Bergmann <[email protected]>
Patch applied with Benjamin's ACK.
Yours,
Linus Walleij