From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754521AbbHEVuw (ORCPT ); Wed, 5 Aug 2015 17:50:52 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:38856 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754487AbbHEVut (ORCPT ); Wed, 5 Aug 2015 17:50:49 -0400 From: Kamal Mostafa To: linux-kernel@vger.kernel.org, stable@vger.kernel.org, kernel-team@lists.ubuntu.com Cc: Florian Fainelli , "David S. Miller" , Kamal Mostafa Subject: [PATCH 3.19.y-ckt 106/107] net: dsa: Test array index before use Date: Wed, 5 Aug 2015 14:49:38 -0700 Message-Id: <1438811379-384-107-git-send-email-kamal@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1438811379-384-1-git-send-email-kamal@canonical.com> References: <1438811379-384-1-git-send-email-kamal@canonical.com> X-Extended-Stable: 3.19 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.19.8-ckt5 -stable review patch. If anyone has any objections, please let me know. ------------------ From: Florian Fainelli commit 8f5063e97f393d49611151d3cf7dcbeb41397f12 upstream. 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 Signed-off-by: David S. Miller Signed-off-by: Kamal Mostafa --- 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 ed1bcee..43bc5c7 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -639,6 +639,8 @@ static int dsa_of_probe(struct platform_device *pdev) 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) @@ -663,8 +665,6 @@ static int dsa_of_probe(struct platform_device *pdev) goto out_free_chip; } - if (port_index == DSA_MAX_PORTS) - break; } } -- 1.9.1