From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754224AbdCBBKH (ORCPT ); Wed, 1 Mar 2017 20:10:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34516 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753667AbdCBBKC (ORCPT ); Wed, 1 Mar 2017 20:10:02 -0500 Date: Wed, 1 Mar 2017 19:03:42 -0600 From: Josh Poimboeuf To: Arnd Bergmann Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Linux Kernel Mailing List , Denys Vlasenko Subject: Re: [PATCH] [RFC] x86: avoid -mtune=atom for objtool warnings Message-ID: <20170302010342.fshczxfiiz3txgac@treble> References: <20161010125709.1870563-1-arnd@arndb.de> <20161011150541.opini6gbolmnpzy5@treble> <20161011155146.icyl3zewdvmms2h2@treble> <2252957.Vm1BYSSRqP@wuerfel> <20170301144008.3ocnbvry4sbl3cnu@treble> <20170301165355.w2kmdmbql2f2ouzg@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.0.1 (2016-04-01) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 02 Mar 2017 01:03:45 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 01, 2017 at 11:42:54PM +0100, Arnd Bergmann wrote: > On Wed, Mar 1, 2017 at 5:53 PM, Josh Poimboeuf wrote: > > On Wed, Mar 01, 2017 at 04:27:29PM +0100, Arnd Bergmann wrote: > > > I see no apparent reason for the ud2. > > It's the possible division by zero. This change would avoid the ud2: > > diff --git a/drivers/i2c/busses/i2c-img-scb.c b/drivers/i2c/busses/i2c-img-scb.c > index db8e8b40569d..a2b09c518225 100644 > --- a/drivers/i2c/busses/i2c-img-scb.c > +++ b/drivers/i2c/busses/i2c-img-scb.c > @@ -1196,6 +1196,8 @@ static int img_i2c_init(struct img_i2c *i2c) > clk_khz /= prescale; > > /* Setup the clock increment value */ > + if (clk_khz < 1) > + clk_khz = 1; > inc = (256 * 16 * bitrate_khz) / clk_khz; > > /* Ok, I see what gcc is doing. clk_khz = clk_get_rate(i2c->scb_clk) / 1000; ... inc = (256 * 16 * bitrate_khz) / clk_khz; Because CONFIG_HAVE_CLK isn't set, clk_get_rate() returns 0, which means clk_khz is always zero, so the last statement *always* results in a divide-by-zero. So that looks like a bug in the code. However, I'm baffled by how gcc handles it. Instead of: a) reporting a compile-time warning/error; or b) letting the #DE (divide error) exception happen; it inserts a 'ud2', resulting in a #UD (invalid opcode). Why?!? -- Josh