当前位置: 技术问答>linux和unix
LDD3的scull代码问题
来源: 互联网 发布时间:2016-01-20
本文导语: struct scull_qset *scull_follow(struct scull_dev *dev, int n) ...{ struct scull_qset *qs = dev->data; /**//* Allocate first qset explicitly if need be */ if (! qs) ...{ qs = dev->data = kmalloc(sizeof(struct sc...
struct scull_qset *scull_follow(struct scull_dev *dev, int n)
...{
struct scull_qset *qs = dev->data;
/**//* Allocate first qset explicitly if need be */
if (! qs) ...{
qs = dev->data = kmalloc(sizeof(struct scull_qset), GFP_KERNEL);
if (qs == NULL)
return NULL; /**//* Never mind */
memset(qs, 0, sizeof(struct scull_qset));
}
/**//* Then follow the list */
while (n--) ...{
if (!qs->next) ...{
qs->next = kmalloc(sizeof(struct scull_qset), GFP_KERNEL);
if (qs->next == NULL)
return NULL; /**//* Never mind */
memset(qs->next, 0, sizeof(struct scull_qset));
}
qs = qs->next;
continue;
}
return qs;
}
为什么qs分配了内存,没有看到有释放?
...{
struct scull_qset *qs = dev->data;
/**//* Allocate first qset explicitly if need be */
if (! qs) ...{
qs = dev->data = kmalloc(sizeof(struct scull_qset), GFP_KERNEL);
if (qs == NULL)
return NULL; /**//* Never mind */
memset(qs, 0, sizeof(struct scull_qset));
}
/**//* Then follow the list */
while (n--) ...{
if (!qs->next) ...{
qs->next = kmalloc(sizeof(struct scull_qset), GFP_KERNEL);
if (qs->next == NULL)
return NULL; /**//* Never mind */
memset(qs->next, 0, sizeof(struct scull_qset));
}
qs = qs->next;
continue;
}
return qs;
}
为什么qs分配了内存,没有看到有释放?
|
这个driver就是一个虚拟内存的driver。其实是先有设备接点,然后当调用write的时候如果没有内存就分配他,相应的在read/write中有。而当cleanup是会完全卸载设备接点。具体你把整个代码看完应该能看到free的地方。