lkml.org 
[lkml]   [2011]   [May]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 04/12] staging: usbip: stub_main.c: code cleanup


Am 20.05.2011 20:45, schrieb matt mooney:
> On 11:08 Fri 20 May , walter harms wrote:
>>
>>
>> Am 20.05.2011 06:36, schrieb matt mooney:
>>> Remove match_find() and replace with get_busid_idx(); change
>>> get_busid_priv(), add_match_busid(), and del_match_busid() to use
>>> get_busid_idx(); and cleanup code in the other functions.
>>>
>>> Signed-off-by: matt mooney <mfm@muteddisk.com>
>>> ---
>>> drivers/staging/usbip/stub_main.c | 147 ++++++++++++++++++-------------------
>>> 1 files changed, 73 insertions(+), 74 deletions(-)
>>>
>>> diff --git a/drivers/staging/usbip/stub_main.c b/drivers/staging/usbip/stub_main.c
>>> index 0ca1462..00398a6 100644
>>> --- a/drivers/staging/usbip/stub_main.c
>>> +++ b/drivers/staging/usbip/stub_main.c
>>> @@ -50,82 +50,90 @@ static void init_busid_table(void)
>>> spin_lock_init(&busid_table_lock);
>>> }
>>>
>>> -int match_busid(const char *busid)
>>> +/*
>>> + * Find the index of the busid by name.
>>> + * Must be called with busid_table_lock held.
>>> + */
>>> +static int get_busid_idx(const char *busid)
>>> {
>>> int i;
>>> + int idx = -1;
>>>
>>> - spin_lock(&busid_table_lock);
>>> for (i = 0; i < MAX_BUSID; i++)
>>> if (busid_table[i].name[0])
>>> if (!strncmp(busid_table[i].name, busid, BUSID_SIZE)) {
>>> - /* already registerd */
>>> - spin_unlock(&busid_table_lock);
>>> - return 0;
>>> + idx = i;
>>> + break;
>>> }
>>> - spin_unlock(&busid_table_lock);
>>> -
>>> - return 1;
>>> + return idx;
>>> }
>>>
>>> struct bus_id_priv *get_busid_priv(const char *busid)
>>> {
>>> - int i;
>>> + int idx;
>>> + struct bus_id_priv *bid = NULL;
>>>
>>> spin_lock(&busid_table_lock);
>>> - for (i = 0; i < MAX_BUSID; i++)
>>> - if (busid_table[i].name[0])
>>> - if (!strncmp(busid_table[i].name, busid, BUSID_SIZE)) {
>>> - /* already registerd */
>>> - spin_unlock(&busid_table_lock);
>>> - return &(busid_table[i]);
>>> - }
>>> + idx = get_busid_idx(busid);
>>> + if (idx >= 0)
>>> + bid = &(busid_table[idx]);
>>> spin_unlock(&busid_table_lock);
>>>
>>> - return NULL;
>>> + return bid;
>>> }
>>>
>>> static int add_match_busid(char *busid)
>>> {
>>> int i;
>>> -
>>> - if (!match_busid(busid))
>>> - return 0;
>>> + int ret = -1;
>>>
>>> spin_lock(&busid_table_lock);
>>> + /* already registered? */
>>> + if (get_busid_idx(busid) >= 0) {
>>> + ret = 0;
>>> + goto out;
>>> + }
>>> +
>>> for (i = 0; i < MAX_BUSID; i++)
>>> if (!busid_table[i].name[0]) {
>>> strncpy(busid_table[i].name, busid, BUSID_SIZE);
>>
>> i am missing an if() here ??
>
> I am not sure what you mean. It should be correct.
>

ups, sorry my fault
missread it as strcmp() everything is fine now.

re,
wh



\
 
 \ /
  Last update: 2011-05-21 13:47    [from the cache]
©2003-2011 Jasper Spaans