Linux Kernel设备驱动模型之 总线查找驱动

设备模型之总线查找驱动:

/**  * bus_for_each_drv - driver iterator  * @bus: bus we're dealing with.  * @start: driver to start iterating on.  * @data: data to pass to the callback.  * @fn: function to call for each driver.  *  * This is nearly identical to the device iterator above.  * We iterate over each driver that belongs to @bus, and call  * @fn for each. If @fn returns anything but 0, we break out  * and return it. If @start is not NULL, we use it as the head  * of the list.  *  * NOTE: we don't return the driver that returns a non-zero  * value, nor do we leave the reference count incremented for that  * driver. If the caller needs to know that info, it must set it  * in the callback. It must also be sure to increment the refcount  * so it doesn't disappear before returning to the caller.  */ int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,        void *data, int (*fn)(struct device_driver *, void *)) {  struct klist_iter i;  struct device_driver *drv;  int error = 0;

 if (!bus)   return -EINVAL;

 klist_iter_init_node(&bus->p->klist_drivers, &i,         start ? &start->p->knode_bus : NULL);  while ((drv = next_driver(&i)) && !error)   error = fn(drv, data);  klist_iter_exit(&i);  return error; }

 

static struct device_driver *next_driver(struct klist_iter *i) {  struct klist_node *n = klist_next(i);  struct driver_private *drv_priv;

 if (n) {   drv_priv = container_of(n, struct driver_private, knode_bus);   return drv_priv->driver;  }  return NULL; }

 

 
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值