Commit db2181c9 authored by Federico Vaga's avatar Federico Vaga

sw:drv: bugfix filter our messages on poll

Without filtering the user poll on the full buffer which may not reflect
the real status from its point of view (with filters).

The following use case is buggy:

- buffer is not empty
- user does poll()
- poll sais that the user can read
- user does read()
- read return nothing because the buffer does not contain valid messages

This is critical for sync messages.
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent ad33f01e
......@@ -829,6 +829,29 @@ static ssize_t trtl_hmq_read(struct file *f, char __user *ubuf,
return count ? count : err;
}
/**
* It filters out messages until a valid one
* @usr: pointer to an user HMQ instance
*/
static void trtl_hmq_user_filter(struct trtl_hmq_user *usr)
{
struct trtl_hmq *hmq = usr->hmq;
struct trtl_msg *msg;
unsigned long flags1, flags2;
spin_lock_irqsave(&hmq->buf_in.lock, flags1);
spin_lock_irqsave(&usr->lock, flags2);
/* Loop until we find a valid message for the user */
while (hmq->buf_in.idx_w != usr->idx_r) {
msg = &hmq->buf_in.msg[usr->idx_r & (hmq_buf_max_msg - 1)];
if (trtl_hmq_filter_check(usr, msg))
break;
usr->idx_r++;
}
spin_unlock_irqrestore(&usr->lock, flags1);
spin_unlock_irqrestore(&hmq->buf_in.lock, flags2);
}
/**
* It looks into the input and output buffer to see if the user cna take
* any action. If the user can write 'POLLOUT', if the user can read 'POLLOUT'
......@@ -845,6 +868,7 @@ static unsigned int trtl_hmq_poll(struct file *f, struct poll_table_struct *w)
ret |= POLLOUT | POLLWRNORM;
/* Check if we have something to read */
trtl_hmq_user_filter(usr);
if (hmq->buf_in.idx_w != usr->idx_r)
ret |= POLLIN | POLLRDNORM;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment