netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] net:tipc:Remove repeated initialization
@ 2023-07-06 13:42 Wang Ming
  2023-07-06 15:47 ` Jakub Kicinski
  2023-07-06 18:50 ` [PATCH] net: tipc: Remove repeated “initialization” Markus Elfring
  0 siblings, 2 replies; 10+ messages in thread
From: Wang Ming @ 2023-07-06 13:42 UTC (permalink / raw)
  To: Jon Maloy, Ying Xue, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, tipc-discussion,
	linux-kernel
  Cc: opensource.kernel, Wang Ming

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.

Signed-off-by: Wang Ming <machel@vivo.com>
---
 net/tipc/group.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/net/tipc/group.c b/net/tipc/group.c
index 3e137d8c9d2f..b2f964f62c36 100644
--- a/net/tipc/group.c
+++ b/net/tipc/group.c
@@ -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;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v1] net:tipc:Remove repeated initialization
  2023-07-06 13:42 [PATCH v1] net:tipc:Remove repeated initialization Wang Ming
@ 2023-07-06 15:47 ` Jakub Kicinski
  2023-07-06 17:13   ` Christophe JAILLET
  2023-07-07  1:21   ` 回复: [PATCH v1] net:tipc:Remove repeated initialization 王明-软件底层技术部
  2023-07-06 18:50 ` [PATCH] net: tipc: Remove repeated “initialization” Markus Elfring
  1 sibling, 2 replies; 10+ messages in thread
From: Jakub Kicinski @ 2023-07-06 15:47 UTC (permalink / raw)
  To: Wang Ming
  Cc: Jon Maloy, Ying Xue, David S. Miller, Eric Dumazet, Paolo Abeni,
	netdev, tipc-discussion, linux-kernel, opensource.kernel

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.
> 
> Signed-off-by: Wang Ming <machel@vivo.com>

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1] net:tipc:Remove repeated initialization
  2023-07-06 15:47 ` Jakub Kicinski
@ 2023-07-06 17:13   ` Christophe JAILLET
  2023-07-07  1:24     ` 回复: " 王明-软件底层技术部
  2023-07-07  1:21   ` 回复: [PATCH v1] net:tipc:Remove repeated initialization 王明-软件底层技术部
  1 sibling, 1 reply; 10+ messages in thread
From: Christophe JAILLET @ 2023-07-06 17:13 UTC (permalink / raw)
  To: Wang Ming
  Cc: Jon Maloy, Ying Xue, David S. Miller, Eric Dumazet, Paolo Abeni,
	netdev, tipc-discussion, linux-kernel, opensource.kernel,
	Jakub Kicinski

Le 06/07/2023 à 17:47, Jakub Kicinski a écrit :
> 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.
>>
>> Signed-off-by: Wang Ming <machel@vivo.com>
> 
> 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] net: tipc: Remove repeated “initialization”
  2023-07-06 13:42 [PATCH v1] net:tipc:Remove repeated initialization Wang Ming
  2023-07-06 15:47 ` Jakub Kicinski
@ 2023-07-06 18:50 ` Markus Elfring
  1 sibling, 0 replies; 10+ messages in thread
From: Markus Elfring @ 2023-07-06 18:50 UTC (permalink / raw)
  To: Wang Ming, tipc-discussion, netdev, kernel-janitors,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Jon Maloy,
	Paolo Abeni, Ying Xue
  Cc: opensource.kernel, LKML

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

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


> 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> +++ b/net/tipc/group.c
> @@ -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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* 回复: [PATCH v1] net:tipc:Remove repeated initialization
  2023-07-06 15:47 ` Jakub Kicinski
  2023-07-06 17:13   ` Christophe JAILLET
@ 2023-07-07  1:21   ` 王明-软件底层技术部
  2023-07-07  1:54     ` Jakub Kicinski
  1 sibling, 1 reply; 10+ messages in thread
From: 王明-软件底层技术部 @ 2023-07-07  1:21 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Jon Maloy, Ying Xue, David S. Miller, Eric Dumazet, Paolo Abeni,
	netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
	LKML, opensource.kernel

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

-----邮件原件-----
发件人: Jakub Kicinski <kuba@kernel.org> 
发送时间: 2023年7月6日 23:47
收件人: 王明-软件底层技术部 <machel@vivo.com>
抄送: Jon Maloy <jmaloy@redhat.com>; Ying Xue <ying.xue@windriver.com>; David S. Miller <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Paolo Abeni <pabeni@redhat.com>; netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org; opensource.kernel <opensource.kernel@vivo.com>
主题: Re: [PATCH v1] net:tipc:Remove repeated initialization

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

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.
>
> Signed-off-by: Wang Ming <machel@vivo.com>

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* 回复: [PATCH v1] net:tipc:Remove repeated initialization
  2023-07-06 17:13   ` Christophe JAILLET
@ 2023-07-07  1:24     ` 王明-软件底层技术部
  2023-07-07  5:24       ` Christophe JAILLET
  0 siblings, 1 reply; 10+ messages in thread
From: 王明-软件底层技术部 @ 2023-07-07  1:24 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Jon Maloy, Ying Xue, David S. Miller, Eric Dumazet, Paolo Abeni,
	netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
	LKML, opensource.kernel, Jakub Kicinski

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

-----邮件原件-----
发件人: Christophe JAILLET <christophe.jaillet@wanadoo.fr> 
发送时间: 2023年7月7日 1:14
收件人: 王明-软件底层技术部 <machel@vivo.com>
抄送: Jon Maloy <jmaloy@redhat.com>; Ying Xue <ying.xue@windriver.com>; David S. Miller <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Paolo Abeni <pabeni@redhat.com>; netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org; opensource.kernel <opensource.kernel@vivo.com>; Jakub Kicinski <kuba@kernel.org>
主题: Re: [PATCH v1] net:tipc:Remove repeated initialization

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

Le 06/07/2023 à 17:47, Jakub Kicinski a écrit :
> 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.
>>
>> Signed-off-by: Wang Ming <machel@vivo.com>
>
> 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: 回复: [PATCH v1] net:tipc:Remove repeated initialization
  2023-07-07  1:21   ` 回复: [PATCH v1] net:tipc:Remove repeated initialization 王明-软件底层技术部
@ 2023-07-07  1:54     ` Jakub Kicinski
  0 siblings, 0 replies; 10+ messages in thread
From: Jakub Kicinski @ 2023-07-07  1:54 UTC (permalink / raw)
  To: 王明-软件底层技术部
  Cc: Jon Maloy, Ying Xue, David S. Miller, Eric Dumazet, Paolo Abeni,
	netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
	LKML, opensource.kernel

On Fri, 7 Jul 2023 01:21:52 +0000 王明-软件底层技术部 wrote:
> Hi Jakub Kicinski
> : )
> I understand, but I am confused about whether my modification is wrong?

The changes are so trivial they are not worth spending time on.

And you haven't read:
https://www.kernel.org/doc/html/next/process/index.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: 回复: [PATCH v1] net:tipc:Remove repeated initialization
  2023-07-07  1:24     ` 回复: " 王明-软件底层技术部
@ 2023-07-07  5:24       ` Christophe JAILLET
  2023-07-07  6:42         ` net: tipc: Remove repeated “initialization” in tipc_group_add_to_tree() Markus Elfring
  0 siblings, 1 reply; 10+ messages in thread
From: Christophe JAILLET @ 2023-07-07  5:24 UTC (permalink / raw)
  To: 王明-软件底层技术部
  Cc: Jon Maloy, Ying Xue, David S. Miller, Eric Dumazet, Paolo Abeni,
	netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
	LKML, opensource.kernel, Jakub Kicinski

Le 07/07/2023 à 03:24, 王明-软件底层技术部 a écrit :
> 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


> 
> -----邮件原件-----
> 发件人: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> 发送时间: 2023年7月7日 1:14
> 收件人: 王明-软件底层技术部 <machel@vivo.com>
> 抄送: Jon Maloy <jmaloy@redhat.com>; Ying Xue <ying.xue@windriver.com>; David S. Miller <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Paolo Abeni <pabeni@redhat.com>; netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org; opensource.kernel <opensource.kernel@vivo.com>; Jakub Kicinski <kuba@kernel.org>
> 主题: Re: [PATCH v1] net:tipc:Remove repeated initialization
> 
> [你通常不会收到来自 christophe.jaillet@wanadoo.fr 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
> 
> Le 06/07/2023 à 17:47, Jakub Kicinski a écrit :
>> 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.
>>>
>>> Signed-off-by: Wang Ming <machel@vivo.com>
>>
>> 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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: net: tipc: Remove repeated “initialization” in tipc_group_add_to_tree()
  2023-07-07  5:24       ` Christophe JAILLET
@ 2023-07-07  6:42         ` Markus Elfring
  2023-07-07 10:25           ` Tung Quang Nguyen
  0 siblings, 1 reply; 10+ messages in thread
From: Markus Elfring @ 2023-07-07  6:42 UTC (permalink / raw)
  To: Christophe Jaillet,
	王明-软件底层技术部,
	opensource.kernel, tipc-discussion, netdev, kernel-janitors
  Cc: LKML, Dan Carpenter, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Jon Maloy, Paolo Abeni, Ying Xue

> 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: net: tipc: Remove repeated “initialization” in tipc_group_add_to_tree()
  2023-07-07  6:42         ` net: tipc: Remove repeated “initialization” in tipc_group_add_to_tree() Markus Elfring
@ 2023-07-07 10:25           ` Tung Quang Nguyen
  0 siblings, 0 replies; 10+ messages in thread
From: Tung Quang Nguyen @ 2023-07-07 10:25 UTC (permalink / raw)
  To: 王明-软件底层技术部,
	tipc-discussion@lists.sourceforge.net, netdev@vger.kernel.org
  Cc: Dan Carpenter, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Jon Maloy, Paolo Abeni, Ying Xue, Markus Elfring,
	Christophe Jaillet, opensource.kernel@vivo.com

> -               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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-07-07 10:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-06 13:42 [PATCH v1] net:tipc:Remove repeated initialization Wang Ming
2023-07-06 15:47 ` Jakub Kicinski
2023-07-06 17:13   ` Christophe JAILLET
2023-07-07  1:24     ` 回复: " 王明-软件底层技术部
2023-07-07  5:24       ` Christophe JAILLET
2023-07-07  6:42         ` net: tipc: Remove repeated “initialization” in tipc_group_add_to_tree() Markus Elfring
2023-07-07 10:25           ` Tung Quang Nguyen
2023-07-07  1:21   ` 回复: [PATCH v1] net:tipc:Remove repeated initialization 王明-软件底层技术部
2023-07-07  1:54     ` Jakub Kicinski
2023-07-06 18:50 ` [PATCH] net: tipc: Remove repeated “initialization” Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).