diff mbox series

wireguard: queueing: Fix implicit type conversion

Message ID 1635469664-1708957-1-git-send-email-jiasheng@iscas.ac.cn (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series wireguard: queueing: Fix implicit type conversion | expand

Checks

Context Check Description
netdev/cover_letter success Single patches do not need cover letters
netdev/fixes_present success Fixes tag not required for -next series
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes fail Problems with Fixes tag: 1
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success No static functions without inline keyword in header files

Commit Message

Jiasheng Jiang Oct. 29, 2021, 1:07 a.m. UTC
The parameter 'cpu' is defined as unsigned int.
However in the cpumask_next() it is implicitly type conversed
to int.
It is universally accepted that the implicit type conversion is
terrible.
Also, having the good programming custom will set an example for
others.
Thus, it might be better to change the type of 'cpu' from
unsigned int to int.

Fixes: e7096c1 ("net: WireGuard secure network tunnel")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/net/wireguard/queueing.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jason A. Donenfeld Oct. 29, 2021, 2:27 p.m. UTC | #1
On Fri, Oct 29, 2021 at 3:08 AM Jiasheng Jiang <jiasheng@iscas.ac.cn> wrote:
> It is universally accepted that the implicit type conversion is
> terrible.

I'm not so sure about this, but either way, I think this needs a bit
more justification and analysis to merge. cpumask_weight returns an
unsigned, for example, and is used as a modulo operand later in the
function. It looks like nr_cpumask_bits is also unsigned. And so on.
So you're really trading one implicit type conversion package for
another. If you're swapping these around, why? It can't be because,
"it is universally accepted that the implicit type conversion is
terrible," since you're adding more of it in a different form. Is your
set of implicit type conversions semantically more proper? If so,
please describe that. Alternatively, is there a way to harmonize
everything into one type? Is there a minimal set of casts that enables
that?

Jason
Eric Dumazet Oct. 29, 2021, 3:30 p.m. UTC | #2
On 10/29/21 7:27 AM, Jason A. Donenfeld wrote:
> On Fri, Oct 29, 2021 at 3:08 AM Jiasheng Jiang <jiasheng@iscas.ac.cn> wrote:
>> It is universally accepted that the implicit type conversion is
>> terrible.
> 
> I'm not so sure about this, but either way, I think this needs a bit
> more justification and analysis to merge. cpumask_weight returns an
> unsigned, for example, and is used as a modulo operand later in the
> function. It looks like nr_cpumask_bits is also unsigned. And so on.
> So you're really trading one implicit type conversion package for
> another. If you're swapping these around, why? It can't be because,
> "it is universally accepted that the implicit type conversion is
> terrible," since you're adding more of it in a different form. Is your
> set of implicit type conversions semantically more proper? If so,
> please describe that. Alternatively, is there a way to harmonize
> everything into one type? Is there a minimal set of casts that enables
> that?
>

I agree with you.

Even standard iterators play/mix with signed/unsigned in plain sight.

extern unsigned int nr_cpu_ids;

unsigned int cpumask_next(int n, const struct cpumask *srcp);

int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap);

#define for_each_cpu(cpu, mask)				\
	for ((cpu) = -1;				\
		(cpu) = cpumask_next((cpu), (mask)),	\
		(cpu) < nr_cpu_ids;)
diff mbox series

Patch

diff --git a/drivers/net/wireguard/queueing.h b/drivers/net/wireguard/queueing.h
index 4ef2944..64f397f 100644
--- a/drivers/net/wireguard/queueing.h
+++ b/drivers/net/wireguard/queueing.h
@@ -106,7 +106,7 @@  static inline void wg_reset_packet(struct sk_buff *skb, bool encapsulating)
 
 static inline int wg_cpumask_choose_online(int *stored_cpu, unsigned int id)
 {
-	unsigned int cpu = *stored_cpu, cpu_index, i;
+	int cpu = *stored_cpu, cpu_index, i;
 
 	if (unlikely(cpu == nr_cpumask_bits ||
 		     !cpumask_test_cpu(cpu, cpu_online_mask))) {