diff mbox

[3/3] rtc: stm32: use 32-bit cast for BIT() macro

Message ID 20170113153311.2611510-3-arnd@arndb.de (mailing list archive)
State New, archived
Headers show

Commit Message

Arnd Bergmann Jan. 13, 2017, 3:32 p.m. UTC
Using the ~ operator on a BIT() constant results in a large 'unsigned long'
constant that won't fit into an 'unsigned int' function argument on 64-bit
architectures, resulting in a harmless build warning in x86 allmodconfig:

drivers/rtc/rtc-stm32.c: In function 'stm32_rtc_probe':
drivers/rtc/rtc-stm32.c:651:51: error: large integer implicitly truncated to unsigned type [-Werror=overflow]
  regmap_update_bits(rtc->dbp, PWR_CR, PWR_CR_DBP, ~PWR_CR_DBP);

This works around the warning by adding an explict cast to 'u32', but
that is unfortunately a bit ugly and I feel there should be a better
way to do this, possibly with some changes to either the bitops.h
header or the regmap API.

Cc: Mark Brown <broonie@kernel.org>
Fixes: 4e64350f42e2 ("rtc: add STM32 RTC driver")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/rtc/rtc-stm32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Russell King (Oracle) Jan. 13, 2017, 3:52 p.m. UTC | #1
On Fri, Jan 13, 2017 at 04:32:53PM +0100, Arnd Bergmann wrote:
> -#define PWR_CR_DBP			BIT(8)
> +#define PWR_CR_DBP			(u32)BIT(8)

Shouldn't that have parens around it as it's no longer a simple expression.
Alexandre Belloni Jan. 13, 2017, 3:55 p.m. UTC | #2
On 13/01/2017 at 15:52:29 +0000, Russell King - ARM Linux wrote :
> On Fri, Jan 13, 2017 at 04:32:53PM +0100, Arnd Bergmann wrote:
> > -#define PWR_CR_DBP			BIT(8)
> > +#define PWR_CR_DBP			(u32)BIT(8)
> 
> Shouldn't that have parens around it as it's no longer a simple expression.
> 

Yes, at least checkpatch complains about it.
Amelie Delaunay Jan. 13, 2017, 3:56 p.m. UTC | #3
Hi Arnd,

On 01/13/2017 04:32 PM, Arnd Bergmann wrote:
> Using the ~ operator on a BIT() constant results in a large 'unsigned long'
> constant that won't fit into an 'unsigned int' function argument on 64-bit
> architectures, resulting in a harmless build warning in x86 allmodconfig:
>
> drivers/rtc/rtc-stm32.c: In function 'stm32_rtc_probe':
> drivers/rtc/rtc-stm32.c:651:51: error: large integer implicitly truncated to unsigned type [-Werror=overflow]
>   regmap_update_bits(rtc->dbp, PWR_CR, PWR_CR_DBP, ~PWR_CR_DBP);
I thought I would fix this warning by replacing all ~PWR_CR_DBP by 0, 
because the mask PWR_CR_DBP prevents other bits to be cleared.
In this way, I avoid the ugly cast...
>
> This works around the warning by adding an explict cast to 'u32', but
> that is unfortunately a bit ugly and I feel there should be a better
> way to do this, possibly with some changes to either the bitops.h
> header or the regmap API.
>
> Cc: Mark Brown <broonie@kernel.org>
> Fixes: 4e64350f42e2 ("rtc: add STM32 RTC driver")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/rtc/rtc-stm32.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/rtc/rtc-stm32.c b/drivers/rtc/rtc-stm32.c
> index 8c599f52124c..05d3dc89e55f 100644
> --- a/drivers/rtc/rtc-stm32.c
> +++ b/drivers/rtc/rtc-stm32.c
> @@ -92,7 +92,7 @@
>  /* STM32_PWR_CR */
>  #define PWR_CR				0x00
>  /* STM32_PWR_CR bit field */
> -#define PWR_CR_DBP			BIT(8)
> +#define PWR_CR_DBP			(u32)BIT(8)
>
>  struct stm32_rtc {
>  	struct rtc_device *rtc_dev;
>

Regards,
Amelie
Arnd Bergmann Jan. 13, 2017, 4:48 p.m. UTC | #4
On Fri, Jan 13, 2017 at 4:56 PM, Amelie DELAUNAY <amelie.delaunay@st.com> wrote:
> On 01/13/2017 04:32 PM, Arnd Bergmann wrote:
>>
>> Using the ~ operator on a BIT() constant results in a large 'unsigned
>> long'
>> constant that won't fit into an 'unsigned int' function argument on 64-bit
>> architectures, resulting in a harmless build warning in x86 allmodconfig:
>>
>> drivers/rtc/rtc-stm32.c: In function 'stm32_rtc_probe':
>> drivers/rtc/rtc-stm32.c:651:51: error: large integer implicitly truncated
>> to unsigned type [-Werror=overflow]
>>   regmap_update_bits(rtc->dbp, PWR_CR, PWR_CR_DBP, ~PWR_CR_DBP);
>
> I thought I would fix this warning by replacing all ~PWR_CR_DBP by 0,
> because the mask PWR_CR_DBP prevents other bits to be cleared.
> In this way, I avoid the ugly cast...

Good idea, much nicer than mine! Can you send that patch?

    Arnd
diff mbox

Patch

diff --git a/drivers/rtc/rtc-stm32.c b/drivers/rtc/rtc-stm32.c
index 8c599f52124c..05d3dc89e55f 100644
--- a/drivers/rtc/rtc-stm32.c
+++ b/drivers/rtc/rtc-stm32.c
@@ -92,7 +92,7 @@ 
 /* STM32_PWR_CR */
 #define PWR_CR				0x00
 /* STM32_PWR_CR bit field */
-#define PWR_CR_DBP			BIT(8)
+#define PWR_CR_DBP			(u32)BIT(8)
 
 struct stm32_rtc {
 	struct rtc_device *rtc_dev;