remove sleep_on from drivers/net/shaper.c
PATCH 1/1 remove sleep_on from drivers/net/shaper.c
The shaper devices uses sleep_on for it's wait queue. The implementation is racy, the attached patch replaces it with an explicit add/remove_wait_queue.
drivers/net/shaper.c +17 -6
@@ -83,6 +83,7 @@#include <linux/if_arp.h> #include <linux/init.h> #include <linux/if_shaper.h> +#include <linux/wait.h> #include <net/dst.h> #include <net/arp.h>
@@ -106,17 +107,27 @@static int shaper_lock (struct shaper *sh) { +DECLARE_WAITQUEUE (wait, current); +/* * Lock in an interrupt must fail */ -while (test_and_set_bit (0 , &sh->locked)) - { -if (!in_interrupt ()) -sleep_on (&sh->wait_queue); -else +if (in_interrupt ()) { +if (test_and_set_bit (0 , &sh->locked)) {return 0 ; - + }else { +return 1 ; + } + } +add_wait_queue (&sh->wait_queue, &wait); +for (;;) { +set_current_state (TASK_UNINTERRUPTIBLE ); +if (test_and_set_bit (0 , &sh->locked) ==0 ) +break ; +schedule (); } +remove_wait_queue (&sh->wait_queue, &wait); +__set_current_state (TASK_RUNNING );return 1 ; }