From patchwork Sat Jan 7 08:10:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kweh Hock Leong X-Patchwork-Id: 712213 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 3twMD94k75z9sCX for ; Sat, 7 Jan 2017 11:07:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034712AbdAGAGe (ORCPT ); Fri, 6 Jan 2017 19:06:34 -0500 Received: from mga07.intel.com ([134.134.136.100]:47540 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755219AbdAGAFq (ORCPT ); Fri, 6 Jan 2017 19:05:46 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP; 06 Jan 2017 16:05:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,326,1477983600"; d="scan'208";a="919782655" Received: from kweh-desk1.png.intel.com ([172.30.66.18]) by orsmga003.jf.intel.com with ESMTP; 06 Jan 2017 16:05:42 -0800 From: "Kweh, Hock Leong" To: "David S. Miller" , Joao Pinto , Giuseppe CAVALLARO , seraphin.bonnaffe@st.com, Jarod Wilson , Andy Shevchenko Cc: Alexandre TORGUE , Joachim Eastwood , Niklas Cassel , Johan Hovold , pavel@ucw.cz, "Kweh, Hock Leong" , lars.persson@axis.com, netdev , LKML Subject: [PATCH v4] net: stmmac: fix maxmtu assignment to be within valid range Date: Sat, 7 Jan 2017 16:10:34 +0800 Message-Id: <1483776634-13095-1-git-send-email-hock.leong.kweh@intel.com> X-Mailer: git-send-email 1.7.9.5 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: "Kweh, Hock Leong" There is no checking valid value of maxmtu when getting it from device tree. This resolution added the checking condition to ensure the assignment is made within a valid range. Signed-off-by: Kweh, Hock Leong --- changelog v4: * add print warning message when maxmtu > max_mtu as well * add maxmtu = JUMBO_LEN into each *_default_data() at stmmac_pci.c changelog v3: * print the warning message only if maxmtu < min_mtu * add maxmtu = JUMBO_LEN at stmmac_pci.c to follow stmmac_platform.c changelog v2: * correction of "devicetree" to "device tree" reported by Andy * print warning message while maxmtu is not in valid range drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 +++++++- drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 92ac006..f2a352f 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3345,8 +3345,14 @@ int stmmac_dvr_probe(struct device *device, ndev->max_mtu = JUMBO_LEN; else ndev->max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN); - if (priv->plat->maxmtu < ndev->max_mtu) + if ((priv->plat->maxmtu < ndev->max_mtu) && + (priv->plat->maxmtu >= ndev->min_mtu)) ndev->max_mtu = priv->plat->maxmtu; + else if ((priv->plat->maxmtu < ndev->min_mtu) || + (priv->plat->maxmtu > ndev->max_mtu)) + netdev_warn(priv->dev, + "%s: warning: maxmtu having invalid value (%d)\n", + __func__, priv->plat->maxmtu); if (flow_ctrl) priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */ diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c index a283177..3da4737 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c @@ -89,6 +89,9 @@ static void stmmac_default_data(struct plat_stmmacenet_data *plat) /* Set default value for unicast filter entries */ plat->unicast_filter_entries = 1; + + /* Set the maxmtu to a default of JUMBO_LEN */ + plat->maxmtu = JUMBO_LEN; } static int quark_default_data(struct plat_stmmacenet_data *plat, @@ -126,6 +129,9 @@ static int quark_default_data(struct plat_stmmacenet_data *plat, /* Set default value for unicast filter entries */ plat->unicast_filter_entries = 1; + /* Set the maxmtu to a default of JUMBO_LEN */ + plat->maxmtu = JUMBO_LEN; + return 0; }