From patchwork Wed May 20 17:05:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Raghavendra, Vignesh" X-Patchwork-Id: 1294497 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.a=rsa-sha256 header.s=ti-com-17Q1 header.b=JSZgVNl0; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Rzfm2RT8z9sTC for ; Thu, 21 May 2020 03:06:08 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 46A1F81584; Wed, 20 May 2020 19:06:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="JSZgVNl0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6721781D08; Wed, 20 May 2020 19:05:59 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5D60C81547 for ; Wed, 20 May 2020 19:05:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=vigneshr@ti.com Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 04KH5pUX016832; Wed, 20 May 2020 12:05:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1589994351; bh=D+xdiD+xyIdQAEZbJoe8HTD3uWDVlN9ARmR5uyABe4o=; h=From:To:CC:Subject:Date; b=JSZgVNl04uSaEgN20C010qBsqjzQFvyXYqzT3zn0UvBhbz90gVVwFQtD+hlNNL0ri noSMneilI+Dv3bIwvIqIfz+46BJ1qERwO3AnfBFj4vKZHG+xr0Tm0b1LYcw8mwIHCW icLbtp34U8miqfEhq4YG3HVRCdyDAU+sYES42Aik= Received: from DFLE114.ent.ti.com (dfle114.ent.ti.com [10.64.6.35]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 04KH5p5C124339 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 20 May 2020 12:05:51 -0500 Received: from DFLE108.ent.ti.com (10.64.6.29) by DFLE114.ent.ti.com (10.64.6.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Wed, 20 May 2020 12:05:51 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Wed, 20 May 2020 12:05:51 -0500 Received: from a0132425.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 04KH5nD4089838; Wed, 20 May 2020 12:05:50 -0500 From: Vignesh Raghavendra To: Tom Rini CC: Subject: [PATCH] phy: Fix possible NULL pointer deference Date: Wed, 20 May 2020 22:35:41 +0530 Message-ID: <20200520170541.13312-1-vigneshr@ti.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean It is possible that users of generic_phy_*() APIs may pass a valid struct phy pointer but phy->dev can be NULL, leading to NULL pointer deference in phy_dev_ops(). So call generic_phy_valid() to verify that phy and phy->dev are both valid. Signed-off-by: Vignesh Raghavendra --- drivers/phy/phy-uclass.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c index 1fded5ebf42f..89510c5772e0 100644 --- a/drivers/phy/phy-uclass.c +++ b/drivers/phy/phy-uclass.c @@ -117,7 +117,7 @@ int generic_phy_init(struct phy *phy) { struct phy_ops const *ops; - if (!phy) + if (!generic_phy_valid(phy)) return 0; ops = phy_dev_ops(phy->dev); @@ -128,7 +128,7 @@ int generic_phy_reset(struct phy *phy) { struct phy_ops const *ops; - if (!phy) + if (!generic_phy_valid(phy)) return 0; ops = phy_dev_ops(phy->dev); @@ -139,7 +139,7 @@ int generic_phy_exit(struct phy *phy) { struct phy_ops const *ops; - if (!phy) + if (!generic_phy_valid(phy)) return 0; ops = phy_dev_ops(phy->dev); @@ -150,7 +150,7 @@ int generic_phy_power_on(struct phy *phy) { struct phy_ops const *ops; - if (!phy) + if (!generic_phy_valid(phy)) return 0; ops = phy_dev_ops(phy->dev); @@ -161,7 +161,7 @@ int generic_phy_power_off(struct phy *phy) { struct phy_ops const *ops; - if (!phy) + if (!generic_phy_valid(phy)) return 0; ops = phy_dev_ops(phy->dev);