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]
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;
}