mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-28 15:41:40 +00:00
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:72e5016f87
("drivers: phy: add generic PHY framework") Fixes:b9688df3cb
("drivers: phy: Set phy->dev to NULL when generic_phy_get_by_index() fails") Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
This commit is contained in:
parent
feb4b919ab
commit
14639bf14d
3 changed files with 23 additions and 1 deletions
|
@ -433,6 +433,11 @@
|
||||||
#phy-cells = <0>;
|
#phy-cells = <0>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
phy_provider3: gen_phy@3 {
|
||||||
|
compatible = "sandbox,phy";
|
||||||
|
#phy-cells = <2>;
|
||||||
|
};
|
||||||
|
|
||||||
gen_phy_user: gen_phy_user {
|
gen_phy_user: gen_phy_user {
|
||||||
compatible = "simple-bus";
|
compatible = "simple-bus";
|
||||||
phys = <&phy_provider0 0>, <&phy_provider0 1>, <&phy_provider1>;
|
phys = <&phy_provider0 0>, <&phy_provider0 1>, <&phy_provider1>;
|
||||||
|
@ -445,6 +450,12 @@
|
||||||
phy-names = "phy1", "phy2";
|
phy-names = "phy1", "phy2";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
gen_phy_user2: gen_phy_user2 {
|
||||||
|
compatible = "simple-bus";
|
||||||
|
phys = <&phy_provider3 0 0>;
|
||||||
|
phy-names = "phy1";
|
||||||
|
};
|
||||||
|
|
||||||
some-bus {
|
some-bus {
|
||||||
#address-cells = <1>;
|
#address-cells = <1>;
|
||||||
#size-cells = <0>;
|
#size-cells = <0>;
|
||||||
|
|
|
@ -195,6 +195,7 @@ int generic_phy_get_by_index_nodev(ofnode node, int index, struct phy *phy)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
|
phy->dev = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ static int dm_test_phy_base(struct unit_test_state *uts)
|
||||||
ut_assert(phy2.dev != phy3.dev);
|
ut_assert(phy2.dev != phy3.dev);
|
||||||
|
|
||||||
/* Try to get a non-existing phy */
|
/* 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,
|
ut_asserteq(-ENODATA, generic_phy_get_by_name(parent,
|
||||||
"phy_not_existing", &phy1_method1));
|
"phy_not_existing", &phy1_method1));
|
||||||
ut_assert(!generic_phy_valid(&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));
|
&phy1_method2));
|
||||||
ut_assert(!generic_phy_valid(&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;
|
return 0;
|
||||||
}
|
}
|
||||||
DM_TEST(dm_test_phy_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
DM_TEST(dm_test_phy_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
||||||
|
|
Loading…
Reference in a new issue