From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752914AbdFVJCq (ORCPT ); Thu, 22 Jun 2017 05:02:46 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:34124 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751163AbdFVJCp (ORCPT ); Thu, 22 Jun 2017 05:02:45 -0400 Date: Thu, 22 Jun 2017 11:02:41 +0200 From: Ingo Molnar To: Arnd Bergmann Cc: "Paul E. McKenney" , Thomas Gleixner , Sebastian Andrzej Siewior , Anna-Maria Gleixner , Boris Ostrovsky , Linux Kernel Mailing List Subject: Re: [PATCH] rcu: remove unused variable in boot_cpu_state_init Message-ID: <20170622090241.3cwwfesg7c43lgbq@gmail.com> References: <20170621215741.4028236-1-arnd@arndb.de> <20170621221054.GU3721@linux.vnet.ibm.com> <20170622072644.so23jacjhvrox5pd@gmail.com> <20170622075104.dlajhtcx7p3sgacs@gmail.com> <20170622075410.pur2m5dobqcwosjh@gmail.com> <20170622075910.mahc5gzrz5cxdsg6@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Arnd Bergmann wrote: > On Thu, Jun 22, 2017 at 9:59 AM, Ingo Molnar wrote: > > > > So, to continue this side thought about uninitialized_var(), it is dangerous > > because the following buggy pattern does not generate a compiler warning: > > > > long uninitialized_var(error); > > > > ... > > > > if (error) > > return error; > > > > > > ... and still there are over 290 uses of uninitialized_var() in the kernel - and > > any of them could turn into a silent but real uninitialized variable bugs due to > > subsequent changes. > > Right, absolutely agreed on that. A related problem however is blindly > initializing variables to NULL to get rid of uninitialized variable warnings, > such as > > struct subsystem_specific *obj = NULL; > if (function_argument > 10) > goto err; > obj = create_obj(); > ... > err: > clean_up(obj->member); > > > I've seen a couple of variations of that problem, so simply outlawing > uninitialized_var() will only solve a subset of these issues, and ideally > we should also make sure that initializations at declaration time are > used properly, and not just to shut up compiler warnings. Well, a deterministic crash on a NULL dereference is still (much) better than a non-deterministic 'use random value from stack and corrupt memory or crash' bug pattern, right? Also, static analysis tools ought to be pretty good about finding control flows where a NULL gets dereferenced. Thanks, Ingo