From patchwork Wed Mar 5 00:35:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 326550 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 2E0B02C01A7 for ; Wed, 5 Mar 2014 11:36:09 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757447AbaCEAfu (ORCPT ); Tue, 4 Mar 2014 19:35:50 -0500 Received: from mail-ig0-f170.google.com ([209.85.213.170]:57588 "EHLO mail-ig0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757111AbaCEAfr (ORCPT ); Tue, 4 Mar 2014 19:35:47 -0500 Received: by mail-ig0-f170.google.com with SMTP id uq10so6263571igb.1 for ; Tue, 04 Mar 2014 16:35:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:to:from:cc:date:message-id:user-agent:mime-version :content-type:content-transfer-encoding; bh=pR+Fc3yF9Cx2FkukQ2MlJZ+CV2TI3cZTXOWvHcwFn78=; b=MPP7m50Q0BNh3MhbbE0M+WjDotPiPloT/SfbQzqMkL/9iW4PqQDwZoJqHn4hPlkY8s AeDU7FRqozsePmvd1ZA/a+FgzYjKpi/ZBnrIHPzF8cUvsIXLxZlQvMioVOKYAfrZbwNT 9pSXpVcqJIA+rR+Fjj4qudP3Wb792kGRhGBFVUnogHNx7wQn8CFZdj0Ud7KCjGG8ic0L ZKfBfumZ0zPYtJTC+0sJhmyzHItoHe/lqNIOPZ5Bus/ArDS2qkh8+r/Gbco8Z+3tgQCD 5574ZoQXUM/QST4Qhr3V6M44NzRy2zqlLRaQlL9Ky5NYx+4hKXBvcXkc+uoUUZtzvzzx Snpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:from:cc:date:message-id:user-agent :mime-version:content-type:content-transfer-encoding; bh=pR+Fc3yF9Cx2FkukQ2MlJZ+CV2TI3cZTXOWvHcwFn78=; b=KC3/h+61RL9F3nQnam6IAN7fS++AHSJ05vlIyR0d9Sp5m1IXi0hVRVdUB8AQejSgdY AzKCOeUMfZddXxQB0IqEvUq/cRFtNZx08JtriUVCn14eTCINQTyeWAUr4fKX0hNSztdK PFPKbHpdckMxFdbW5BSlK4jLSMk3iHq6KFtDWcqEslVASCP/LN0TGOK57mQVc+SU1CAs j2+aHoJ6zDEuX5zU3PyCZepEecaw4B/Yj/h8Z67Quy2qdW5bEGRmh/9iIxaYl3TxqONb ghUG76avP+I9oi/qRMS0+e4Mz4K6DoUYeHmPHD9OJ0lL2xlJ5sJCiMbJWwmQ6WginA0a 9W/Q== X-Gm-Message-State: ALoCoQknV9584LN5oC5ry9g8wmI/ZsPtvUnqFxF9mDCDUbtBSse9Da7JFfiYr0VTg5BrVKgRJ79ORKRgVYuzL7etBnAEz5Q+Ya7XwwprqLLjkT/WGVD4D4iuihSHwoqk8FOQV2JfJNJ62h04YX8pivNomwC42SXYNPEkqzPzO5Vnz/It6r7t5YP6Tm/xAEP8HEoqXFXV7g2Omb7U7FppqS6es6bwGaO1Z+8bad2hOUirXX+vjDM/Fe8= X-Received: by 10.50.138.72 with SMTP id qo8mr6366798igb.11.1393979746224; Tue, 04 Mar 2014 16:35:46 -0800 (PST) Received: from localhost ([172.16.49.180]) by mx.google.com with ESMTPSA id r6sm55152519igg.10.2014.03.04.16.35.45 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 04 Mar 2014 16:35:45 -0800 (PST) Subject: [PATCH] phy: fix compiler array bounds warning on settings[] To: netdev@vger.kernel.org From: Bjorn Helgaas Cc: linux-kernel@vger.kernel.org Date: Tue, 04 Mar 2014 17:35:44 -0700 Message-ID: <20140305003544.23016.55079.stgit@bhelgaas-glaptop.roam.corp.google.com> User-Agent: StGit/0.16 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org With -Werror=array-bounds, gcc v4.7.x warns that in phy_find_valid(), the settings[] "array subscript is above array bounds", I think because idx is a signed integer and if the caller supplied idx < 0, we pass the guard but still reference out of bounds. Fix this by making idx unsigned here and elsewhere. Signed-off-by: Bjorn Helgaas Acked-by: Florian Fainelli --- drivers/net/phy/phy.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 19c9eca0ef26..76d96b9ebcdb 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -164,9 +164,9 @@ static const struct phy_setting settings[] = { * of that setting. Returns the index of the last setting if * none of the others match. */ -static inline int phy_find_setting(int speed, int duplex) +static inline unsigned int phy_find_setting(int speed, int duplex) { - int idx = 0; + unsigned int idx = 0; while (idx < ARRAY_SIZE(settings) && (settings[idx].speed != speed || settings[idx].duplex != duplex)) @@ -185,7 +185,7 @@ static inline int phy_find_setting(int speed, int duplex) * the mask in features. Returns the index of the last setting * if nothing else matches. */ -static inline int phy_find_valid(int idx, u32 features) +static inline unsigned int phy_find_valid(unsigned int idx, u32 features) { while (idx < MAX_NUM_SETTINGS && !(settings[idx].setting & features)) idx++; @@ -204,7 +204,7 @@ static inline int phy_find_valid(int idx, u32 features) static void phy_sanitize_settings(struct phy_device *phydev) { u32 features = phydev->supported; - int idx; + unsigned int idx; /* Sanitize settings based on PHY capabilities */ if ((features & SUPPORTED_Autoneg) == 0) @@ -954,7 +954,8 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable) (phydev->interface == PHY_INTERFACE_MODE_RGMII))) { int eee_lp, eee_cap, eee_adv; u32 lp, cap, adv; - int idx, status; + int status; + unsigned int idx; /* Read phy status to properly get the right settings */ status = phy_read_status(phydev);