Our today’s hero is company named Port, with their can4linux drivers.
These people demonstrate wonderful knowledge on how to do mutual-exclusion in kernel. Here is an example:
if(0 == atomic_read(&Can_isopen[minor])) {
/* first time called, initialize hardware and global data */
...
}
... /* many more code, without any locks held */
atomic_inc(&Can_isopen[minor]);
Looks like they are sure that using atomic here will help them to catch first call reliably.
One more example:
spin_lock(&waitflag_lock);
for(i = 0; i < CAN_MAX_OPEN; i++) {
if(CanWaitFlag[minor][i] == 0) break;
}
spin_unlock(&waitflag_lock);
And now they think that i is a reliable index of zero array element.
Both examples taken from their open() routine.
There are numerous other issues in the code - races, improper use of kernel infrastructure, etc. A very good example of out-of-community, no-review development.
Anyway, they are still in business, and do offer all that to their customers. Let's wish them good luck
.