diff options
author | Jonas Karlman <jonas@kwiboo.se> | 2023-08-31 22:16:35 +0000 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-09-13 15:52:20 -0400 |
commit | 14639bf14d824d9fbcfd918f0e7924c7f7065422 (patch) | |
tree | 846bd0c2783be0096a440ce61a29d0c0568c6360 /test | |
parent | feb4b919abf39f39faf660ef3d9aedebb54f5db5 (diff) | |
download | u-boot-14639bf14d824d9fbcfd918f0e7924c7f7065422.zip u-boot-14639bf14d824d9fbcfd918f0e7924c7f7065422.tar.gz u-boot-14639bf14d824d9fbcfd918f0e7924c7f7065422.tar.bz2 |
phy: Set phy->dev to NULL when generic_phy_get_by_index_nodev() fails
Generic phy helpers typically use generic_phy_valid() to determine if
the helper should perform its function on a passed struct phy.
generic_phy_valid() treat any struct phy having phy->dev set as valid.
With generic_phy_get_by_index_nodev() setting phy->dev to a valid struct
udevice early, there can be situations where the struct phy is returned
as valid when initialization in fact failed and returned an error.
Fix this by setting phy->dev back to NULL when any of the calls to
of_xlate ops, device_get_supply_regulator or phy_alloc_counts fail. Also
extend the dm_test_phy_base test with a test where of_xlate ops fail.
Fixes: 72e5016f878d ("drivers: phy: add generic PHY framework")
Fixes: b9688df3cbf4 ("drivers: phy: Set phy->dev to NULL when generic_phy_get_by_index() fails")
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
Diffstat (limited to 'test')
-rw-r--r-- | test/dm/phy.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/test/dm/phy.c b/test/dm/phy.c index 09329b9..2abd27b 100644 --- a/test/dm/phy.c +++ b/test/dm/phy.c @@ -49,7 +49,7 @@ static int dm_test_phy_base(struct unit_test_state *uts) ut_assert(phy2.dev != phy3.dev); /* Try to get a non-existing phy */ - ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PHY, 4, &dev)); + ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PHY, 5, &dev)); ut_asserteq(-ENODATA, generic_phy_get_by_name(parent, "phy_not_existing", &phy1_method1)); ut_assert(!generic_phy_valid(&phy1_method1)); @@ -57,6 +57,16 @@ static int dm_test_phy_base(struct unit_test_state *uts) &phy1_method2)); ut_assert(!generic_phy_valid(&phy1_method2)); + /* Try to get a phy where of_xlate fail */ + ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS, + "gen_phy_user2", &parent)); + ut_asserteq(-EINVAL, generic_phy_get_by_name(parent, "phy1", + &phy1_method1)); + ut_assert(!generic_phy_valid(&phy1_method1)); + ut_asserteq(-EINVAL, generic_phy_get_by_index(parent, 0, + &phy1_method2)); + ut_assert(!generic_phy_valid(&phy1_method2)); + return 0; } DM_TEST(dm_test_phy_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |