Struct kobj_map {
Struct the probe {
Struct the probe * next;
Dev_t dev.
Unsigned long range;
Struct module * owner;
Kobj_probe_t * get;
Int (* lock) (dev_t, void *);
Void * data;
The probes} * [255];
Struct lock mutex *;
};
I see kobj_map this function is as follows:
Int kobj_map (struct kobj_map * domain, dev_t dev, unsigned long range,
Struct the module, the module * kobj_probe_t * probe,
Int (* lock) (dev_t, void *), void * data)
{
Unsigned n=MAJOR (dev + range - 1) - MAJOR (dev) + 1;//assume range> (2 ^ 12-1), leading to the n=2
Unsigned index=MAJOR (dev);
Unsigned I;
Struct the probe * p;
If (n & gt; 255)
N=255;
P=kmalloc (sizeof (struct the probe) * n, GFP_KERNEL);//here will create 2 probe structure
If (p==NULL)
The return - ENOMEM;
For (I=0; i
p-> The get=the probe;
p-> The lock=the lock;
p-> Dev=dev.
p-> The range=range;
p-> Data=https://bbs.csdn.net/topics/data;
}
Mutex_lock (domain - & gt; The lock);
For (I=0, p -=n; i
While (* s & amp; & (* s) - & gt; The range & lt; Range)
S=& amp; (* s) - & gt; next;
p-> Next=* s;
* s=p;
}
Mutex_unlock (domain - & gt; The lock);
return 0;
}
I don't quite understand at this list index to + + insert, I doubt is a dynamic application of all of the probe structure, dev is the same, index++ here, it will not inserted the dev to other list? This is what I want the probes [255] array pointer is not only the same major number in a linked list? Index++ above, to the next the list of different major number, but the dynamic creation of the probe of the dev is the same, it doesn't have a problem? Or I understand is wrong? So cause I don't quite understand what the range is used for? The whole management process and what the hell?
CodePudding user response:
Write wrong, should be 2 ^ 1 to 20, can lead to n> 1