Skip to contentSkip to conversation

net:tipc:Remove repeated initialization

PATCH In review Wang Ming 5 participants 10 messages Jul 6, 2023 – Jul 7, 2023

Subsystems (3)
lore
Share & tools
lore

Wang Ming

author
#0 lore raw

PATCH 1/1 net:tipc:Remove repeated initialization

The original code initializes 'tmp' twice, which causes duplicate initialization issue. To fix this, we remove the second initialization of 'tmp' and use 'parent' directly forsubsequent operations.

---
 net/tipc/group.c | 2 --
 1 file changed, 2 deletions(-)
net/tipc/group.c +0 -2
index 3e137d8c9d2f..b2f964f62c36 100644
@@ -284,8 +284,6 @@ static int tipc_group_add_to_tree(struct tipc_group *grp,
 	n = &grp->members.rb_node;
 	while (*n) {
 		tmp = container_of(*n, struct tipc_member, tree_node);
-		parent = *n;
-		tmp = container_of(parent, struct tipc_member, tree_node);
 		nkey = (u64)tmp->node << 32 | tmp->port;
 		if (key < nkey)
 			n = &(*n)->rb_left;
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 7 lines · On Thu, 6 Jul 2023 21:42:09 +0800 Wang Ming wrote:

The original code initializes 'tmp' twice, which causes duplicate initialization issue. To fix this, we remove the second initialization of 'tmp' and use 'parent' directly forsubsequent operations.

Please stop sending the "remove repeated initialization" patches to networking, thanks.

#2 lore raw

Le 06/07/2023 à 17:47, Jakub Kicinski a écrit :

Quoted 7 lines · On Thu, 6 Jul 2023 21:42:09 +0800 Wang Ming wrote:
Quoted 6 lines

The original code initializes 'tmp' twice, which causes duplicate initialization issue. To fix this, we remove the second initialization of 'tmp' and use 'parent' directly forsubsequent operations.

Quoted 6 lines
Quoted 1 line

Please stop sending the "remove repeated initialization" patches to networking, thanks.

The patch also looks just bogus, as 'parent' is now always NULL when:
rb_link_node(&m->tree_node, parent, n);

is called after the while loop.

CJ

#3 lore raw

Hi CJ
: )
So what you're saying is there's no repeat initialization problem here.

-----邮件原件-----
发件人: Christophe JAILLET <[email protected]>
发送时间: 2023年7月7日 1:14
收件人: 王明-软件底层技术部 <[email protected]>
抄送: Jon Maloy <[email protected]>; Ying Xue <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; [email protected]; opensource.kernel <[email protected]>; Jakub Kicinski <[email protected]> 主题: Re: [PATCH v1] net:tipc:Remove repeated initialization

[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]

Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Thu, 6 Jul 2023 21:42:09 +0800 Wang Ming wrote:

The original code initializes 'tmp' twice, which causes duplicate initialization issue.
To fix this, we remove the second initialization of 'tmp' and use 'parent' directly forsubsequent operations.

Quoted 6 lines
Quoted 1 line

Please stop sending the "remove repeated initialization" patches to networking, thanks.

The patch also looks just bogus, as 'parent' is now always NULL when:

    rb_link_node(&m->tree_node, parent, n);

is called after the while loop.

CJ

#4 lore raw

Le 07/07/2023 à 03:24, 王明-软件底层技术部 a écrit :

Quoted 3 lines

Hi CJ
: )
So what you're saying is there's no repeat initialization problem here.

Hi,

First, top posting is usually not the better way to answer email.

Anyway, in your patch, you have:
n = &grp->members.rb_node;
while (*n) {
tmp = container_of(*n, struct tipc_member, tree_node);
- parent = *n;
- tmp = container_of(parent, struct tipc_member, tree_node);
nkey = (u64)tmp->node << 32 | tmp->port;
if (key < nkey)
n = &(*n)->rb_left;

You are right, 'tmp' is initialized twice. It is even initialized twice, with the same walue.

But in your patch, you also remove "parent = *n;"
So now, 'parent' is never updated in the function, and when rb_link_node() is called after the while loop, it is NULL.

So your patch changed the behaviour of the code and looks broken.

Something like:
while (*n) {

 		tmp = container_of(*n, struct tipc_member, tree_node);
		parent = *n;

- tmp = container_of(parent, struct tipc_member, tree_node);
nkey = (u64)tmp->node << 32 | tmp->port; if (key < nkey)
n = &(*n)->rb_left;

would look good to me but, as said by Jakub in the thread, is really unlikely to be applied.

The risk of breaking code (as you un-intentionally did) is higher than the value of removing a redundant initialization.

Reviewing such patches also consume maintainers' time to check for such potential errors and sometimes it is safer to leave things as-is in order not to waste time and avoid potential troubles.

CJ

Quoted 30 lines

-----邮件原件-----
发件人: Christophe JAILLET <[email protected]>
发送时间: 2023年7月7日 1:14
收件人: 王明-软件底层技术部 <[email protected]>
抄送: Jon Maloy <[email protected]>; Ying Xue <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; [email protected]; opensource.kernel <[email protected]>; Jakub Kicinski <[email protected]> 主题: Re: [PATCH v1] net:tipc:Remove repeated initialization

[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]

Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Thu, 6 Jul 2023 21:42:09 +0800 Wang Ming wrote:

The original code initializes 'tmp' twice, which causes duplicate initialization issue.
To fix this, we remove the second initialization of 'tmp' and use 'parent' directly forsubsequent operations.

Quoted 6 lines
Quoted 1 line

Please stop sending the "remove repeated initialization" patches to networking, thanks.

The patch also looks just bogus, as 'parent' is now always NULL when:

     rb_link_node(&m->tree_node, parent, n);

is called after the while loop.

CJ

#5 lore raw

Re: net: tipc: Remove repeated “initialization” in tipc_group_add_to_tree()

Quoted 2 lines

The risk of breaking code (as you un-intentionally did) is higher than the value of removing a redundant initialization.

I find that it would be nicer to perform only required data processing steps. The application of variable assignments can occasionally be improved further.

The corresponding efforts grow for proper code review.

The discussed change possibilities might belong to the adjustment category “code cleanup”.
Some contributors have got difficulties to integrate presented ideas. Thus it seems that more attractive incentives need to be offered for potentially desirable software updates.

Regards,
Markus

#6 lore raw

RE: net: tipc: Remove repeated “initialization” in tipc_group_add_to_tree()

net/tipc/group.c static int tipc_group_add_to_tree(struct tipc_group *grp, · line 289

Quoted 5 lines
net/tipc/group.c +0 -2
-               parent = *n;
-               tmp = container_of(parent, struct tipc_member, tree_node);
                nkey = (u64)tmp->node << 32 | tmp->port;
                if (key < nkey)
                        n = &(*n)->rb_left;

[RESEND]
Your patch breaks my test suite. You introduced a new bug which was pointed out by Christophe.
It is a redundant assignment to variable tmp as you pointed out.
I suggest that you repost this cleanup together with other patches that you see need to be refactored (I believe there are still many things like this in TIPC) in the future, or I can do what you suggested in my future cleanup.

#7 lore raw
In reply to Jakub Kicinski

Hi Jakub Kicinski
: )
I understand, but I am confused about whether my modification is wrong?

-----邮件原件-----
发件人: Jakub Kicinski <[email protected]>
发送时间: 2023年7月6日 23:47
收件人: 王明-软件底层技术部 <[email protected]>
抄送: Jon Maloy <[email protected]>; Ying Xue <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; [email protected]; opensource.kernel <[email protected]> 主题: Re: [PATCH v1] net:tipc:Remove repeated initialization

[Some people who received this message don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 6 lines · On Thu, 6 Jul 2023 21:42:09 +0800 Wang Ming wrote:

The original code initializes 'tmp' twice, which causes duplicate initialization issue.
To fix this, we remove the second initialization of 'tmp' and use 'parent' directly forsubsequent operations.

Please stop sending the "remove repeated initialization" patches to networking, thanks.

#9 lore raw

Re: [PATCH] net: tipc: Remove repeated “initialization”

In reply to Wang Ming
Quoted 2 lines

The original code initializes 'tmp' twice,
which causes duplicate initialization issue.

Is it more appropriate to refer to a repetition of questionable variable assignments?

Quoted 3 lines

To fix this, we remove the second initialization
of 'tmp' and use 'parent' directly forsubsequent
operations.

* Would you like to avoid a typo in this sentence?

* Please choose a better imperative change suggestion.

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.4#n94

…

net/tipc/group.c static int tipc_group_add_to_tree(struct tipc_group *grp, · line 287

Quoted 8 lines

+++ b/net/tipc/group.c

net/tipc/group.c +0 -2
@@ -284,8 +284,6 @@ static int tipc_group_add_to_tree(struct tipc_group *grp,
 	n = &grp->members.rb_node;
 	while (*n) {
 		tmp = container_of(*n, struct tipc_member, tree_node);
-		parent = *n;
-		tmp = container_of(parent, struct tipc_member, tree_node);
 		nkey = (u64)tmp->node << 32 | tmp->port;

…

How does the proposed deletion fit to the function call “rb_link_node(&m->tree_node, parent, n)” after the loop?
https://elixir.bootlin.com/linux/v6.4.2/source/net/tipc/group.c#L277

Regards,
Markus