From mboxrd@z Thu Jan 1 00:00:00 1970 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.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 BDC02C433FF for ; Fri, 2 Aug 2019 10:03:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8DDAE20665 for ; Fri, 2 Aug 2019 10:03:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564740233; bh=rdBbQIUYNfkRm8ZkQ0N6taQuyISkbv8YCK+SvbUbs/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=bRcCKPdgp8o2o42wjMRSScHdPcVBUbY9NRPmpcI+fJFJeD8F5fHFQVBKsEfCYpZmR 57YIDajv+XL5w43an6RvbwoGPHvKnuk7EP9yONF9SmET56NqTlOE+VG5dHmVk+0TSJ lZ4CRpopCqHfH57lcgvyaH+m6v61oS5KxBcm0eM0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390128AbfHBJlA (ORCPT ); Fri, 2 Aug 2019 05:41:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:42210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391178AbfHBJk5 (ORCPT ); Fri, 2 Aug 2019 05:40:57 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C0C2520679; Fri, 2 Aug 2019 09:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564738856; bh=rdBbQIUYNfkRm8ZkQ0N6taQuyISkbv8YCK+SvbUbs/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M0f+DXTjI65No5b4j5lFBjRX4S4l04qO9ELLUGM1PETJ6Wm1C1q8AiyIiiH4Z0moa ww5Pjj2CNdFHkzmxNxFIo1h4QONPaKoef1lYwlb7uMlCuKxw+abNppdJx/H+jCUjt8 gBgrOaRw5ot2fB29Rrv70tr7YBtdYu8+sKhj80cM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ioana Ciornei , Andrew Lunn , Florian Fainelli , "David S. Miller" , Sasha Levin Subject: [PATCH 4.9 022/223] net: phy: Check against net_device being NULL Date: Fri, 2 Aug 2019 11:34:07 +0200 Message-Id: <20190802092240.481519565@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802092238.692035242@linuxfoundation.org> References: <20190802092238.692035242@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [ Upstream commit 82c76aca81187b3d28a6fb3062f6916450ce955e ] In general, we don't want MAC drivers calling phy_attach_direct with the net_device being NULL. Add checks against this in all the functions calling it: phy_attach() and phy_connect_direct(). Signed-off-by: Ioana Ciornei Suggested-by: Andrew Lunn Reviewed-by: Andrew Lunn Reviewed-by: Florian Fainelli Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/phy/phy_device.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 5048a6df6a8e..5c2c72b1ef8b 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -673,6 +673,9 @@ int phy_connect_direct(struct net_device *dev, struct phy_device *phydev, { int rc; + if (!dev) + return -EINVAL; + rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface); if (rc) return rc; @@ -965,6 +968,9 @@ struct phy_device *phy_attach(struct net_device *dev, const char *bus_id, struct device *d; int rc; + if (!dev) + return ERR_PTR(-EINVAL); + /* Search the list of PHY devices on the mdio bus for the * PHY with the requested name */ -- 2.20.1