驱动程序通常使用 dev_set_drvdata() 存储指向其状态的指针。当驱动程序成功地将自己绑定到该设备时,probe() 将返回零,并且驱动程序模型代码将完成其将驱动程序绑定到该设备的部分。 驱动程序的 probe() 可能会返回一个负的 errno 值,表示驱动程序没有绑定到这个设备,在这种情况下,它应该释放它分配的所有资源。
dev->class= led_class;//关联设备类dev->parent =NULL; dev->devt = devno;//关联设备号dev_set_drvdata(dev, NULL); dev_set_name(dev,"led");//设置节点名字dev->release =device_create_release; ret=device_register(dev);if(ret)gotoout_put_dev;return0; out_put_dev: put_device(dev); ...
device_lock(dev->parent); device_lock(dev); if (dev->driver == drv) __device_release_driver(dev); device_unlock(dev); if (dev->parent) device_unlock(dev->parent); put_device(dev); } } 接下来分析__device_release_driver函数 static void __device_release_driver(struct device *dev) ...
static inline unsigned int dev_set_drvdata(struct device *dev, void *data) { dev->driver_data = data;; } 这下我们就明白,我们是把dev的设备信息保存到了interface->dev->driver_data中。在以后使用的时候,只需要调用usb_get_intfdata就可以得到dev的信息。 59-67:我们向这个interface注册一个skel_cl...
/* /drivers/base/dd.c */intdev_set_drvdata(struct device*dev,void*data){int error;if(!dev->p){error=device_private_init(dev);if(error)returnerror;}dev->p->driver_data=data;return0;} /* /linux/device.h */struct device{struct device*parent;struct device_private*p;struct kobject ko...
在注册的 Nand Flash 驱动程序中, probe 方法为 s3c2410_nand_probe(). s3c2410_nand_probe()再调用 s3c24xx_nand_probe(). 在该函数中, 把*info 作为 Nand Flash 驱动的私有数据结构, 并通过 dev_set_drvdata(dev, info)把*info 保存在*device 的*driver_data 字段中.然后通过 clk_get(dev, "nand"...
struct hello_android_dev* hdev = (struct hello_android_dev*)dev_get_drvdata(dev); printk(KERN_ALERT"hello_val_store.buf: %s count:%d\n",buf,(int)count); return __hello_set_val(hdev, buf, count+1); } static int __hello_setup_dev(struct hello_android_dev* dev) { ...
int (*match)(struct device *dev, struct device_driver *drv),用于判断挂在该 bus 上的设备和驱动是否匹配的回调函数; int (*probe)(struct device *dev),如果 bus 具有探测设备的能力,则会提供该回调函数; struct subsys_private *p,用于管理 bus 上的设备和驱动的数据结构; ...
struct device *dev, char *bus_name) { struct usb_hcd *hcd; hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL); if (!hcd) { dev_dbg (dev, "hcd alloc failed\n"); return NULL; } dev_set_drvdata(dev, hcd); ...