diff mbox series

phy: Fix possible NULL pointer deference

Message ID 20200520170541.13312-1-vigneshr@ti.com
State Accepted
Commit 64b69f8c89352975c25730bcca4bf8af2296297f
Delegated to: Tom Rini
Headers show
Series phy: Fix possible NULL pointer deference | expand

Commit Message

Raghavendra, Vignesh May 20, 2020, 5:05 p.m. UTC
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 <vigneshr@ti.com>
---
 drivers/phy/phy-uclass.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Tom Rini May 25, 2020, 5:59 p.m. UTC | #1
On Wed, May 20, 2020 at 10:35:41PM +0530, Vignesh Raghavendra wrote:

> 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 <vigneshr@ti.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

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);