1 /* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
9 #ifdef WANT_URB_PARANOIA
11 #include "ozurbparanoia.h"
13 #define OZ_MAX_URBS 1000
14 struct urb
*g_urb_memory
[OZ_MAX_URBS
];
16 DEFINE_SPINLOCK(g_urb_mem_lock
);
18 void oz_remember_urb(struct urb
*urb
)
20 unsigned long irq_state
;
22 spin_lock_irqsave(&g_urb_mem_lock
, irq_state
);
23 if (g_nb_urbs
< OZ_MAX_URBS
) {
24 g_urb_memory
[g_nb_urbs
++] = urb
;
25 oz_dbg(ON
, "urb up = %d %p\n", g_nb_urbs
, urb
);
27 oz_dbg(ON
, "ERROR urb buffer full\n");
29 spin_unlock_irqrestore(&g_urb_mem_lock
, irq_state
);
34 int oz_forget_urb(struct urb
*urb
)
36 unsigned long irq_state
;
40 spin_lock_irqsave(&g_urb_mem_lock
, irq_state
);
41 for (i
= 0; i
< g_nb_urbs
; i
++) {
42 if (g_urb_memory
[i
] == urb
) {
45 memcpy(&g_urb_memory
[i
], &g_urb_memory
[i
+1],
46 (g_nb_urbs
- i
) * sizeof(struct urb
*));
47 oz_dbg(ON
, "urb down = %d %p\n", g_nb_urbs
, urb
);
50 spin_unlock_irqrestore(&g_urb_mem_lock
, irq_state
);
53 #endif /* #ifdef WANT_URB_PARANOIA */