mirror of
				https://source.denx.de/u-boot/u-boot.git
				synced 2025-11-04 10:21:25 +01:00 
			
		
		
		
	phy: Set phy->dev to NULL when generic_phy_get_by_name() fails
generic_phy_get_by_name() does not initialize phy->dev to NULL before
returning when dev_read_stringlist_search() fails. This can lead to an
uninitialized or reused struct phy erroneously be report as valid by
generic_phy_valid().
Fix this issue by initializing phy->dev to NULL, also extend the
dm_test_phy_base test with calls to generic_phy_valid().
Fixes: b9688df3cbf4 ("drivers: phy: Set phy->dev to NULL when generic_phy_get_by_index() fails")
Fixes: 868d58f69c7c ("usb: dwc3: Fix non-usb3 configurations")
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
			
			
This commit is contained in:
		
							parent
							
								
									cba79a1b2e
								
							
						
					
					
						commit
						feb4b919ab
					
				@ -211,6 +211,9 @@ int generic_phy_get_by_name(struct udevice *dev, const char *phy_name,
 | 
			
		||||
 | 
			
		||||
	debug("%s(dev=%p, name=%s, phy=%p)\n", __func__, dev, phy_name, phy);
 | 
			
		||||
 | 
			
		||||
	assert(phy);
 | 
			
		||||
	phy->dev = NULL;
 | 
			
		||||
 | 
			
		||||
	index = dev_read_stringlist_search(dev, "phy-names", phy_name);
 | 
			
		||||
	if (index < 0) {
 | 
			
		||||
		debug("dev_read_stringlist_search() failed: %d\n", index);
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,9 @@ static int dm_test_phy_base(struct unit_test_state *uts)
 | 
			
		||||
	 * Get the same phy port in 2 different ways and compare.
 | 
			
		||||
	 */
 | 
			
		||||
	ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1_method1));
 | 
			
		||||
	ut_assert(generic_phy_valid(&phy1_method1));
 | 
			
		||||
	ut_assertok(generic_phy_get_by_index(parent, 0, &phy1_method2));
 | 
			
		||||
	ut_assert(generic_phy_valid(&phy1_method2));
 | 
			
		||||
	ut_asserteq(phy1_method1.id, phy1_method2.id);
 | 
			
		||||
 | 
			
		||||
	/*
 | 
			
		||||
@ -50,6 +52,10 @@ static int dm_test_phy_base(struct unit_test_state *uts)
 | 
			
		||||
	ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PHY, 4, &dev));
 | 
			
		||||
	ut_asserteq(-ENODATA, generic_phy_get_by_name(parent,
 | 
			
		||||
					"phy_not_existing", &phy1_method1));
 | 
			
		||||
	ut_assert(!generic_phy_valid(&phy1_method1));
 | 
			
		||||
	ut_asserteq(-ENOENT, generic_phy_get_by_index(parent, 3,
 | 
			
		||||
						      &phy1_method2));
 | 
			
		||||
	ut_assert(!generic_phy_valid(&phy1_method2));
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user