From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751832AbdIWQ5k (ORCPT ); Sat, 23 Sep 2017 12:57:40 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:43349 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750916AbdIWQ5j (ORCPT ); Sat, 23 Sep 2017 12:57:39 -0400 From: Colin King To: Andrew Lunn , Vivien Didelot , Florian Fainelli , "David S . Miller" , netdev@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] net: dsa: avoid null pointer dereference on p->phy Date: Sat, 23 Sep 2017 17:57:20 +0100 Message-Id: <20170923165720.18560-1-colin.king@canonical.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King Currently p->phy is being null checked in several places to avoid null pointer dereferences on p->phy, however, the final call to phy_attached_info on p->phy when p->phy will perform a null pointer dereference. Fix this by simply moving the call into the previous code block that is only executed if p->phy is not null. Detected by CoverityScan, CID#1457034 ("Dereference after null check") Fixes: 2220943a21e2 ("phy: Centralise print about attached phy") Signed-off-by: Colin Ian King --- net/dsa/slave.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 02ace7d462c4..29ab4e98639b 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -1115,10 +1115,9 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev) of_phy_deregister_fixed_link(port_dn); return ret; } + phy_attached_info(p->phy); } - phy_attached_info(p->phy); - return 0; } -- 2.14.1