在四处寻找一种方法来检索指向 mii_bus 对象的设备指针后,我最终想出了以下解决方案。我不确定这是最好的方法,但它看起来很干净。我基本上最终向 mdio_bus.c 添加了一个辅助函数,它允许另一个驱动程序使用 class_find_device() 按名称搜索总线。我确信有更好的方法可以做到这一点,这不涉及添加到公共汽车的驱动程序,但这似乎也不是最糟糕的方法。
-布赖恩
以下是我添加到 mdio_bus.c 中的函数:
/**
* mdiobus_match_name - compares specified string to the device name
* @dev: device object to be examined
* @data: pointer to string to compare device name to
*
* Description: matching function used in call to class_find_device() to find
* a device with the specified name
*/
static int mdiobus_match_name( struct device * dev, void * data )
{
const char * name = data;
return sysfs_streq( name, dev_name( dev ) );
}
/**
* mdiobus_find_by_name - Convenience function for retrieving an mii_bus pointer
* by name
* @name: name of the bus being searched for
*/
struct mii_bus * mdiobus_find_by_name( char * name )
{
struct device * dev;
/* search devices registered for with the mdio_bus_class using the device
name as the matching criteria */
dev = class_find_device( &mdio_bus_class,
NULL,
(void *)name,
mdiobus_match_name );
/* return the mii_bus pointer or NULL if none was found */
return dev ? container_of( dev, struct mii_bus, dev ) : NULL;
}
EXPORT_SYMBOL( mdiobus_find_by_name );