Question about spinlock and timer
Hello, linux guru.
After reading spinlock documentation at the kernelnewbie.org, i've got a question:
If i clearly understand, each kernel timer is connected with some memory region, and this region should be freed when timer becomes clear. And this can occur before spi_lock_bh(). Therefore this memory regin will be freed second time in the loop.
spin_lock_bh(&list_lock);
while (list) {
struct foo *next = list->next;
del_timer(&list->timer);
kfree(list);
list = next;
}
spin_unlock_bh(&list_lock);This is correct example:
retry:
spin_lock_bh(&list_lock);
while (list) {
struct foo *next = list->next;
if (!del_timer(&list->timer)) {
/* Give timer a chance to delete this */
spin_unlock_bh(&list_lock);
goto retry;
}
kfree(list);
list = next;
}
spin_unlock_bh(&list_lock);If i was right in previous assumption, than this code may be owervritten in such manner:
.....
if (!del_timer(&list->timer)) {
if (!next)
break;
list = next;
continue;
}.....
Or am I wrong again?
If it is so, please tell me the write answer and explanation.
Thanks in advance for you answers and appologies.
---
WBR. //s0mbre