lkml.org 
[lkml]   [2000]   [Oct]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject2.4.0test - uid_hash_find()

I've been touring around the kernel sources when I stumbled
across the uid_hash_find() function (kernel/user.c):

static inline struct user_struct *uid_hash_find(unsigned short uid, unsigned int hashent)
{
struct user_struct *up, *next;

next = uidhash[hashent];
for (;;) {
up = next;
if (next) {
next = up->next;
if (up->uid != uid)
continue;
atomic_inc(&up->__count);
}
break;
}
return up;
}

Now, it took me some time to figure out how this function
behaves, and I came into conclusion that the implementation
is not only an unreadable piece of code, but also inefficient.

Give one reason why we shouldn't use this:

static inline struct user_struct *uid_hash_find(unsigned short uid, unsigned int hashent)
{
struct user_struct *up;

for (up = uidhash[hashent]; up ; up = up->next)
if (up->uid == uid)
{
atomic_inc(&up->__count);
return up;
}

return NULL;
}

[compiled, booted, and it works fine]

The patch:

--- linux/kernel/user.c Sun Aug 13 16:36:42 2000
+++ linux.vanilla/kernel/user.c Sun Oct 8 19:34:07 2000
@@ -53,20 +53,16 @@

static inline struct user_struct *uid_hash_find(unsigned short uid, unsigned int hashent)
{
- struct user_struct *up, *next;
+ struct user_struct *up;

- next = uidhash[hashent];
- for (;;) {
- up = next;
- if (next) {
- next = up->next;
- if (up->uid != uid)
- continue;
- atomic_inc(&up->__count);
+ for (up = uidhash[hashent]; up ; up = up->next)
+ if (up->uid == uid)
+ {
+ atomic_inc(&up->__count);
+ return up;
}
- break;
- }
- return up;
+
+ return NULL;
}

/*
--
Dan Aloni
dax@karrde.org


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:39    [W:0.062 / U:0.056 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site