Re: Behavior of poll() within a module

Manfred Spraul (manfred@colorfullife.com)
Tue, 23 Oct 2001 17:58:03 +0200


>
> The following actual module code:
>
> static unsigned int vxi_poll(struct file *fp, struct poll_table_struct *wait)
> {
> unsigned long flags;
> unsigned int mask;
> DEB(printk("vxi_poll\n"));
> info->poll_active++;
> poll_wait(fp, &info->wait, wait);
> spin_lock_irqsave(&vxi_lock, flags);
> mask = info->poll_mask;
> if(!--info->poll_active)
> info->poll_mask = 0;
> spin_unlock_irqrestore(&vxi_lock, flags);
> DEB(printk("vxi_poll returns\n"));
> return mask;
> }
Which module is that? I can't find it in Linus tree.
Is "info" a global variable?

* poll is called without any SMP locking, "info->poll_active++" is not SMP safe. Use atomic_inc, or even better just delete that
line.
* Clearing poll_mask during poll is wrong.
poll should return the events that are currently available, i.e. what would happen if read() or write() would be called now.

read() on a non-blocking file handle would return immediately with 1 or more bytes read --> set POLLIN
write() on a non-blocking file handle would return immediately with a nonzero byte count written--> set POLLOUT.
The clearing of poll_mask must occur during read() and write() if these conditions are not true anymore.

--
    Manfred

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/