打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
device_create用法
今天在用device_create时参考网上用法时,加载驱动时总是报错,搞了一下午
my_class = class_create(THIS_MODULE, "my_class");
     if(IS_ERR(my_class))
     {
          printk("Err: failed in creating class.\n");
          return -1;
      }

  /* register your own device in sysfs, and this will cause udev to create corresponding device node */
      device_create( my_class, NULL, MKDEV(hello_major, 0), "hello" "%d", 0 );// X

     应为  device_create( my_class, NULL, MKDEV(hello_major, 0), NULL ,"hello%d", 0)



  printk (KERN_INFO "Registered character driver\n");
      return 0;
函数源代码如下:/**
 * device_create - creates a device and registers it with sysfs
 * @class: pointer to the struct class that this device should be registered to
 * @parent: pointer to the parent struct device of this new device, if any
 * @devt: the dev_t for the char device to be added
 * @drvdata: the data to be added to the device for callbacks
 * @fmt: string for the device's name
 *
 * This function can be used by char device classes.  A struct device
 * will be created in sysfs, registered to the specified class.
 *
 * A "dev" file will be created, showing the dev_t for the device, if
 * the dev_t is not 0,0.
 * If a pointer to a parent struct device is passed in, the newly created
 * struct device will be a child of that device in sysfs.
 * The pointer to the struct device will be returned from the call.
 * Any further sysfs files that might be required can be created using this
 * pointer.
 *
 * Returns &struct device pointer on success, or ERR_PTR() on error.
 *
 * Note: the struct class passed to this function must have previously
 * been created with a call to class_create().
 */
struct device *device_create(struct class *class, struct device *parent,
                 dev_t devt, void *drvdata, const char *fmt, ...)
{
    va_list vargs;
    struct device *dev;

    va_start(vargs, fmt);
    dev = device_create_vargs(class, parent, devt, drvdata, fmt, vargs);
    va_end(vargs);
    return dev;
}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Linux驱动学习(四)
Linux驱动框架
DEVICE
在驱动模块初始化函数中实现设备节点的自动创建(华清远见旗下品牌)
Linux驱动程序开发 - 设备驱动模型初探
Linux驱动 | Linux内核 RTC时间架构
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服