From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751846AbdIWRV3 (ORCPT ); Sat, 23 Sep 2017 13:21:29 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:33567 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750916AbdIWRV1 (ORCPT ); Sat, 23 Sep 2017 13:21:27 -0400 X-Google-Smtp-Source: AOwi7QBSi+wShEl0dNn/Yt/zaqo1ljkyTuG/mpXrWUoOm1IKsgutC6MXtI3zL9SBjIECGc6xD0iHsg== Subject: Re: [PATCH] net: dsa: avoid null pointer dereference on p->phy To: Colin King , Andrew Lunn , Vivien Didelot , "David S . Miller" , netdev@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org References: <20170923165720.18560-1-colin.king@canonical.com> From: Florian Fainelli Message-ID: <4c92bb5f-ad5e-7f3e-cad8-b13bb69b79ff@gmail.com> Date: Sat, 23 Sep 2017 10:21:24 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20170923165720.18560-1-colin.king@canonical.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/23/2017 09:57 AM, Colin King wrote: > 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") The code flow is not exactly easy to read, but I don't see how we can actually wind up in that situation because we check the return values of of_phy_connect() and dsa_slave_phy_connect() earlier on. > > 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; > } > > -- Florian