From patchwork Thu Apr 28 01:32:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David Rivshin (Allworx)" X-Patchwork-Id: 8964991 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3C4B7BF29F for ; Thu, 28 Apr 2016 01:34:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2390E2027D for ; Thu, 28 Apr 2016 01:34:39 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2764D2026D for ; Thu, 28 Apr 2016 01:34:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1avapG-0003WL-2r; Thu, 28 Apr 2016 01:33:06 +0000 Received: from mail-qk0-x242.google.com ([2607:f8b0:400d:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1avapD-0003Sz-HX for linux-arm-kernel@lists.infradead.org; Thu, 28 Apr 2016 01:33:04 +0000 Received: by mail-qk0-x242.google.com with SMTP id b63so4616515qkg.2 for ; Wed, 27 Apr 2016 18:32:43 -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=QKp4EJZsJsI2UZjifxrHnTUS5pFNBvUwDBqagP8kWNI=; b=amJmofZTtbnA63MTMjZRYSrUJh6YLHM9lwouz8a3lLfSY4K1+CDO3lyfExRL2yXVcj tyxn2thCnZ44awQ0ZH6ambJS9a/Be1STPwTVp+ooEdIfdQLc3i7HwK5R+KAEGrxfDS32 wKoeFXdSTntAQvQjsB7x8XNFDbBWf3abncbBy+nr90X9Opt+FggSmLR+s1XXCS71BEbc iaIuR3dGx9t8ed8XPhIaV1qsXhm8i+pwax6iiDIfam2aI/00SZzQZAi2sguJBUz2Y46F ymp8PU9ep8XXPqvRomJtXcwlLtY9htZjtjDDcTbowdF3GsbLOUaz8uc3dgpiR2qK+/Z5 xh5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QKp4EJZsJsI2UZjifxrHnTUS5pFNBvUwDBqagP8kWNI=; b=BokkO+X9afotrN5cCcedpsMBKSqpogXctatoG9wh89cDgS2XHCf+JxfBgok8aJKq7+ 0UhOKdDqFPK/YFQsZy/hJEhahIYTLULqdnQEuVYDW8BOCAOdTW3PfResEgmMzlf9ptdM ZGCSWa40oGTCJQ4vFneCNLNpnoQfoyuUR5/OO3UzTh8Y18kbfVRJKNnfWTYUuzGAqi6g 8B43zROZmIPzf5uXIwTojL8ObzdCysBOEH/jeMrjdyj/4APNqpdhFAKtLwmvHszI0a1Y pg9WQCxPrimmgRphzdgyY5QSY4cYt1+9tYB6DuLEsUrfym4yrd/kXBBjsxH0vXUksglH vHsA== X-Gm-Message-State: AOPr4FUdUkqy+A2QBXkQypLVQ4eA0Y76sWEjBd2WXjTq46nOfWPD+bLDp2lJ99oElYZYfw== X-Received: by 10.55.71.146 with SMTP id u140mr12076865qka.14.1461807162372; Wed, 27 Apr 2016 18:32:42 -0700 (PDT) Received: from drivshin-linux.crosskeys.inscitek.com ([24.213.148.66]) by smtp.gmail.com with ESMTPSA id x202sm2110742qhx.30.2016.04.27.18.32.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Apr 2016 18:32:42 -0700 (PDT) From: "David Rivshin (Allworx)" To: netdev@vger.kernel.org, linux-omap@vger.kernel.org Subject: [PATCH net v3 2/5] drivers: net: cpsw: fix segfault in case of bad phy-handle Date: Wed, 27 Apr 2016 21:32:31 -0400 Message-Id: <1461807151-4416-1-git-send-email-drivshin.allworx@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1461805808-4102-1-git-send-email-drivshin.allworx@gmail.com> References: <1461805808-4102-1-git-send-email-drivshin.allworx@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160427_183303_661059_A12C6262 X-CRM114-Status: GOOD ( 16.11 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Brunner , devicetree@vger.kernel.org, Grygorii Strashko , Mugunthan V N , Nicolas Chauvet , linux-kernel@vger.kernel.org, Andrew Goodbody , David Miller , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: David Rivshin If an emac node has a phy-handle property that points to something which is not a phy, then a segmentation fault will occur when the interface is brought up. This is because while phy_connect() will return ERR_PTR() on failure, of_phy_connect() will return NULL. The common error check uses IS_ERR(), and so missed when of_phy_connect() fails. The NULL pointer is then dereferenced. Also, the common error message referenced slave->data->phy_id, which would be empty in the case of phy-handle. Instead, use the name of the device_node as a useful identifier. And in the phy_id case add the error code for completeness. Fixes: 9e42f715264f ("drivers: net: cpsw: add phy-handle parsing") Signed-off-by: David Rivshin --- I would suggest this for -stable. It should apply cleanly as far back as 4.5, although there is a trivial conflict in 4.4. I can produce a separate patch against linux-4.4.y if preferred. Changes since v2: - new patch, although fixing part of previous patch 2 [1] Changes since v1 [2]: - Rebased (no conflicts) - Added Tested-by from Nicolas Chauvet - Added Acked-by from Rob Herring for the binding change [1] http://patchwork.ozlabs.org/patch/613260/ [2] http://patchwork.ozlabs.org/patch/560324/ drivers/net/ethernet/ti/cpsw.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index ce0b0ca..5903448 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -1143,33 +1143,42 @@ static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv) if (priv->data.dual_emac) cpsw_add_dual_emac_def_ale_entries(priv, slave, slave_port); else cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast, 1 << slave_port, 0, 0, ALE_MCAST_FWD_2); - if (slave->data->phy_node) + if (slave->data->phy_node) { slave->phy = of_phy_connect(priv->ndev, slave->data->phy_node, &cpsw_adjust_link, 0, slave->data->phy_if); - else + if (!slave->phy) { + dev_err(priv->dev, "phy \"%s\" not found on slave %d\n", + slave->data->phy_node->full_name, + slave->slave_num); + return; + } + } else { slave->phy = phy_connect(priv->ndev, slave->data->phy_id, &cpsw_adjust_link, slave->data->phy_if); - if (IS_ERR(slave->phy)) { - dev_err(priv->dev, "phy %s not found on slave %d\n", - slave->data->phy_id, slave->slave_num); - slave->phy = NULL; - } else { - phy_attached_info(slave->phy); - - phy_start(slave->phy); - - /* Configure GMII_SEL register */ - cpsw_phy_sel(&priv->pdev->dev, slave->phy->interface, - slave->slave_num); + if (IS_ERR(slave->phy)) { + dev_err(priv->dev, + "phy \"%s\" not found on slave %d, err %ld\n", + slave->data->phy_id, slave->slave_num, + PTR_ERR(slave->phy)); + slave->phy = NULL; + return; + } } + + phy_attached_info(slave->phy); + + phy_start(slave->phy); + + /* Configure GMII_SEL register */ + cpsw_phy_sel(&priv->pdev->dev, slave->phy->interface, slave->slave_num); } static inline void cpsw_add_default_vlan(struct cpsw_priv *priv) { const int vlan = priv->data.default_vlan; const int port = priv->host_port; u32 reg;