Re: A small patch?

Linus Torvalds (torvalds@transmeta.com)
Mon, 2 Jun 1997 13:12:46 -0700 (PDT)


On Mon, 2 Jun 1997, H.J. Lu wrote:
>
> I just took another look at the code. Does this patch for
> __add_wait_queue () look ok?

This should never happen, your patch shouldn't make any difference to the
behaviour (except make things a teeny bit slower due to the new test).

> Index: include/linux/sched.h
> ===================================================================
> RCS file: /home/work/cvs/linux/linux/include/linux/sched.h,v
> retrieving revision 1.1.1.12
> diff -u -r1.1.1.12 sched.h
> --- sched.h 1997/05/24 01:39:23 1.1.1.12
> +++ sched.h 1997/06/02 20:02:49
> @@ -505,6 +505,8 @@
>
> if (head)
> next = head;
> + if (!next)
> + next = wait;
> *p = wait;
> wait->next = next;
> }

next cannot be NULL at that point, unless somebody has passed
add_wait_queue a bad pointer. The code looks like

extern inline void __add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
{
struct wait_queue *head = *p;
struct wait_queue *next = WAIT_QUEUE_HEAD(p);

if (head)
next = head;
*p = wait;
wait->next = next;
}

Note that "next" is initialized to WAIT_QUEUE_HEAD(p), which cannot be
NULL unless "p" is a totally invalid pointer (in which case you'd get a
fault at the *p assignment anyway). And the "next = head" assignment
obviously only happens if head is non-NULL, so next cannot become NULL
there either.

Linus