diff mbox series

[v2,3/4] memory: tegra124-emc: Fix compilation warnings on 64bit platforms

Message ID 20210516161214.4693-4-digetx@gmail.com (mailing list archive)
State Superseded, archived
Headers show
Series Enable compile-testing of Tegra memory drivers | expand

Commit Message

Dmitry Osipenko May 16, 2021, 4:12 p.m. UTC
Fix compilation warning on 64bit platforms caused by implicit promotion
of 32bit signed integer to a 64bit unsigned value which happens after
enabling compile-testing of the driver.

Suggested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/memory/tegra/tegra124-emc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Nathan Chancellor May 17, 2021, 6:26 a.m. UTC | #1
On 5/16/2021 9:12 AM, Dmitry Osipenko wrote:
> Fix compilation warning on 64bit platforms caused by implicit promotion
> of 32bit signed integer to a 64bit unsigned value which happens after
> enabling compile-testing of the driver.
> 
> Suggested-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

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

> ---
>   drivers/memory/tegra/tegra124-emc.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/memory/tegra/tegra124-emc.c b/drivers/memory/tegra/tegra124-emc.c
> index 5699d909abc2..c9eb948cf4df 100644
> --- a/drivers/memory/tegra/tegra124-emc.c
> +++ b/drivers/memory/tegra/tegra124-emc.c
> @@ -272,8 +272,8 @@
>   #define EMC_PUTERM_ADJ				0x574
>   
>   #define DRAM_DEV_SEL_ALL			0
> -#define DRAM_DEV_SEL_0				(2 << 30)
> -#define DRAM_DEV_SEL_1				(1 << 30)
> +#define DRAM_DEV_SEL_0				(2u << 30)
> +#define DRAM_DEV_SEL_1				(1u << 30)
>   
>   #define EMC_CFG_POWER_FEATURES_MASK		\
>   	(EMC_CFG_DYN_SREF | EMC_CFG_DRAM_ACPD | EMC_CFG_DRAM_CLKSTOP_SR | \
>
Krzysztof Kozlowski May 17, 2021, 11:28 a.m. UTC | #2
On 16/05/2021 12:12, Dmitry Osipenko wrote:
> Fix compilation warning on 64bit platforms caused by implicit promotion
> of 32bit signed integer to a 64bit unsigned value which happens after
> enabling compile-testing of the driver.
> 
> Suggested-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  drivers/memory/tegra/tegra124-emc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/memory/tegra/tegra124-emc.c b/drivers/memory/tegra/tegra124-emc.c
> index 5699d909abc2..c9eb948cf4df 100644
> --- a/drivers/memory/tegra/tegra124-emc.c
> +++ b/drivers/memory/tegra/tegra124-emc.c
> @@ -272,8 +272,8 @@
>  #define EMC_PUTERM_ADJ				0x574
>  
>  #define DRAM_DEV_SEL_ALL			0
> -#define DRAM_DEV_SEL_0				(2 << 30)
> -#define DRAM_DEV_SEL_1				(1 << 30)
> +#define DRAM_DEV_SEL_0				(2u << 30)
> +#define DRAM_DEV_SEL_1				(1u << 30)

Why not using BIT()? This would make even this 2<<30 less awkard...

Best regards,
Krzysztof
Dmitry Osipenko May 17, 2021, 1:35 p.m. UTC | #3
17.05.2021 14:28, Krzysztof Kozlowski пишет:
> On 16/05/2021 12:12, Dmitry Osipenko wrote:
>> Fix compilation warning on 64bit platforms caused by implicit promotion
>> of 32bit signed integer to a 64bit unsigned value which happens after
>> enabling compile-testing of the driver.
>>
>> Suggested-by: Nathan Chancellor <nathan@kernel.org>
>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>> ---
>>  drivers/memory/tegra/tegra124-emc.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/memory/tegra/tegra124-emc.c b/drivers/memory/tegra/tegra124-emc.c
>> index 5699d909abc2..c9eb948cf4df 100644
>> --- a/drivers/memory/tegra/tegra124-emc.c
>> +++ b/drivers/memory/tegra/tegra124-emc.c
>> @@ -272,8 +272,8 @@
>>  #define EMC_PUTERM_ADJ				0x574
>>  
>>  #define DRAM_DEV_SEL_ALL			0
>> -#define DRAM_DEV_SEL_0				(2 << 30)
>> -#define DRAM_DEV_SEL_1				(1 << 30)
>> +#define DRAM_DEV_SEL_0				(2u << 30)
>> +#define DRAM_DEV_SEL_1				(1u << 30)
> 
> Why not using BIT()? This would make even this 2<<30 less awkard...

The bitfield 31:30 is a enum, 3 is a wrong value. Formally it's
incorrect to use the BIT() macro here.
Krzysztof Kozlowski May 17, 2021, 1:39 p.m. UTC | #4
On 17/05/2021 09:35, Dmitry Osipenko wrote:
> 17.05.2021 14:28, Krzysztof Kozlowski пишет:
>> On 16/05/2021 12:12, Dmitry Osipenko wrote:
>>> Fix compilation warning on 64bit platforms caused by implicit promotion
>>> of 32bit signed integer to a 64bit unsigned value which happens after
>>> enabling compile-testing of the driver.
>>>
>>> Suggested-by: Nathan Chancellor <nathan@kernel.org>
>>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>>> ---
>>>  drivers/memory/tegra/tegra124-emc.c | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/memory/tegra/tegra124-emc.c b/drivers/memory/tegra/tegra124-emc.c
>>> index 5699d909abc2..c9eb948cf4df 100644
>>> --- a/drivers/memory/tegra/tegra124-emc.c
>>> +++ b/drivers/memory/tegra/tegra124-emc.c
>>> @@ -272,8 +272,8 @@
>>>  #define EMC_PUTERM_ADJ				0x574
>>>  
>>>  #define DRAM_DEV_SEL_ALL			0
>>> -#define DRAM_DEV_SEL_0				(2 << 30)
>>> -#define DRAM_DEV_SEL_1				(1 << 30)
>>> +#define DRAM_DEV_SEL_0				(2u << 30)
>>> +#define DRAM_DEV_SEL_1				(1u << 30)
>>
>> Why not using BIT()? This would make even this 2<<30 less awkard...
> 
> The bitfield 31:30 is a enum, 3 is a wrong value. Formally it's
> incorrect to use the BIT() macro here.

Why "3"? BIT(31) is the same as 2<<30. It's common to use BIT for
register fields which do not accept all possible values. Now you
basically reimplement BIT() which is error-prone.


Best regards,
Krzysztof
Dmitry Osipenko May 17, 2021, 1:47 p.m. UTC | #5
17.05.2021 16:39, Krzysztof Kozlowski пишет:
> On 17/05/2021 09:35, Dmitry Osipenko wrote:
>> 17.05.2021 14:28, Krzysztof Kozlowski пишет:
>>> On 16/05/2021 12:12, Dmitry Osipenko wrote:
>>>> Fix compilation warning on 64bit platforms caused by implicit promotion
>>>> of 32bit signed integer to a 64bit unsigned value which happens after
>>>> enabling compile-testing of the driver.
>>>>
>>>> Suggested-by: Nathan Chancellor <nathan@kernel.org>
>>>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>>>> ---
>>>>  drivers/memory/tegra/tegra124-emc.c | 4 ++--
>>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/drivers/memory/tegra/tegra124-emc.c b/drivers/memory/tegra/tegra124-emc.c
>>>> index 5699d909abc2..c9eb948cf4df 100644
>>>> --- a/drivers/memory/tegra/tegra124-emc.c
>>>> +++ b/drivers/memory/tegra/tegra124-emc.c
>>>> @@ -272,8 +272,8 @@
>>>>  #define EMC_PUTERM_ADJ				0x574
>>>>  
>>>>  #define DRAM_DEV_SEL_ALL			0
>>>> -#define DRAM_DEV_SEL_0				(2 << 30)
>>>> -#define DRAM_DEV_SEL_1				(1 << 30)
>>>> +#define DRAM_DEV_SEL_0				(2u << 30)
>>>> +#define DRAM_DEV_SEL_1				(1u << 30)
>>>
>>> Why not using BIT()? This would make even this 2<<30 less awkard...
>>
>> The bitfield 31:30 is a enum, 3 is a wrong value. Formally it's
>> incorrect to use the BIT() macro here.
> 
> Why "3"? BIT(31) is the same as 2<<30.

By 3 I meant BIT(31)|BIT(30). This bitfield is explicitly designated as
a enum in the hardware documentation.

> It's common to use BIT for
> register fields which do not accept all possible values. Now you
> basically reimplement BIT() which is error-prone.

Could you please show couple examples? The common practice today is to
use FIELD_PREP helpers, but this driver was written before these helpers
existed.
Krzysztof Kozlowski May 17, 2021, 2:04 p.m. UTC | #6
On 17/05/2021 09:47, Dmitry Osipenko wrote:
> 17.05.2021 16:39, Krzysztof Kozlowski пишет:
>>>>>  #define DRAM_DEV_SEL_ALL			0
>>>>> -#define DRAM_DEV_SEL_0				(2 << 30)
>>>>> -#define DRAM_DEV_SEL_1				(1 << 30)
>>>>> +#define DRAM_DEV_SEL_0				(2u << 30)
>>>>> +#define DRAM_DEV_SEL_1				(1u << 30)
>>>>
>>>> Why not using BIT()? This would make even this 2<<30 less awkard...
>>>
>>> The bitfield 31:30 is a enum, 3 is a wrong value. Formally it's
>>> incorrect to use the BIT() macro here.
>>
>> Why "3"? BIT(31) is the same as 2<<30.
> 
> By 3 I meant BIT(31)|BIT(30). This bitfield is explicitly designated as
> a enum in the hardware documentation.

I understand it and using BIT() here does not mean someone has to set
both of them. BIT() is a helper pointing out that you want to toggle one
bit. It does not mean that it is allowed to do so always!

> 
>> It's common to use BIT for
>> register fields which do not accept all possible values. Now you
>> basically reimplement BIT() which is error-prone.
> 
> Could you please show couple examples? The common practice today is to
> use FIELD_PREP helpers, but this driver was written before these helpers
> existed.


There are plenty of such examples so I guess it would be easier to ask
you to provide counter ones. Few IT for enum-like registers found within 2 minutes:

https://elixir.bootlin.com/linux/latest/C/ident/MAX77620_CNFG_GPIO_INT_MASK
https://elixir.bootlin.com/linux/v5.13-rc2/source/drivers/regulator/max77650-regulator.c#L18
https://elixir.bootlin.com/linux/v5.13-rc2/source/drivers/regulator/tps6524x-regulator.c#L62
https://elixir.bootlin.com/linux/v5.13-rc2/source/drivers/regulator/tps80031-regulator.c#L39
https://elixir.bootlin.com/linux/v5.13-rc2/source/drivers/regulator/da9121-regulator.h#L200
https://elixir.bootlin.com/linux/v5.13-rc2/source/drivers/regulator/da9121-regulator.h#L231

Best regards,
Krzysztof
Dmitry Osipenko May 17, 2021, 2:23 p.m. UTC | #7
17.05.2021 17:04, Krzysztof Kozlowski пишет:
> On 17/05/2021 09:47, Dmitry Osipenko wrote:
>> 17.05.2021 16:39, Krzysztof Kozlowski пишет:
>>>>>>  #define DRAM_DEV_SEL_ALL			0
>>>>>> -#define DRAM_DEV_SEL_0				(2 << 30)
>>>>>> -#define DRAM_DEV_SEL_1				(1 << 30)
>>>>>> +#define DRAM_DEV_SEL_0				(2u << 30)
>>>>>> +#define DRAM_DEV_SEL_1				(1u << 30)
>>>>>
>>>>> Why not using BIT()? This would make even this 2<<30 less awkard...
>>>>
>>>> The bitfield 31:30 is a enum, 3 is a wrong value. Formally it's
>>>> incorrect to use the BIT() macro here.
>>>
>>> Why "3"? BIT(31) is the same as 2<<30.
>>
>> By 3 I meant BIT(31)|BIT(30). This bitfield is explicitly designated as
>> a enum in the hardware documentation.
> 
> I understand it and using BIT() here does not mean someone has to set
> both of them. BIT() is a helper pointing out that you want to toggle one
> bit. It does not mean that it is allowed to do so always!
> 
>>
>>> It's common to use BIT for
>>> register fields which do not accept all possible values. Now you
>>> basically reimplement BIT() which is error-prone.
>>
>> Could you please show couple examples? The common practice today is to
>> use FIELD_PREP helpers, but this driver was written before these helpers
>> existed.
> 
> 
> There are plenty of such examples so I guess it would be easier to ask
> you to provide counter ones. Few IT for enum-like registers found within 2 minutes:
> 
> https://elixir.bootlin.com/linux/latest/C/ident/MAX77620_CNFG_GPIO_INT_MASK
> https://elixir.bootlin.com/linux/v5.13-rc2/source/drivers/regulator/max77650-regulator.c#L18
> https://elixir.bootlin.com/linux/v5.13-rc2/source/drivers/regulator/tps6524x-regulator.c#L62
> https://elixir.bootlin.com/linux/v5.13-rc2/source/drivers/regulator/tps80031-regulator.c#L39
> https://elixir.bootlin.com/linux/v5.13-rc2/source/drivers/regulator/da9121-regulator.h#L200
> https://elixir.bootlin.com/linux/v5.13-rc2/source/drivers/regulator/da9121-regulator.h#L231

Alright, I'll use the BIT macro in the v3.

I also realized now that the tegra30-emc drivers needs the same change.

Thank you for the review.
Krzysztof Kozlowski May 17, 2021, 2:24 p.m. UTC | #8
On 16/05/2021 12:12, Dmitry Osipenko wrote:
> Fix compilation warning on 64bit platforms caused by implicit promotion
> of 32bit signed integer to a 64bit unsigned value which happens after
> enabling compile-testing of the driver.
> 
> Suggested-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
The patch was not suggested by Nathan but it was:
Reported-by: kernel test robot <lkp@intel.com>

Nathan however provided analysis and proper solution, so co-developed or
his SoB fits better. This is not that important as comment above -
including robot's credits.

Best regards,
Krzysztof
Dmitry Osipenko May 17, 2021, 2:53 p.m. UTC | #9
17.05.2021 17:24, Krzysztof Kozlowski пишет:
> On 16/05/2021 12:12, Dmitry Osipenko wrote:
>> Fix compilation warning on 64bit platforms caused by implicit promotion
>> of 32bit signed integer to a 64bit unsigned value which happens after
>> enabling compile-testing of the driver.
>>
>> Suggested-by: Nathan Chancellor <nathan@kernel.org>
>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> The patch was not suggested by Nathan but it was:
> Reported-by: kernel test robot <lkp@intel.com>
> 
> Nathan however provided analysis and proper solution, so co-developed or
> his SoB fits better. This is not that important as comment above -
> including robot's credits.

I'll update the tags in v3, thank you.
diff mbox series

Patch

diff --git a/drivers/memory/tegra/tegra124-emc.c b/drivers/memory/tegra/tegra124-emc.c
index 5699d909abc2..c9eb948cf4df 100644
--- a/drivers/memory/tegra/tegra124-emc.c
+++ b/drivers/memory/tegra/tegra124-emc.c
@@ -272,8 +272,8 @@ 
 #define EMC_PUTERM_ADJ				0x574
 
 #define DRAM_DEV_SEL_ALL			0
-#define DRAM_DEV_SEL_0				(2 << 30)
-#define DRAM_DEV_SEL_1				(1 << 30)
+#define DRAM_DEV_SEL_0				(2u << 30)
+#define DRAM_DEV_SEL_1				(1u << 30)
 
 #define EMC_CFG_POWER_FEATURES_MASK		\
 	(EMC_CFG_DYN_SREF | EMC_CFG_DRAM_ACPD | EMC_CFG_DRAM_CLKSTOP_SR | \