From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jiri Pirko Subject: Re: [PATCH] flow_dissector: avoid uninitialized variable access Date: Sat, 22 Oct 2016 08:55:48 +0200 Message-ID: <20161022065548.GA1625@nanopsycho.orion> References: <20161021155626.4020344-1-arnd@arndb.de> <20161021163118.GA2155@nanopsycho.orion> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Arnd Bergmann , "David S. Miller" , Alexander Duyck , Tom Herbert , Jiri Pirko , Hadar Hen Zion , Gao Feng , Eric Garver , Amir Vadai , Network Development , Linux Kernel Mailing List To: Linus Torvalds Return-path: Received: from mail-wm0-f52.google.com ([74.125.82.52]:38215 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752134AbcJVGzx (ORCPT ); Sat, 22 Oct 2016 02:55:53 -0400 Received: by mail-wm0-f52.google.com with SMTP id c78so22376412wme.1 for ; Fri, 21 Oct 2016 23:55:52 -0700 (PDT) Content-Disposition: inline In-Reply-To: Sender: netdev-owner@vger.kernel.org List-ID: Sat, Oct 22, 2016 at 03:48:48AM CEST, torvalds@linux-foundation.org wrote: >On Fri, Oct 21, 2016 at 9:31 AM, Jiri Pirko wrote: >> >> I don't see how vlan could be used uninitialized. But I understand that >> this is impossible for gcc to track it. Please just use uninitialized_var() > >Actually, I think we should never use "uninitialized_var()" except >possibly for arrays or structures that gcc can complain about. > >It's a horrible thing to use, in that it adds extra cruft to the >source code, and then shuts up a compiler warning (even the _reliable_ >warnings from gcc). > >It's much better to just initialize the variable, and if gcc some day >gets smarter and sees that it is unnecessary and always overwritten, >so much the better. The cost of initializing a single word is >basically zero. On the other hand, I would agrue that initializing a var to "some" value that is never used might confuse the reader. He would naturally try to understand the reason for that exact value in initialization.