From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751215AbdFAOke (ORCPT ); Thu, 1 Jun 2017 10:40:34 -0400 Received: from mx2.suse.de ([195.135.220.15]:40486 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751134AbdFAOkc (ORCPT ); Thu, 1 Jun 2017 10:40:32 -0400 Date: Thu, 1 Jun 2017 16:40:19 +0200 From: Jean Delvare To: Andy Shevchenko Cc: LKML , Dmitry Torokhov , Mika Westerberg , Linus Walleij Subject: Re: [PATCH] firmware: dmi: Check DMI structure length Message-ID: <20170601164019.0a4035a4@endymion> In-Reply-To: References: <20170601150839.08fdb556@endymion> Organization: SUSE Linux X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.31; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andy, Thanks for the review. On Thu, 1 Jun 2017 16:16:05 +0300, Andy Shevchenko wrote: > On Thu, Jun 1, 2017 at 4:08 PM, Jean Delvare wrote: > > Before accessing DMI data to record it for later, we should ensure > > that the DMI structures are large enough to contain the data in > > question. > > > - const u8 *d = (u8 *) dm + index; > > + const u8 *d; > > > + d = (u8 *) dm + index; > > I think you may leave this as is and make it compiler's burden to optimize. Is there any benefit except making the patch smaller? > > - const u8 *d = (u8 *) dm + index; > > + const u8 *d; > > > + d = (u8 *) dm + index; > > Ditto. > > > - int i, count = *(u8 *)(dm + 1); > > + int i, count; > > > + count = *(u8 *)(dm + 1); > > Ditto. I would expect a static code analyzer to complain about at least the last one. Dereferencing a pointer before checking its validity is bad. I'm not a big fan of counting of compiler optimizations to make the code right. -- Jean Delvare SUSE L3 Support