From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2061FC2D0A3 for ; Tue, 10 Nov 2020 01:26:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF3D02078D for ; Tue, 10 Nov 2020 01:26:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="a5cXAsAz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730603AbgKJB0o (ORCPT ); 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-Google-Smtp-Source: ABdhPJyId0TiOzOqiFGE0H+bF95RmGtjd6vw5jTrtLt0Hd3sykGjZMSOHupvlqQGlMR7Zd+CbsLsbQ== 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);