Skip to contentSkip to conversation

phy: Fix possible NULL pointer deference

PATCH New Vignesh Raghavendra 2 participants 2 messages May 20, 2020 – May 25, 2020 Generic PHY framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 drivers/phy/phy-uclass.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/phy/phy-uclass.c +5 -5
index 1fded5ebf42f..89510c5772e0 100644
@@ -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);
 
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/1 phy: Fix possible NULL pointer deference

Quoted 8 lines · Vignesh Raghavendra

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.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200525/2d973be0/attachment.sig>