From: Alan Cox Date: Fri, 25 Mar 2016 21:07:07 +0000 (+0000) Subject: alloc_socket: interrupt lock X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=a31db315645b286a5f1f0901b8c63668a7e57a15;p=FUZIX.git alloc_socket: interrupt lock In the normal case this is safe because we always allocate from in kernel. Likewise it's safe for accept with the native TCP/IP. However it's not safe if we have a hardware TCP/IP and it implements accept() and thus allocates accepting sockets from an interrupt. So block IRQs for the brief scan. [noted by Brett] --- diff --git a/Kernel/syscall_net.c b/Kernel/syscall_net.c index d8d46853..c4a4a8fa 100644 --- a/Kernel/syscall_net.c +++ b/Kernel/syscall_net.c @@ -90,12 +90,17 @@ static int sock_wait_enter(struct socket *s, uint8_t flag, uint8_t state) static struct socket *alloc_socket(void) { + irqflags_t irq = di(); struct socket *s = sockets; while (s < sockets + NSOCKET) { - if (s->s_state == SS_UNUSED) + if (s->s_state == SS_UNUSED) { + s->s_state = SS_INIT; + irqrestore(irq); return s; + } s++; } + irqrestore(irq); return NULL; }