以下是转载自
网友ying_seven的博客(看到其也是转载的,但是并没有注明来处)
--------------------------------------------------------------------------------------------------------------------------
按照国嵌的代码(LDD那本书上的代码也一样):
struct device my_bus = {
.bus_id = "my_bus0",
.release = my_bus_release,
};
static int my_match(struct device *dev, struct device_driver *driver)
{
return !strncmp(dev->bus_id, driver->name, strlen(driver->name));
}
编译时,提示 struct device 中没有bus_id 这样的错误。打开/lib/modules/2.6.35-28-generic/build/include/linux/device.h
找到struct device 的定义,里面没有bus_id,但有:
const char *init_name; /* initial name of the device */ 这句。
可见,要把上面结构中的.bus_id = "my_bus0", 改为 .init_name = "my_bus0",
同时上网搜到,return !strncmp(dev->bus_id, driver->name, strlen(driver->name));这句也要改成:
return !strncmp(dev_name(dev), driver->name, strlen(driver->name));
这样编译即可成功!
另注:
如果要设置设备的名字,也不再使用strncpy(my_dev.bus_id, "my_dev", BUS_ID_SIZE); 而改用:
dev_set_name(&dev, "name");