Re: [RFC] Outline of USB process integration in the kernel taskqueue system

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Hans Petter Selasky
Date: Saturday, November 6, 2010 - 1:37 am

On Friday 05 November 2010 20:06:12 John Baldwin wrote:

Hi,

I think you are getting me wrong! In the initial "0001-Implement-
taskqueue_cancel-9-to-cancel-a-task-from-a.patch" you have the following code-
chunk:

+int
+taskqueue_cancel(struct taskqueue *queue, struct task *task)
+{
+       int rc;
+
+       TQ_LOCK(queue);
+       if (!task_is_running(queue, task)) {
+               if ((rc = task->ta_pending) > 0)
+                       STAILQ_REMOVE(&queue->tq_queue, task, task, ta_link);
+               task->ta_pending = 0;
+       } else
+               rc = -EBUSY;
+       TQ_UNLOCK(queue);
+       return (rc);
+}

This code should be written like this, having the if (!task_is_running()) 
after checking the ta_pending variable.

+int
+taskqueue_cancel(struct taskqueue *queue, struct task *task)
+{
+       int rc;
+
+       TQ_LOCK(queue);
+               if ((rc = task->ta_pending) > 0) {
+                       STAILQ_REMOVE(&queue->tq_queue, task, task, ta_link);
+               		  task->ta_pending = 0;
+			  }
+       if (!task_is_running(queue, task))
+               rc = -EBUSY;
+       TQ_UNLOCK(queue);
+       return (rc);
+}

Or completely skip the !task_is_running() check. Else you are opening up a 
race in this function! Do I need to explain that more? Isn't it obvious?

--HPS
_______________________________________________
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC] Outline of USB process integration in the kernel tas ..., Hans Petter Selasky, (Mon Nov 1, 12:54 pm)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Mon Nov 1, 1:15 pm)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Tue Nov 2, 12:39 am)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Thu Nov 4, 1:38 am)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Thu Nov 4, 8:10 am)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Thu Nov 4, 11:41 am)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Thu Nov 4, 12:08 pm)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Thu Nov 4, 12:11 pm)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Thu Nov 4, 1:15 pm)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Fri Nov 5, 10:36 am)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Fri Nov 5, 11:30 am)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Fri Nov 5, 11:35 am)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Fri Nov 5, 11:45 am)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Fri Nov 5, 12:00 pm)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Sat Nov 6, 1:37 am)
Re: [RFC] Outline of USB process integration in the kernel ..., Hans Petter Selasky, (Sat Nov 6, 7:22 am)