From patchwork Fri Apr 3 11:28:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuanhong Guo X-Patchwork-Id: 228206 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4B08C2D0E8 for ; Fri, 3 Apr 2020 11:30:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7410F2137B for ; Fri, 3 Apr 2020 11:30:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iegDoB1I" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390800AbgDCL34 (ORCPT ); Fri, 3 Apr 2020 07:29:56 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:34302 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390783AbgDCL3q (ORCPT ); Fri, 3 Apr 2020 07:29:46 -0400 Received: by mail-pl1-f195.google.com with SMTP id a23so2607480plm.1; Fri, 03 Apr 2020 04:29:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8rXpdWw7x9PpBvoBR/qm/XcVJsNWHJ1tSvQ9UIVcPLA=; b=iegDoB1IxCA4quOPEOuEst/h/o+3lRJuFDKhH/u9bys+FKqKdgPy8zwo7dxJoU2DwR OqDJQKEkNLhlMWWPZ065eDbOe6Eo4ZD2JqnLMoX4sksEkxM3ZDYy5kzvKC2zOoRSXSix t4aCJWtpQqSvrC2solgN22MI9dJUgkfeMjY9mCzCjV3+JrCclicKu8HBvSumuae23O0f YKuek9MktR7z3Pa6J8hUkwLCmerbyvtBYv3ux2yPUeMxkyXQt8qVyoEDBorLtSBfEd5K OyxNXrHVYivJX0Up0fRhONeNVQ+BFkAj2kkYUT2zWAdglRTaY2wwTkrVVQKGMJYZypuJ v5YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8rXpdWw7x9PpBvoBR/qm/XcVJsNWHJ1tSvQ9UIVcPLA=; b=kXlRLJUqIFfWAFPsfiwYuGzh5x1N3JZ3KQW7qFLWFkLE5Ai/l6mMccFhnZajqXiFA6 tCzhjuIEwJ497mwwRbceZpwRDh8m5MDz98GmBwuZlrYN95D52ZYPC67Sof55lVOw0VJ9 my6XkabdGL1fNS64ztn05A8WiNzqRboQhB+dKVbX5ASzx2DVZVCHnqB2n7YS+UnsF8OH 4ZGt7in73vy4qsVRh1bOwwFx2ZPI2GMmz9VetkPxWOC2mjJuWIAlcub4KpmdHU5uKuz5 BYEva4Y59ye/BynE+GGJuGYCy6ZwmhTZDXHcanI+sValOygyUbcmIC+T9TIZDput3UHb Mr1Q== X-Gm-Message-State: AGi0PuaRyRoZjx880J91xAQaoPPKbY3MZLDFEjJlw1hgc6K1KOUKUSDL Ou93nUOCClTk1kyiBVV/l8p1Uyp0gw8= X-Google-Smtp-Source: APiQypJ73aRw0jbyNSgssLXyjPahMN2KTO/im/OozAk2AXrhtWeGe0HEMNdi7dRewEFL4MTJbkL6Mg== X-Received: by 2002:a17:90a:37ea:: with SMTP id v97mr9591002pjb.26.1585913384901; Fri, 03 Apr 2020 04:29:44 -0700 (PDT) Received: from guoguo-omen.lan ([240e:379:95c:7214:abe6:11ff:840d:b9a7]) by smtp.gmail.com with ESMTPSA id g18sm5034114pgh.42.2020.04.03.04.29.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 04:29:44 -0700 (PDT) From: Chuanhong Guo To: netdev@vger.kernel.org Cc: Chuanhong Guo , stable@vger.kernel.org, Sean Wang , Andrew Lunn , Vivien Didelot , Florian Fainelli , "David S. Miller" , Matthias Brugger , =?utf-8?q?Ren=C3=A9_van_Dor?= =?utf-8?q?st?= , Russell King , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] net: dsa: mt7530: fix null pointer dereferencing in port5 setup Date: Fri, 3 Apr 2020 19:28:24 +0800 Message-Id: <20200403112830.505720-1-gch981213@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The 2nd gmac of mediatek soc ethernet may not be connected to a PHY and a phy-handle isn't always available. Unfortunately, mt7530 dsa driver assumes that the 2nd gmac is always connected to switch port 5 and setup mt7530 according to phy address of 2nd gmac node, causing null pointer dereferencing when phy-handle isn't defined in dts. This commit fix this setup code by checking return value of of_parse_phandle before using it. Fixes: 38f790a80560 ("net: dsa: mt7530: Add support for port 5") Signed-off-by: Chuanhong Guo Cc: stable@vger.kernel.org --- mt7530 is available as a standalone chip and we should not make it tightly coupled with a specific type of ethernet dt binding in the first place. A proper fix is to replace this port detection logic with a dt property under mt7530 node, but that's too much for linux-stable. drivers/net/dsa/mt7530.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 6e91fe2f4b9a..1d53a4ebcd5a 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -1414,6 +1414,9 @@ mt7530_setup(struct dsa_switch *ds) continue; phy_node = of_parse_phandle(mac_np, "phy-handle", 0); + if (!phy_node) + continue; + if (phy_node->parent == priv->dev->of_node->parent) { ret = of_get_phy_mode(mac_np, &interface); if (ret && ret != -ENODEV)