Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1168320pxb; Fri, 6 Nov 2020 02:49:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyTNOjUBYGusbfFZbAYxp7yYZAw18aj/L8jYlmoUPtGtVWpukYJg52es/7+vXF7wwxhTI7w X-Received: by 2002:a17:906:831a:: with SMTP id j26mr1443947ejx.450.1604659754091; Fri, 06 Nov 2020 02:49:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604659754; cv=none; d=google.com; s=arc-20160816; b=xQzxRYsD0JGCMyQ69uer8UqNhajEnCSceI1naw0JljwJGdVgGvdgUy9MNFYLL/Z/oi VySVwyMYpocK0uAjHJH2pkXGvUsVuwkDZt+ooAex85ZW3wcBIh9ZMLYEvxqCTXPu41Xx rRfDeKD+DJ5vZIcrhkxw0bw4MqJPZH2jK9l7FWLRbSiqdy9J2okWJn5J4LZNmCMxaa0a lacO+Kz5DiCpS9uuPiFZqJs3F8DgXgbzzhsUnfi9+y34epw4jIYYFN7Svu+QVvm6J7tn xsUPDvEQbhwcgbdszLgQmP0B0nRIbUqG5K6VGnpz7zOZK1/fFUbV+zXoN0NcRRqn7pIb Y38Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:date:from:dkim-signature; bh=sS6LjFB1Hny842iCOSq0gSFHnnlXSZfE6BxMZzj8mek=; b=dR46st+s35ihE8K+naOiUL5y1lXZIZlG1SVcnkcNBYprgTTFM5MCcbCRhxmFjUbHKW pjQC74ten8BGXZHoCwjRfHRhf9MpBwFIoG0Fg8fe4CWSLtKyITVMrUs5ufmDdIBU3Yeu 3KPCUzQff7AS+c71N7cNrsGcKPuIRQ7c5rWaJa/HBhyqef8iVYia/FmwkT01d770m8Jb wmEMsns7CJ67Cs2bvaUV/E/l/nLWl2J7SKooRsnlL8y5DEoQVUMQWNnSayJa+TFG8lQD +hH0WQrX5OvEqBWlNuopF374m4wa45z3ZmLJ9wJSL88fh+/d9i/brECV0srulRPCoTgH 3tjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZOkhO3Ur; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y3si800131edm.138.2020.11.06.02.48.51; Fri, 06 Nov 2020 02:49:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZOkhO3Ur; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726960AbgKFKrX (ORCPT + 99 others); Fri, 6 Nov 2020 05:47:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbgKFKrX (ORCPT ); Fri, 6 Nov 2020 05:47:23 -0500 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BA75C0613CF; Fri, 6 Nov 2020 02:47:22 -0800 (PST) Received: by mail-ej1-x642.google.com with SMTP id o21so1276029ejb.3; Fri, 06 Nov 2020 02:47:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=sS6LjFB1Hny842iCOSq0gSFHnnlXSZfE6BxMZzj8mek=; b=ZOkhO3Uri73lGsBrJPKvQX8VfO8Y4OPTkk4naQG0B0lDGfmkvc+TcbWh8irWkItyZD /wNP/VlswRYcgt1dxzWOOklcwF/wIc+XVz5HMZZ59bIvpa+nXXZR5/QrC45AfJLQkrS4 1uKyO4isqOEnbdePOQM5kdSAApfh7e7S6MDCjjl75noImrWi2rvs5YEn3hwLRDhyVhIQ 4O+kbMiTHt2CU0oQ4UMtWHKMuXXwCweQeylgQGOAyeqtpIWHS1dg9O6+VVeMmwLgoWzA oIZJn3fmXaQtsv3wiCpJ5YGvw04WZp2NXHggqSE56JoV5Bk4SrMeO2sn+xzaN7Oa/MX+ FiaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=sS6LjFB1Hny842iCOSq0gSFHnnlXSZfE6BxMZzj8mek=; b=Wvq4ws2kr3g0QhMepOQTHfk/4brfsxnsHi1X0Tafv5ZFheBqIVIoCgnGTvVxEIU8ms ex6EcSnVMiRR9a5T9cgt3YGjR+FM3Q/70+zgGLHYkZo8EbwgiMLxHS7nACp+ZWHTc7X+ LeIhV8H5JMlBWsm48lCuBwN4D9LeycDOvx2DKNqos2CLPHryqdkkHwk6YFisiVzfOm4j CfXYDuN0+G5GnsQrnH/sNF5c4q/j+o1tMHC0QMRKrvaCWc6cfzyugsUqLNMSJsn9PZ20 76pwcsBJtqRmBi4/3gKVj4ctmq43aSy+BP/rpHuGvJzf7uCkFtA5j9YThLRibDEwFbUp +PQg== X-Gm-Message-State: AOAM533MnQ6mseAtBpGCKzaeDwYZV9kCyiMRDh5qzC5NSdHT2T8kBaNb PZxaR2Ce+LInco//WIPMffc= X-Received: by 2002:a17:906:748b:: with SMTP id e11mr1306240ejl.513.1604659641272; Fri, 06 Nov 2020 02:47:21 -0800 (PST) Received: from felia ([2001:16b8:2d20:9d00:e580:adb5:1ef:950d]) by smtp.gmail.com with ESMTPSA id j4sm649195ejs.8.2020.11.06.02.47.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2020 02:47:20 -0800 (PST) From: Lukas Bulwahn X-Google-Original-From: Lukas Bulwahn Date: Fri, 6 Nov 2020 11:47:19 +0100 (CET) X-X-Sender: lukas@felia To: Lukas Bulwahn cc: Nathan Chancellor , Balbir Singh , Tom Rix , Nick Desaulniers , clang-built-linux@googlegroups.com, kernel-janitors@vger.kernel.org, linux-safety@lists.elisa.tech, linux-kernel@vger.kernel.org Subject: Re: [PATCH] taskstats: remove unneeded dead assignment In-Reply-To: Message-ID: References: <20201106062210.27920-1-lukas.bulwahn@gmail.com> <20201106095004.GA3269193@ubuntu-m3-large-x86> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 6 Nov 2020, Lukas Bulwahn wrote: > > > On Fri, 6 Nov 2020, Nathan Chancellor wrote: > > > On Fri, Nov 06, 2020 at 07:22:10AM +0100, 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. > > > > > > As compilers will detect this unneeded assignment and optimize this anyway, > > > the resulting object code is identical before and after this change. > > > > > > No functional change. No change to object code. > > > > > > Signed-off-by: Lukas Bulwahn > > > > Question below. > > > > Reviewed-by: Nathan Chancellor > > > > > --- > > > applies cleanly on current master and next-20201105 > > > > > > Balbir, please pick this minor non-urgent clean-up patch. > > > > > > kernel/taskstats.c | 1 - > > > 1 file changed, 1 deletion(-) > > > > > > diff --git a/kernel/taskstats.c b/kernel/taskstats.c > > > index a2802b6ff4bb..bd18a7bf5276 100644 > > > --- a/kernel/taskstats.c > > > +++ b/kernel/taskstats.c > > > @@ -117,7 +117,6 @@ static void send_cpu_listeners(struct sk_buff *skb, > > > > > > genlmsg_end(skb, reply); > > > > > > - rc = 0; > > > down_read(&listeners->sem); > > > list_for_each_entry(s, &listeners->list, list) { > > > > Would it be worth moving the scope of rc into the for loop, now that it > > is only used there? Looks like it used to be used in the main function > > scope before commit 053c095a82cf ("netlink: make nlmsg_end() and > > genlmsg_end() void") but if this is removed, it is only used to check > > the return of genlmsg_unicast within the list_for_each_entry loop. Not > > sure that buys us anything but I know you have done it in patches > > before so I thought it was worth considering. > > > > I thought about moving it into the local scope, but it is a purely > cosmetic matter. Compilers are smart enough to generate the same code no > matter where it is defined. > So, I always look around in the same file to determine if there is some > kind of strong preference for very locally scoped variable definition or > if they are generally just all defined at the function entry. > > Depending on my gut feeling in which style the file has mainly been > written, I then go with the one or other option. In this case, I went > with just keeping the definition at the function entry. > > There is really no strong rule, though, that I see serving as good > indicator. > > Thanks for your review. > More specifically, if I think rc should be only defined locally, I would probably need to apply the same argument to skb_next in this function and put that in local scope as well. That did not happen in the past, so I am not going to change that now neither. Hence, the change stays minimal invasive but and that is important: it makes clang-analyzer happy. And a happy clang-analyzer will eventually point to real bugs :) There are a few examples of dead store warnings that in the end really point to missing or wrong paths in some functions... Lukas