From patchwork Sun Jul 12 01:02:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 494058 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 1B76A1402BB for ; Sun, 12 Jul 2015 11:02:29 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=qOQp7Gm9; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751968AbbGLBCU (ORCPT ); Sat, 11 Jul 2015 21:02:20 -0400 Received: from mail-oi0-f42.google.com ([209.85.218.42]:36837 "EHLO mail-oi0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750935AbbGLBCS (ORCPT ); Sat, 11 Jul 2015 21:02:18 -0400 Received: by oibn4 with SMTP id n4so3028536oib.3 for ; Sat, 11 Jul 2015 18:02:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/5X9FQsedAuNQ5jBOAFpdVhNZ+5c9OWLn3Um29vSGbo=; b=qOQp7Gm90cLDo75QKK1ekoOQewE8w1WS80MgwHxttolDDmxi6rzEirmJZ0OLrx0gow zt5G/xz44xV5FLAV6BeDlqRAZ+3ZIS93DfDC0xmzerK2IXvORW7Y71VO9ROeKyabruKb 786mQJabFLMt+1YmMLQIcKhrSi/fwgJR6aRyt1GbawqlavWf52k+tfsgIwNwtrlfZXE6 w560eQmZW7jblBfCn0EkX43avcrExGa6HwQBVfR+8HMQalLMDb3ajN7ZurN3+IlgWpey GZJf3xYfV7F2Sw+h6aKmu6D4SayxMzWyWMtZzCYzuapHkjtrh3DZyhI9ekkOBvo2WbZE WpNQ== X-Received: by 10.60.69.7 with SMTP id a7mr13114286oeu.14.1436662938216; Sat, 11 Jul 2015 18:02:18 -0700 (PDT) Received: from bender.lan (ip68-96-94-194.oc.oc.cox.net. [68.96.94.194]) by smtp.gmail.com with ESMTPSA id xp8sm7640761obc.10.2015.07.11.18.02.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 11 Jul 2015 18:02:17 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: davem@davemloft.net, andrew@lunn.ch, linux@roeck-us.net, dan.carpenter@oracle.com, Florian Fainelli Subject: [PATCH net 1/2] net: dsa: Test array index before use Date: Sat, 11 Jul 2015 18:02:10 -0700 Message-Id: <1436662931-8982-2-git-send-email-f.fainelli@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1436662931-8982-1-git-send-email-f.fainelli@gmail.com> References: <1436662931-8982-1-git-send-email-f.fainelli@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org port_index is used an index into an array, and this information comes from Device Tree, make sure that port_index is not equal to the array size before using it. Move the check against port_index earlier in the loop. Fixes: 5e95329b701c: ("dsa: add device tree bindings to register DSA switches") Reported-by: Dan Carpenter Signed-off-by: Florian Fainelli --- net/dsa/dsa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 392e29a0227d..52beeb8829dc 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -642,6 +642,8 @@ static int dsa_of_probe(struct device *dev) continue; port_index = be32_to_cpup(port_reg); + if (port_index >= DSA_MAX_PORTS) + break; port_name = of_get_property(port, "label", NULL); if (!port_name) @@ -666,8 +668,6 @@ static int dsa_of_probe(struct device *dev) goto out_free_chip; } - if (port_index == DSA_MAX_PORTS) - break; } }