[linux device driver] Chapter 14:kobject_init的理解
来源:互联网 发布:2017做淘宝还有钱赚吗 编辑:程序博客网 时间:2024/05/11 05:42
文章描述了好几个步骤,首先是清空kobject,这通常是使用memset清零包含kobject的结构体,比如:
memset(scullc_devices, 0, scullc_devs*sizeof (struct scullc_dev));for (i = 0; i < scullc_devs; i++) {scullc_devices[i].quantum = scullc_quantum;scullc_devices[i].qset = scullc_qset;sema_init (&scullc_devices[i].sem, 1);scullc_setup_cdev(scullc_devices + i, i);}
而scullc_devices就包含了kobject.
第二步是使用kobject_init设置内部变量,这个过程是scullc_setup_cdev调用cdev_init实现的:
void cdev_init(struct cdev *cdev, struct file_operations *fops){memset(cdev, 0, sizeof *cdev);INIT_LIST_HEAD(&cdev->list);cdev->kobj.ktype = &ktype_cdev_default;kobject_init(&cdev->kobj);cdev->ops = fops;}然后深入分析kboject_init:
void kobject_init(struct kobject * kobj){kref_init(&kobj->kref);//将引用计数设置为1INIT_LIST_HEAD(&kobj->entry);//初始化listkobj->kset = kset_get(kobj->kset);//设置kobj}void kref_init(struct kref *kref){atomic_set(&kref->refcount,1);}static inline struct kset * to_kset(struct kobject * kobj){return kobj ? container_of(kobj,struct kset,kobj) : NULL;}static inline struct kset * kset_get(struct kset * k){return k ? to_kset(kobject_get(&k->kobj)) : NULL;}
从上面来看,是将kobject的引用计数设置为1,
其他相关的问题,可以参照这篇文章,相当完整:设备模型-kobject详解
0 0
- [linux device driver] Chapter 14:kobject_init的理解
- [linux device driver] Chapter 03:IS_ERR的理解
- [linux device driver] Chapter 03:scullc_open理解
- [linux device driver] Chapter 03:scull_load脚本理解
- linux device driver container_of理解
- 对linux下platform device和Platform Driver的理解
- [linux device driver]Chapter 03:Scull_load中涉及到的群组权限之staff\wheel
- [linux device driver]Chapter 03:scull_load中涉及到的bash命令 exit
- [linux device driver] Chapter 03:字符设备注册学习
- [linux device driver] Chapter 03:make输出重定向
- [linux device driver] Chapter 04:Magic SysRq Key
- [linux device driver] Chapter 03:从scull_load了解awk
- [linux device driver] Chapter 04:使用/proc文件系统查询调试
- Linux device driver 的概念
- Linux device driver 的概念
- chapter 4.7: WDF的device和driver支持
- [linux device driver] Chapter 03:以scull_load为引,详解Bash的位置参数和内部参数
- [linux device driver] Chapter 03:以scull_load为例,讲解bash中反单引号`、双引号等的作用
- Spring 简介
- GMT&UTC,UNIX时间戳,时区
- 日志处理
- MySql 错误代码 1045 的 解决方案
- Java API
- [linux device driver] Chapter 14:kobject_init的理解
- Bestcoder #1 hodj4857
- SQL组装类
- 01. 矩阵乘法
- MySql错误代码1045的解决方案
- 复习数据结构:排序算法(四)——归并排序
- #define和typedef的简单区别及使用
- pat1035 Password
- 02. 高斯消元