From 37a5e4d859e8e69bace4eaddacad8d3cc30c8287 Mon Sep 17 00:00:00 2001 From: Vignesh Raghavendra Date: Wed, 20 May 2020 22:35:41 +0530 Subject: [PATCH] UPSTREAM: phy: Fix possible NULL pointer deference 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. Change-Id: I0d19180ae8524eb240f4afd6ea55d5d0f2907798 Signed-off-by: Vignesh Raghavendra Signed-off-by: Wyon Bi (cherry picked from commit 64b69f8c89352975c25730bcca4bf8af2296297f) --- 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 671365389f..a29298be5b 100644 --- a/drivers/phy/phy-uclass.c +++ b/drivers/phy/phy-uclass.c @@ -100,7 +100,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); @@ -111,7 +111,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); @@ -122,7 +122,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); @@ -133,7 +133,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); @@ -144,7 +144,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);