~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to drivers/staging/usbip/stub_main.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno, Martin Michlmayr
  • Date: 2011-04-06 13:53:30 UTC
  • mfrom: (43.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110406135330-wjufxhd0tvn3zx4z
Tags: 2.6.38-3
[ Ben Hutchings ]
* [ppc64] Add to linux-tools package architectures (Closes: #620124)
* [amd64] Save cr4 to mmu_cr4_features at boot time (Closes: #620284)
* appletalk: Fix bugs introduced when removing use of BKL
* ALSA: Fix yet another race in disconnection
* cciss: Fix lost command issue
* ath9k: Fix kernel panic in AR2427
* ses: Avoid kernel panic when lun 0 is not mapped
* PCI/ACPI: Report ASPM support to BIOS if not disabled from command line

[ Aurelien Jarno ]
* rtlwifi: fix build when PCI is not enabled.

[ Martin Michlmayr ]
* rtlwifi: Eliminate udelay calls with too large values (Closes: #620204)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 * USA.
18
18
 */
19
19
 
 
20
#include <linux/slab.h>
20
21
 
21
22
#include "usbip_common.h"
22
23
#include "stub.h"
40
41
 * remote host.
41
42
 */
42
43
#define MAX_BUSID 16
43
 
#define BUSID_SIZE 20
44
 
static char busid_table[MAX_BUSID][BUSID_SIZE];
 
44
static struct bus_id_priv busid_table[MAX_BUSID];
45
45
static spinlock_t busid_table_lock;
46
46
 
47
47
 
52
52
        spin_lock(&busid_table_lock);
53
53
 
54
54
        for (i = 0; i < MAX_BUSID; i++)
55
 
                if (busid_table[i][0])
56
 
                        if (!strncmp(busid_table[i], busid, BUSID_SIZE)) {
 
55
                if (busid_table[i].name[0])
 
56
                        if (!strncmp(busid_table[i].name, busid, BUSID_SIZE)) {
57
57
                                /* already registerd */
58
58
                                spin_unlock(&busid_table_lock);
59
59
                                return 0;
64
64
        return 1;
65
65
}
66
66
 
 
67
struct bus_id_priv *get_busid_priv(const char *busid)
 
68
{
 
69
        int i;
 
70
 
 
71
        spin_lock(&busid_table_lock);
 
72
 
 
73
        for (i = 0; i < MAX_BUSID; i++)
 
74
                if (busid_table[i].name[0])
 
75
                        if (!strncmp(busid_table[i].name, busid, BUSID_SIZE)) {
 
76
                                /* already registerd */
 
77
                                spin_unlock(&busid_table_lock);
 
78
                                return &(busid_table[i]);
 
79
                        }
 
80
 
 
81
        spin_unlock(&busid_table_lock);
 
82
 
 
83
        return NULL;
 
84
}
 
85
 
67
86
static ssize_t show_match_busid(struct device_driver *drv, char *buf)
68
87
{
69
88
        int i;
72
91
        spin_lock(&busid_table_lock);
73
92
 
74
93
        for (i = 0; i < MAX_BUSID; i++)
75
 
                if (busid_table[i][0])
76
 
                        out += sprintf(out, "%s ", busid_table[i]);
 
94
                if (busid_table[i].name[0])
 
95
                        out += sprintf(out, "%s ", busid_table[i].name);
77
96
 
78
97
        spin_unlock(&busid_table_lock);
79
98
 
92
111
        spin_lock(&busid_table_lock);
93
112
 
94
113
        for (i = 0; i < MAX_BUSID; i++)
95
 
                if (!busid_table[i][0]) {
96
 
                        strncpy(busid_table[i], busid, BUSID_SIZE);
 
114
                if (!busid_table[i].name[0]) {
 
115
                        strncpy(busid_table[i].name, busid, BUSID_SIZE);
 
116
                        if ((busid_table[i].status != STUB_BUSID_ALLOC) &&
 
117
                            (busid_table[i].status != STUB_BUSID_REMOV))
 
118
                                busid_table[i].status = STUB_BUSID_ADDED;
97
119
                        spin_unlock(&busid_table_lock);
98
120
                        return 0;
99
121
                }
103
125
        return -1;
104
126
}
105
127
 
106
 
static int del_match_busid(char *busid)
 
128
int del_match_busid(char *busid)
107
129
{
108
130
        int i;
109
131
 
110
132
        spin_lock(&busid_table_lock);
111
133
 
112
134
        for (i = 0; i < MAX_BUSID; i++)
113
 
                if (!strncmp(busid_table[i], busid, BUSID_SIZE)) {
 
135
                if (!strncmp(busid_table[i].name, busid, BUSID_SIZE)) {
114
136
                        /* found */
115
 
                        memset(busid_table[i], 0, BUSID_SIZE);
 
137
                        if (busid_table[i].status == STUB_BUSID_OTHER)
 
138
                                memset(busid_table[i].name, 0, BUSID_SIZE);
 
139
                        if ((busid_table[i].status != STUB_BUSID_OTHER) &&
 
140
                            (busid_table[i].status != STUB_BUSID_ADDED)) {
 
141
                                busid_table[i].status = STUB_BUSID_REMOV;
 
142
                        }
116
143
                        spin_unlock(&busid_table_lock);
117
144
                        return 0;
118
145
                }
121
148
 
122
149
        return -1;
123
150
}
 
151
static void init_busid_table(void)
 
152
{
 
153
        int i;
 
154
 
 
155
 
 
156
        for (i = 0; i < MAX_BUSID; i++) {
 
157
                memset(busid_table[i].name, 0, BUSID_SIZE);
 
158
                busid_table[i].status = STUB_BUSID_OTHER;
 
159
                busid_table[i].interf_count = 0;
 
160
                busid_table[i].sdev = NULL;
 
161
                busid_table[i].shutdown_busid = 0;
 
162
        }
 
163
        spin_lock_init(&busid_table_lock);
 
164
}
124
165
 
125
166
static ssize_t store_match_busid(struct device_driver *dev, const char *buf,
126
167
                size_t count)
260
301
        printk(KERN_INFO KBUILD_MODNAME ":"
261
302
               DRIVER_DESC ":" DRIVER_VERSION "\n");
262
303
 
263
 
        memset(busid_table, 0, sizeof(busid_table));
264
 
        spin_lock_init(&busid_table_lock);
 
304
        init_busid_table();
265
305
 
266
306
        ret = driver_create_file(&stub_driver.drvwrap.driver,
267
307
                                 &driver_attr_match_busid);