Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3646324pxb; Mon, 9 Nov 2020 17:28:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwELoHNKc76ONxD1NHjEinuCaIt5FmdAQDsOBerTP40HRbrfQ6C5+0jO5GTYExxHYlm/aD7 X-Received: by 2002:a05:6402:1a58:: with SMTP id bf24mr17787648edb.191.1604971739370; Mon, 09 Nov 2020 17:28:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604971739; cv=none; d=google.com; s=arc-20160816; b=sdHJqxmYz5o8JJ8Z6JLVAIMJsIsb8oqDeVzlyT3ONz1MHb+1wjDG+6JvboBu/ktXgC 4nKwOdE4goyUeNJM5MIMC78fkNskeXQiV8yib0OFaPzBFZ7VehJWudEghd1ysVfEVP0y JtklxO74eo3/YkgFDB7GsReoeEthbZk8fmVJMU9EVOom768aQFgEbgKrBn08N0VlIQqj ECaeDI5dP5BGE7Ct5SVwMjUOFV76rmIBmHhcDSKAaFbFflJt9c1AtA06AMk/RgYTrtNu IjZbk+4n7ZYAWT/3z/jAIZtjAH0JSBx0pc6uoD/C3fMrgxa4zoh4epjPshaYKVoHEKWp Q56A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=t05JtdUe9+ueKiWP7Cd0WcO5v2xombvbloOzDhjvSkg=; b=hUFSeCkP2gp9YjKYFxiMwOst4N+UiYm8SW5/EEdyQkOjcc2kPJNZ3h989WCO2s7m0R yU4c5p0WQHikEColp1KkwuX9eS9/vdj0PC+YkAj8J52lxg0/io5gSjFIEh8YpxzybcBS u50R045/wskQ/hYsms5k6M7kuvmrCswXvo4F6FCYn9xWYPgNuY0rwd+FoM94neGk0iEx CWia4jqh579HC9jkSlYVZk+vFSCZSyXmrmo+yuvSXOYpWci39ffPaOq7mJ+W7LWuNRhy bgTcZlhgozoyeMWjhXQZ9lj0+IPY0xWgZfeJRxSCqwQZDMTHwa037T1KHWGOwDPQhpmx s10A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=a5cXAsAz; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l3si7613967edq.552.2020.11.09.17.28.36; Mon, 09 Nov 2020 17:28:59 -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=@redhat.com header.s=mimecast20190719 header.b=a5cXAsAz; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730140AbgKJB0o (ORCPT + 99 others); Mon, 9 Nov 2020 20:26:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:27358 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729452AbgKJB0o (ORCPT ); Mon, 9 Nov 2020 20:26:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604971602; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t05JtdUe9+ueKiWP7Cd0WcO5v2xombvbloOzDhjvSkg=; b=a5cXAsAzZcCX5n0dE5L76oRC/nEsXkbQ1QPfRmQ2d7qjLx9/a91RlDyiorZ7oAH4kYj8vX wRCjN0c7U5fDHoU6F8QtFoNmJtQVzJqf6/nzYOZzIOWRJT1I68ysPoY07mzoQR77m+iDEh UOiIAW8hRwJASoWfVI5vCCGffOkbyLI= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-6-yMDUY7PFOhK4mHwDwfFhzA-1; Mon, 09 Nov 2020 20:26:40 -0500 X-MC-Unique: yMDUY7PFOhK4mHwDwfFhzA-1 Received: by mail-qv1-f72.google.com with SMTP id dd7so6974030qvb.6 for ; Mon, 09 Nov 2020 17:26:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=t05JtdUe9+ueKiWP7Cd0WcO5v2xombvbloOzDhjvSkg=; b=JI2mXwlS3HrIpxEmGsPs3q/zvQseBMcFkmnjq5a7pgtbMJZwEc8cRx48w8+BwT6Rx8 i26u2YpefiRXnCi4sDKg/Ym0JRLgyFlprc5+limw+oJTBB/g20zR03I9R9URsYyAs147 AvvJJgr4qcUQ3ROX4i927pd922FtEMm3esxLiM4IQxgTdysYN8M0Glb/3DxQXOJpzyNV uo0h38Wg8m4MEV4WC1PU9LgdN5NljzgtAf8ChzrqpJ4i5bNfznjr8tXpLbIlMGB+YQ4m yzDlPILTG/gO43w3sCc04v3BfrSvIoTkZNbf5/2+r6TCpQgUuBQbmaiqssdp8GFKd+Jk ZE5A== X-Gm-Message-State: AOAM532ZmAJstf4dvYKi8KNU/RbPzCrZwBfrzMTs5d47f0wIEudSGpBU 2r4KCYlRKcAvhvsippQ4401UG6UtDIYZs3RVOR+O1odEXhc/P8ew2GdBBlRKzk00QqMIcR0GMJu kCXKuYibrqq7FuWZ+31d35Sv0o/xv6t60WNn0yLqNrV5HXtwqkasSLdMMcYOOElXOZRF8Ybw= X-Received: by 2002:a05:6214:12e8:: with SMTP id w8mr12148228qvv.16.1604971600142; Mon, 09 Nov 2020 17:26:40 -0800 (PST) X-Received: by 2002:a05:6214:12e8:: with SMTP id w8mr12148196qvv.16.1604971599811; Mon, 09 Nov 2020 17:26:39 -0800 (PST) Received: from trix.remote.csb (075-142-250-213.res.spectrum.com. [75.142.250.213]) by smtp.gmail.com with ESMTPSA id f56sm5363152qta.49.2020.11.09.17.26.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Nov 2020 17:26:39 -0800 (PST) Subject: Re: [PATCH] sysctl: move local variable in proc_do_large_bitmap() to proper scope To: Lukas Bulwahn , Luis Chamberlain , Kees Cook , Iurii Zaikin , linux-fsdevel@vger.kernel.org Cc: Nathan Chancellor , Nick Desaulniers , clang-built-linux@googlegroups.com, kernel-janitors@vger.kernel.org, linux-safety@lists.elisa.tech, linux-kernel@vger.kernel.org References: <20201109071107.22560-1-lukas.bulwahn@gmail.com> From: Tom Rix Message-ID: Date: Mon, 9 Nov 2020 17:26:37 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20201109071107.22560-1-lukas.bulwahn@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/8/20 11:11 PM, Lukas Bulwahn wrote: > make clang-analyzer caught my attention with: > > kernel/sysctl.c:1511:4: warning: Value stored to 'first' is never read \ > [clang-analyzer-deadcode.DeadStores] > first = 0; > ^ > > Commit 9f977fb7ae9d ("sysctl: add proc_do_large_bitmap") introduced > proc_do_large_bitmap(), where the variable first is only effectively used > when write is false; when write is true, the variable first is only used in > a dead assignment. > > So, simply remove this dead assignment and put the variable in local scope. > > 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 > --- > applies cleanly on v5.10-rc3 and next-20201106 > > Luis, Kees, Iurii, please pick this minor non-urgent clean-up patch. > > kernel/sysctl.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/kernel/sysctl.c b/kernel/sysctl.c > index ce75c67572b9..cc274a431d91 100644 > --- a/kernel/sysctl.c > +++ b/kernel/sysctl.c > @@ -1423,7 +1423,6 @@ int proc_do_large_bitmap(struct ctl_table *table, int write, > void *buffer, size_t *lenp, loff_t *ppos) > { > int err = 0; > - bool first = 1; > size_t left = *lenp; > unsigned long bitmap_len = table->maxlen; > unsigned long *bitmap = *(unsigned long **) table->data; > @@ -1508,12 +1507,12 @@ int proc_do_large_bitmap(struct ctl_table *table, int write, > } > > bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1); > - first = 0; > proc_skip_char(&p, &left, '\n'); > } > left += skipped; > } else { > unsigned long bit_a, bit_b = 0; > + bool first = 1; This looks fine, but while you are here how about setting, to match the type first = true And then only clearing first once if (!first)                                                                               proc_put_char(&buffer, &left, ','); else   first = false Instead of at every loop iteraction Tom > > while (left) { > bit_a = find_next_bit(bitmap, bitmap_len, bit_b);