Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ozurbparanoia.c
Go to the documentation of this file.
1 /* -----------------------------------------------------------------------------
2  * Copyright (c) 2011 Ozmo Inc
3  * Released under the GNU General Public License Version 2 (GPLv2).
4  * -----------------------------------------------------------------------------
5  */
6 #include <linux/usb.h>
7 #include "ozconfig.h"
8 #ifdef WANT_URB_PARANOIA
9 #include "ozurbparanoia.h"
10 #include "oztrace.h"
11 /*-----------------------------------------------------------------------------
12  */
13 #define OZ_MAX_URBS 1000
14 struct urb *g_urb_memory[OZ_MAX_URBS];
15 int g_nb_urbs;
16 DEFINE_SPINLOCK(g_urb_mem_lock);
17 /*-----------------------------------------------------------------------------
18  */
19 void oz_remember_urb(struct urb *urb)
20 {
21  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_trace("%lu: urb up = %d %p\n", jiffies, g_nb_urbs, urb);
26  } else {
27  oz_trace("ERROR urb buffer full\n");
28  }
29  spin_unlock_irqrestore(&g_urb_mem_lock, irq_state);
30 }
31 /*------------------------------------------------------------------------------
32  */
33 int oz_forget_urb(struct urb *urb)
34 {
35  unsigned long irq_state;
36  int i;
37  int rc = -1;
38  spin_lock_irqsave(&g_urb_mem_lock, irq_state);
39  for (i = 0; i < g_nb_urbs; i++) {
40  if (g_urb_memory[i] == urb) {
41  rc = 0;
42  if (--g_nb_urbs > i)
43  memcpy(&g_urb_memory[i], &g_urb_memory[i+1],
44  (g_nb_urbs - i) * sizeof(struct urb *));
45  oz_trace("%lu: urb down = %d %p\n",
46  jiffies, g_nb_urbs, urb);
47  }
48  }
49  spin_unlock_irqrestore(&g_urb_mem_lock, irq_state);
50  return rc;
51 }
52 #endif /* #ifdef WANT_URB_PARANOIA */
53