From mboxrd@z Thu Jan 1 00:00:00 1970 From: Greg Kroah-Hartman Subject: Re: [PATCH] tty/metag_da: initialize number_written to zero Date: Sat, 6 Feb 2016 23:41:09 -0800 Message-ID: <20160207074109.GA6508@kroah.com> References: <1453851445-4645-1-git-send-email-colin.king@canonical.com> <20160127114206.GB20777@jhogan-linux.le.imgtec.org> <56AA6271.1070108@canonical.com> Mime-Version: 1.0 Return-path: Content-Disposition: inline In-Reply-To: <56AA6271.1070108@canonical.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Colin Ian King Cc: James Hogan , Jiri Slaby , linux-metag@vger.kernel.org, linux-kernel@vger.kernel.org On Thu, Jan 28, 2016 at 06:48:17PM +0000, Colin Ian King wrote: > On 27/01/16 11:42, James Hogan wrote: > > Hi Colin, > > > > On Tue, Jan 26, 2016 at 11:37:25PM +0000, Colin King wrote: > >> From: Colin Ian King > >> > >> number_written is not initialized, so it can be any value. In the > >> case where dport->xmit_cnt is zero, number_written is not set > >> and subsequent accesses to it will be reading a garbage value. > > > > the only subsequent accesses when dport->xmit_cnt == 0 are: > > > > /* if we've made more data available, wake up tty */ > > if (count && number_written) { > > > > and: > > > > /* did the write fail? */ > > return count && !number_written; > > > > but dport->xmit_cnt == 0 implies count == 0, so number_written shouldn > 't > > be used, and both will evaluate to false regardless of the uninitialis > ed > > value, so it looks fine as it is to me. > > > > Is this tripping up some static analysis tool or something? > > It was found using cppcheck, namely: > > [drivers/tty/metag_da.c:269]: (error) Uninitialized variable: number_wri > tten Please fix the broken tool, don't paper over it by doing unnecessary work in the kernel. thanks, greg k-h