From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754678AbcA0LmN (ORCPT ); Wed, 27 Jan 2016 06:42:13 -0500 Received: from mailapp01.imgtec.com ([195.59.15.196]:49872 "EHLO imgpgp01.kl.imgtec.org" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754237AbcA0LmI (ORCPT ); Wed, 27 Jan 2016 06:42:08 -0500 X-PGP-Universal: processed; by imgpgp01.kl.imgtec.org on Wed, 27 Jan 2016 11:42:07 +0000 Date: Wed, 27 Jan 2016 11:42:06 +0000 From: James Hogan To: Colin King CC: Greg Kroah-Hartman , Jiri Slaby , , Subject: Re: [PATCH] tty/metag_da: initialize number_written to zero Message-ID: <20160127114206.GB20777@jhogan-linux.le.imgtec.org> References: <1453851445-4645-1-git-send-email-colin.king@canonical.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="24zk1gE8NUlDmwG9" Content-Disposition: inline In-Reply-To: <1453851445-4645-1-git-send-email-colin.king@canonical.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Originating-IP: [192.168.154.110] X-ESG-ENCRYPT-TAG: 56f439c Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --24zk1gE8NUlDmwG9 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Colin, On Tue, Jan 26, 2016 at 11:37:25PM +0000, Colin King wrote: > From: Colin Ian King >=20 > 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 =3D=3D 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 =3D=3D 0 implies count =3D=3D 0, so number_written shou= ldn't be used, and both will evaluate to false regardless of the uninitialised value, so it looks fine as it is to me. Is this tripping up some static analysis tool or something? Thanks James > Fix this by initializing it to zero for the case when > dport->xmit_count is zero. >=20 > Signed-off-by: Colin Ian King > --- > drivers/tty/metag_da.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/drivers/tty/metag_da.c b/drivers/tty/metag_da.c > index 9325262..3da89c1 100644 > --- a/drivers/tty/metag_da.c > +++ b/drivers/tty/metag_da.c > @@ -230,7 +230,7 @@ static int put_channel_data(unsigned int chan) > { > struct dashtty_port *dport; > struct tty_struct *tty; > - int number_written; > + int number_written =3D 0; > unsigned int count =3D 0; > =20 > dport =3D &dashtty_ports[chan]; > --=20 > 2.7.0.rc3 >=20 --24zk1gE8NUlDmwG9 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJWqK0OAAoJEGwLaZPeOHZ6YigP/32e0Fca+QmtGDdzaHq8m5JB a4viAi7HTY1LX81AQXGLRU2sl252KMnd2dbcIxwe7pRuGig4siOfoVUFVtzxlGrW lPC9QC+O4sBa7mSpm0l7Nd0Xobfxh6NbqMfLDZGK+TI/eT4aGhqtMDUohF8qjpcO ETKjALbnOHcGUaERU5doD9SyEow4blM4GNwrqbtNKeocf9933kQNvAa/1joXHXl9 GGfS1vB03v/pZcJDExdTK6lerPt9792x5AO/06OK4Et0OQfZu4l65gnNWl/H0yMF LitUUBdia5jnVfqtQVDe0FbRJlP9Ty8C8dYudGjd0rFmoQdxpf+l4n3g7zNrw1GC 6UuGdPIWRsv54SfUn/b53gD025vwQlKc83r4AtKOow14Q1ykbn3r/NPil9FWPVC5 spkqxj1cQaJth2Cyk7bxj6/L1gCN3aWvbkqx23YFvD3FXagbO0eYXy2rFudpQ2bE iuBMhTwRN/PsJuXaa8HxfrJg3QH2GWdCfBRQnk6t/VGfL8YTajiqi6HiRhe7Owk1 MxGp2foJmXifBP0j01fzEdiX35M8dDyXzzS+z3xHtEWSmLvXox091Wvjlu/siuPC Wjy6o8xBmtn6evllnwLuNylV1VR2tf/QiJpGDKsCDxzOekWvXUIDSBYyvvExG0Za Rz5bKP2u+hpPvokM817E =TgXd -----END PGP SIGNATURE----- --24zk1gE8NUlDmwG9--