On 9/4/07, anon... anon.al <[email protected]> wrote:
<snip>
> If yes: which mechanism can be used?
I was thinking about using an atomic counter in procfile_write
proc_f = create_proc_entry(PROC_FILE_NAME, 0644, NULL);
//...
proc_f->write_proc = procfile_write;
int procfile_write(struct file *filp, const char *buffer, \
unsigned long len, void *data)
{
//"StackXXX"
atomic_inc(&cnt_procfile_users);
printk(KERN_ALERT "Hi there!\n");
atomic_dec(&cnt_procfile_users);
wake_up_interruptible(&queue);
return len;
}
and then in cleanup_module using:
wait_event_interruptible(queue, \
( \
spin_lock_irqsave(&lock, flags), \
cnt = atomic_read(&cnt_procfile_users), \
((cnt == 0) \
? 1 \
: (spin_unlock_irqrestore(&lock, flags), 0))\
));
remove_proc_entry(PROC_FILE_NAME, &proc_root);
spin_unlock_irqrestore(&lock, flags);
But:
x1)
Could it happen that code is already in function procfile_write at "StackXXX"
(before atomic_inc(&cnt_procfile_users)) when the scheduler switches
to another task??
((Or is the "entering into a function, up to the function's first
statement" atomic??))
x2)
Could it happen that the scheduler switches, after
atomic_dev(&cnt_procfile_users) but before
return len??
If so, then it could happen that we're in spin_lock_irqsave, while
someone else is still using the procfile; and then this code still
fails miserably.
?
Regards -Albert
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]