2020-11-06 10:35:53

by Lukas Bulwahn

[permalink] [raw]
Subject: Re: [linux-safety] [PATCH] taskstats: remove unneeded dead assignment



On Fri, 6 Nov 2020, Sudip Mukherjee wrote:

> Hi Lukas,
>
> On 06/11/2020 06:22, Lukas Bulwahn wrote:
> > make clang-analyzer on x86_64 defconfig caught my attention with:
> >
> > kernel/taskstats.c:120:2: warning: Value stored to 'rc' is never read \
> > [clang-analyzer-deadcode.DeadStores]
> > rc = 0;
> > ^
> >
> > Commit d94a041519f3 ("taskstats: free skb, avoid returns in
> > send_cpu_listeners") made send_cpu_listeners() not return a value and
> > hence, the rc variable remained only to be used within the loop where
> > it is always assigned before read and it does not need any other
> > initialisation.
> >
> > So, simply remove this unneeded dead initializing assignment.
>
> Might be better to remove 'rc' completely as it is only used for the if
> condition now.
>
> diff --git a/kernel/taskstats.c b/kernel/taskstats.c
> index a2802b6ff4bb..63541f1ae04a 100644
> --- a/kernel/taskstats.c
> +++ b/kernel/taskstats.c
> @@ -113,11 +113,10 @@ static void send_cpu_listeners(struct sk_buff *skb,
> struct listener *s, *tmp;
> struct sk_buff *skb_next, *skb_cur = skb;
> void *reply = genlmsg_data(genlhdr);
> - int rc, delcount = 0;
> + int delcount = 0;
>
> genlmsg_end(skb, reply);
>
> - rc = 0;
> down_read(&listeners->sem);
> list_for_each_entry(s, &listeners->list, list) {
> skb_next = NULL;
> @@ -126,8 +125,8 @@ static void send_cpu_listeners(struct sk_buff *skb,
> if (!skb_next)
> break;
> }
> - rc = genlmsg_unicast(&init_net, skb_cur, s->pid);
> - if (rc == -ECONNREFUSED) {
> + if (genlmsg_unicast(&init_net, skb_cur, s->pid) ==
> + -ECONNREFUSED) {

I thought about that as well; and I did not like that because of the ugly
line break in this condition.

I did not try but I bet (a beverage of your choice) that the object code
remains the same also for your suggested patch. Try to disprove my claim
and possibly earn yourself a beverage when we meet...

Lukas


2020-11-06 12:10:48

by Sudip Mukherjee

[permalink] [raw]
Subject: Re: [linux-safety] [PATCH] taskstats: remove unneeded dead assignment

Hi Lukas,

On 06/11/2020 10:31, Lukas Bulwahn wrote:
>
>
> On Fri, 6 Nov 2020, Sudip Mukherjee wrote:
>
>> Hi Lukas,
>>

<snip>

>
> I did not try but I bet (a beverage of your choice) that the object code
> remains the same also for your suggested patch. Try to disprove my claim
> and possibly earn yourself a beverage when we meet...

Lets decide which beverage.. ;-)

Using gcc-7.2.0 for MIPS:

original:- ab81d3305d578c2568fbc73aad2f9e61 kernel/taskstats.o
After your change:- ab81d3305d578c2568fbc73aad2f9e61 kernel/taskstats.o
After my change:- 0acae2c8d72abd3e15bf805fccdca711 kernel/taskstats.o



--
Regards
Sudip

2020-11-06 12:41:15

by Lukas Bulwahn

[permalink] [raw]
Subject: Re: [linux-safety] [PATCH] taskstats: remove unneeded dead assignment



On Fri, 6 Nov 2020, Sudip Mukherjee wrote:

> Hi Lukas,
>
> On 06/11/2020 10:31, Lukas Bulwahn wrote:
> >
> >
> > On Fri, 6 Nov 2020, Sudip Mukherjee wrote:
> >
> >> Hi Lukas,
> >>
>
> <snip>
>
> >
> > I did not try but I bet (a beverage of your choice) that the object code
> > remains the same also for your suggested patch. Try to disprove my claim
> > and possibly earn yourself a beverage when we meet...
>
> Lets decide which beverage.. ;-)
>
> Using gcc-7.2.0 for MIPS:
>
> original:- ab81d3305d578c2568fbc73aad2f9e61 kernel/taskstats.o
> After your change:- ab81d3305d578c2568fbc73aad2f9e61 kernel/taskstats.o
> After my change:- 0acae2c8d72abd3e15bf805fccdca711 kernel/taskstats.o
>
>

Interesting, can you share the diff of the objdump before and after?

I bet it found now a different assignment from variables to registers or
so; with the beverage at hand, we can then discuss if that is effectively
still the same object code or not.

Thanks for confirming that my patch here really remains the same compared
to before, even on MIPS :) I only checked x86-64...

Lukas

>
> --
> Regards
> Sudip
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#148): https://lists.elisa.tech/g/linux-safety/message/148
> Mute This Topic: https://lists.elisa.tech/mt/78069241/1714638
> Group Owner: [email protected]
> Unsubscribe: https://lists.elisa.tech/g/linux-safety/unsub [[email protected]]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>
>

2020-11-10 08:09:19

by Dan Carpenter

[permalink] [raw]
Subject: Re: [linux-safety] [PATCH] taskstats: remove unneeded dead assignment

On Fri, Nov 06, 2020 at 12:04:53PM +0000, Sudip Mukherjee wrote:
> Hi Lukas,
>
> On 06/11/2020 10:31, Lukas Bulwahn wrote:
> >
> >
> > On Fri, 6 Nov 2020, Sudip Mukherjee wrote:
> >
> >> Hi Lukas,
> >>
>
> <snip>
>
> >
> > I did not try but I bet (a beverage of your choice) that the object code
> > remains the same also for your suggested patch. Try to disprove my claim
> > and possibly earn yourself a beverage when we meet...
>
> Lets decide which beverage.. ;-)
>
> Using gcc-7.2.0 for MIPS:
>
> original:- ab81d3305d578c2568fbc73aad2f9e61 kernel/taskstats.o
> After your change:- ab81d3305d578c2568fbc73aad2f9e61 kernel/taskstats.o
> After my change:- 0acae2c8d72abd3e15bf805fccdca711 kernel/taskstats.o

I'm surprised the line numbers from the printks aren't affecting it...

I personally prefer Lukas's patch. "rc" should be function scope...

regards,
dan carpenter