From patchwork Thu Sep 22 08:44:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 673219 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 3sfqmW1Gtfz9t1Y for ; Thu, 22 Sep 2016 18:44:27 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756447AbcIVIoY (ORCPT ); Thu, 22 Sep 2016 04:44:24 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:15606 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752591AbcIVIoW (ORCPT ); Thu, 22 Sep 2016 04:44:22 -0400 Received: from mtkhts09.mediatek.inc [(172.21.101.70)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1538205252; Thu, 22 Sep 2016 16:44:18 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkhts09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 14.3.266.1; Thu, 22 Sep 2016 16:40:56 +0800 From: To: , CC: , , , , , , Sean Wang Subject: [PATCH net-next] net: ethernet: mediatek: get out of potential invalid pointer access Date: Thu, 22 Sep 2016 16:44:16 +0800 Message-ID: <1474533856-22753-1-git-send-email-sean.wang@mediatek.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-MTK: N Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Sean Wang Potential dangerous invalid pointer might be accessed if the error happens when couple phy_device to net_device so cleanup the error path. Signed-off-by: Sean Wang --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index a65801a..3d7e0cb 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -296,7 +296,9 @@ static int mtk_phy_connect(struct net_device *dev) regmap_write(eth->ethsys, ETHSYS_SYSCFG0, val); /* couple phydev to net_device */ - mtk_phy_connect_node(eth, mac, np); + if (mtk_phy_connect_node(eth, mac, np)) + goto err_phy; + dev->phydev->autoneg = AUTONEG_ENABLE; dev->phydev->speed = 0; dev->phydev->duplex = 0; @@ -317,7 +319,7 @@ static int mtk_phy_connect(struct net_device *dev) err_phy: of_node_put(np); - dev_err(eth->dev, "invalid phy_mode\n"); + dev_err(eth->dev, "%s: invalid phy\n", __func__); return -EINVAL; }