mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-23 15:11:16 +00:00
hysdn: fix to a race condition in put_log_buffer
The synchronization type that was used earlier to guard the loop that deletes unused log buffers may lead to a situation that prevents any thread from going through the loop. The patch deletes previously used synchronization mechanism and moves the loop under the spin_lock so the similar cases won't be feasible in the future. Found by by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Anton Volkov <avolkov@ispras.ru> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
ec2c672632
commit
b925ef37b0
1 changed files with 13 additions and 15 deletions
|
@ -44,7 +44,6 @@ struct procdata {
|
||||||
char log_name[15]; /* log filename */
|
char log_name[15]; /* log filename */
|
||||||
struct log_data *log_head, *log_tail; /* head and tail for queue */
|
struct log_data *log_head, *log_tail; /* head and tail for queue */
|
||||||
int if_used; /* open count for interface */
|
int if_used; /* open count for interface */
|
||||||
int volatile del_lock; /* lock for delete operations */
|
|
||||||
unsigned char logtmp[LOG_MAX_LINELEN];
|
unsigned char logtmp[LOG_MAX_LINELEN];
|
||||||
wait_queue_head_t rd_queue;
|
wait_queue_head_t rd_queue;
|
||||||
};
|
};
|
||||||
|
@ -102,7 +101,6 @@ put_log_buffer(hysdn_card *card, char *cp)
|
||||||
{
|
{
|
||||||
struct log_data *ib;
|
struct log_data *ib;
|
||||||
struct procdata *pd = card->proclog;
|
struct procdata *pd = card->proclog;
|
||||||
int i;
|
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
if (!pd)
|
if (!pd)
|
||||||
|
@ -126,21 +124,21 @@ put_log_buffer(hysdn_card *card, char *cp)
|
||||||
else
|
else
|
||||||
pd->log_tail->next = ib; /* follows existing messages */
|
pd->log_tail->next = ib; /* follows existing messages */
|
||||||
pd->log_tail = ib; /* new tail */
|
pd->log_tail = ib; /* new tail */
|
||||||
i = pd->del_lock++; /* get lock state */
|
|
||||||
spin_unlock_irqrestore(&card->hysdn_lock, flags);
|
|
||||||
|
|
||||||
/* delete old entrys */
|
/* delete old entrys */
|
||||||
if (!i)
|
while (pd->log_head->next) {
|
||||||
while (pd->log_head->next) {
|
if ((pd->log_head->usage_cnt <= 0) &&
|
||||||
if ((pd->log_head->usage_cnt <= 0) &&
|
(pd->log_head->next->usage_cnt <= 0)) {
|
||||||
(pd->log_head->next->usage_cnt <= 0)) {
|
ib = pd->log_head;
|
||||||
ib = pd->log_head;
|
pd->log_head = pd->log_head->next;
|
||||||
pd->log_head = pd->log_head->next;
|
kfree(ib);
|
||||||
kfree(ib);
|
} else {
|
||||||
} else
|
break;
|
||||||
break;
|
}
|
||||||
} /* pd->log_head->next */
|
} /* pd->log_head->next */
|
||||||
pd->del_lock--; /* release lock level */
|
|
||||||
|
spin_unlock_irqrestore(&card->hysdn_lock, flags);
|
||||||
|
|
||||||
wake_up_interruptible(&(pd->rd_queue)); /* announce new entry */
|
wake_up_interruptible(&(pd->rd_queue)); /* announce new entry */
|
||||||
} /* put_log_buffer */
|
} /* put_log_buffer */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue