Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753079AbbFHN0S (ORCPT ); Mon, 8 Jun 2015 09:26:18 -0400 Received: from www.linutronix.de ([62.245.132.108]:41721 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752630AbbFHN0K (ORCPT ); Mon, 8 Jun 2015 09:26:10 -0400 Date: Mon, 8 Jun 2015 15:26:12 +0200 (CEST) From: Thomas Gleixner To: David Binderman cc: "jason@lakedaemon.net" , "linux-kernel@vger.kernel.org" Subject: RE: linux-4.1-rc7/drivers/irqchip/irq-renesas-intc-irqpin.c:418: array index used before limits check ? In-Reply-To: Message-ID: References: , User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1262 Lines: 40 On Mon, 8 Jun 2015, David Binderman wrote: > ---------------------------------------- > >> [linux-4.1-rc7/drivers/irqchip/irq-renesas-intc-irqpin.c:418]: (style) Array ind > >> ex 'k' is used before limits check. > >> > >> if (!io[k] && k < INTC_IRQPIN_REG_NR_MANDATORY) { > >> > >> Suggest sanity check array index before use. > > > > Which version of gcc is being stupid here? > > None of them. > > The original "(style)" message is from a static analysis tool called cppcheck. > > I can't think of a situation where, if an array index needs checking, then > it should be checked *after* use. It does not check the array index. Read the complete code: for (k = 0; k < INTC_IRQPIN_REG_NR; k++) { io[k] = platform_get_resource(pdev, IORESOURCE_MEM, k); if (!io[k] && k < INTC_IRQPIN_REG_NR_MANDATORY) { The array bound is INTC_IRQPIN_REG_NR and the check about which that tool complains has nothing to do with array bounds. Completely valid code. Thanks, tglx -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/