net: ipa: always inline ipa_aggr_granularity_val()
Subsystems (3)
PATCH 1/1 net: ipa: always inline ipa_aggr_granularity_val()
It isn't required, but all callers of ipa_aggr_granularity_val() pass a constant value (IPA_AGGR_GRANULARITY) as the usec argument. Two of those callers are in ipa_validate_build(), with the result being passed to BUILD_BUG_ON().
Evidently the "sparc64-linux-gcc" compiler (at least) doesn't always inline ipa_aggr_granularity_val(), so the result of the function is not constant at compile time, and that leads to build errors.
Define the function with the __always_inline attribute to avoid the errors. And given that the function is inline, we can switch the WARN_ON() there to be BUILD_BUG_ON().
---
David/Jakub, this fixes a bug in a commit in net-next/master. -Alex
drivers/net/ipa/ipa_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ipa/ipa_main.c +2 -2
@@ -255,9 +255,9 @@ ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data)* less than the number of timer ticks in the requested period. 0 is not * a valid granularity value. */ -static u32 ipa_aggr_granularity_val (u32 usec) +static __always_inline u32 ipa_aggr_granularity_val(u32 usec) { -WARN_ON (!usec); +BUILD_BUG_ON (!usec);return DIV_ROUND_CLOSEST (usec *TIMER_FREQUENCY ,USEC_PER_SEC ) -1 ; }
Signature · 1 line
2.27.0
Quoted 28 lines · Alex Elder
It isn't required, but all callers of
ipa_aggr_granularity_val()pass a constant value (IPA_AGGR_GRANULARITY) as the usec argument. Two of those callers are inipa_validate_build(), with the result being passed toBUILD_BUG_ON().Evidently the "sparc64-linux-gcc" compiler (at least) doesn't always inline
ipa_aggr_granularity_val(), so the result of the function is not constant at compile time, and that leads to build errors.Define the function with the
__always_inlineattribute to avoid the errors. And given that the function is inline, we can switch theWARN_ON()there to beBUILD_BUG_ON().Fixes 5bc5588466a1f ("net: ipa: use WARN_ON() rather than assertions")Reported-by kernel test robot <[email protected]>Signed-off-by Alex Elder <[email protected]>---
David/Jakub, this fixes a bug in a commit in net-next/master. -Alex
drivers/net/ipa/ipa_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ipa/ipa_main.c +0
-0
drivers/net/ipa/ipa_main.c ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data) · line 260
Quoted 8 lines
drivers/net/ipa/ipa_main.c +2
-2@@ -255,9 +255,9 @@ ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data)* less than the number of timer ticks in the requested period. 0 is not * a valid granularity value. */ -static u32 ipa_aggr_granularity_val (u32 usec) +static __always_inline u32 ipa_aggr_granularity_val(u32 usec) { -WARN_ON (!usec); +BUILD_BUG_ON (!usec);
So what exactly are you checking here if all callers pass same value? It is in-kernel API, declared as static inside one module. There is no need to protect from itself.
Thanks
Quoted 6 lines
drivers/net/ipa/ipa_main.c +0
-0return DIV_ROUND_CLOSEST (usec *TIMER_FREQUENCY ,USEC_PER_SEC ) -1 ; }Signature · 1 line
2.27.0
Quoted 33 lines · Leon Romanovsky
Quoted 32 lines · Alex Elder
It isn't required, but all callers of
ipa_aggr_granularity_val()pass a constant value (IPA_AGGR_GRANULARITY) as the usec argument. Two of those callers are inipa_validate_build(), with the result being passed toBUILD_BUG_ON().Evidently the "sparc64-linux-gcc" compiler (at least) doesn't always inline
ipa_aggr_granularity_val(), so the result of the function is not constant at compile time, and that leads to build errors.Define the function with the
__always_inlineattribute to avoid the errors. And given that the function is inline, we can switch theWARN_ON()there to beBUILD_BUG_ON().Fixes 5bc5588466a1f ("net: ipa: use WARN_ON() rather than assertions")Reported-by kernel test robot <[email protected]>Signed-off-by Alex Elder <[email protected]>---
David/Jakub, this fixes a bug in a commit in net-next/master. -Alex
drivers/net/ipa/ipa_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ipa/ipa_main.c +0
-1@@ -255,9 +255,9 @@ ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data)* less than the number of timer ticks in the requested period. 0 is not * a valid granularity value. */ -static u32 ipa_aggr_granularity_val (u32 usec)
Quoted 8 lines
drivers/net/ipa/ipa_main.c ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data) · line 260
Quoted 4 lines
drivers/net/ipa/ipa_main.c +2
-1+static __always_inline u32 ipa_aggr_granularity_val(u32 usec) { -WARN_ON (!usec); +BUILD_BUG_ON (!usec);So what exactly are you checking here if all callers pass same value? It is in-kernel API, declared as static inside one module. There is no need to protect from itself.
Yeah that's a good point. It can just as well be removed. I think the check was added before I knew it was only going to be used with a single constant value. That said, the point was to check at runtime a required constraint.
I'll post version 2 that simply removes it. Thanks.
-Alex
Quoted 9 lines
Thanks
Quoted 6 lines
drivers/net/ipa/ipa_main.c +0
-0return DIV_ROUND_CLOSEST (usec *TIMER_FREQUENCY ,USEC_PER_SEC ) -1 ; }Signature · 1 line
2.27.0
Quoted 43 lines · Alex Elder
Quoted 33 lines · Leon Romanovsky
Quoted 32 lines · Alex Elder
It isn't required, but all callers of
ipa_aggr_granularity_val()pass a constant value (IPA_AGGR_GRANULARITY) as the usec argument. Two of those callers are inipa_validate_build(), with the result being passed toBUILD_BUG_ON().Evidently the "sparc64-linux-gcc" compiler (at least) doesn't always inline
ipa_aggr_granularity_val(), so the result of the function is not constant at compile time, and that leads to build errors.Define the function with the
__always_inlineattribute to avoid the errors. And given that the function is inline, we can switch theWARN_ON()there to beBUILD_BUG_ON().Fixes 5bc5588466a1f ("net: ipa: use WARN_ON() rather than assertions")Reported-by kernel test robot <[email protected]>Signed-off-by Alex Elder <[email protected]>---
David/Jakub, this fixes a bug in a commit in net-next/master. -Alex
drivers/net/ipa/ipa_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ipa/ipa_main.c +0
-1@@ -255,9 +255,9 @@ ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data)* less than the number of timer ticks in the requested period. 0 is not * a valid granularity value. */ -static u32 ipa_aggr_granularity_val (u32 usec)Quoted 8 lines
drivers/net/ipa/ipa_main.c ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data) · line 260
Quoted 4 lines
drivers/net/ipa/ipa_main.c +2
-1+static __always_inline u32 ipa_aggr_granularity_val(u32 usec) { -WARN_ON (!usec); +BUILD_BUG_ON (!usec);So what exactly are you checking here if all callers pass same value? It is in-kernel API, declared as static inside one module. There is no need to protect from itself.
Quoted 6 lines
Yeah that's a good point. It can just as well be removed. I think the check was added before I knew it was only going to be used with a single constant value. That said, the point was to check at runtime a required constraint.
I'll post version 2 that simply removes it. Thanks.
Thanks
Quoted 13 lines
-Alex
Quoted 9 lines
Thanks
Quoted 6 lines
drivers/net/ipa/ipa_main.c +0
-0return DIV_ROUND_CLOSEST (usec *TIMER_FREQUENCY ,USEC_PER_SEC ) -1 ; }Signature · 1 line
2.27.0