diff options
Diffstat (limited to 'drivers/char/drm/drm_auth.c')
-rw-r--r-- | drivers/char/drm/drm_auth.c | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/drivers/char/drm/drm_auth.c b/drivers/char/drm/drm_auth.c index dd140bca8f71..a47b502bc7cc 100644 --- a/drivers/char/drm/drm_auth.c +++ b/drivers/char/drm/drm_auth.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /** | 1 | /** |
2 | * \file drm_auth.h | 2 | * \file drm_auth.c |
3 | * IOCTLs for authentication | 3 | * IOCTLs for authentication |
4 | * | 4 | * |
5 | * \author Rickard E. (Rik) Faith <faith@valinux.com> | 5 | * \author Rickard E. (Rik) Faith <faith@valinux.com> |
@@ -46,7 +46,7 @@ | |||
46 | */ | 46 | */ |
47 | static int drm_hash_magic(drm_magic_t magic) | 47 | static int drm_hash_magic(drm_magic_t magic) |
48 | { | 48 | { |
49 | return magic & (DRM_HASH_SIZE-1); | 49 | return magic & (DRM_HASH_SIZE - 1); |
50 | } | 50 | } |
51 | 51 | ||
52 | /** | 52 | /** |
@@ -59,11 +59,11 @@ static int drm_hash_magic(drm_magic_t magic) | |||
59 | * the one with matching magic number, while holding the drm_device::struct_sem | 59 | * the one with matching magic number, while holding the drm_device::struct_sem |
60 | * lock. | 60 | * lock. |
61 | */ | 61 | */ |
62 | static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic) | 62 | static drm_file_t *drm_find_file(drm_device_t * dev, drm_magic_t magic) |
63 | { | 63 | { |
64 | drm_file_t *retval = NULL; | 64 | drm_file_t *retval = NULL; |
65 | drm_magic_entry_t *pt; | 65 | drm_magic_entry_t *pt; |
66 | int hash = drm_hash_magic(magic); | 66 | int hash = drm_hash_magic(magic); |
67 | 67 | ||
68 | down(&dev->struct_sem); | 68 | down(&dev->struct_sem); |
69 | for (pt = dev->magiclist[hash].head; pt; pt = pt->next) { | 69 | for (pt = dev->magiclist[hash].head; pt; pt = pt->next) { |
@@ -78,7 +78,7 @@ static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic) | |||
78 | 78 | ||
79 | /** | 79 | /** |
80 | * Adds a magic number. | 80 | * Adds a magic number. |
81 | * | 81 | * |
82 | * \param dev DRM device. | 82 | * \param dev DRM device. |
83 | * \param priv file private data. | 83 | * \param priv file private data. |
84 | * \param magic magic number. | 84 | * \param magic magic number. |
@@ -87,28 +87,30 @@ static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic) | |||
87 | * associated the magic number hash key in drm_device::magiclist, while holding | 87 | * associated the magic number hash key in drm_device::magiclist, while holding |
88 | * the drm_device::struct_sem lock. | 88 | * the drm_device::struct_sem lock. |
89 | */ | 89 | */ |
90 | static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic) | 90 | static int drm_add_magic(drm_device_t * dev, drm_file_t * priv, |
91 | drm_magic_t magic) | ||
91 | { | 92 | { |
92 | int hash; | 93 | int hash; |
93 | drm_magic_entry_t *entry; | 94 | drm_magic_entry_t *entry; |
94 | 95 | ||
95 | DRM_DEBUG("%d\n", magic); | 96 | DRM_DEBUG("%d\n", magic); |
96 | 97 | ||
97 | hash = drm_hash_magic(magic); | 98 | hash = drm_hash_magic(magic); |
98 | entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC); | 99 | entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC); |
99 | if (!entry) return -ENOMEM; | 100 | if (!entry) |
101 | return -ENOMEM; | ||
100 | memset(entry, 0, sizeof(*entry)); | 102 | memset(entry, 0, sizeof(*entry)); |
101 | entry->magic = magic; | 103 | entry->magic = magic; |
102 | entry->priv = priv; | 104 | entry->priv = priv; |
103 | entry->next = NULL; | 105 | entry->next = NULL; |
104 | 106 | ||
105 | down(&dev->struct_sem); | 107 | down(&dev->struct_sem); |
106 | if (dev->magiclist[hash].tail) { | 108 | if (dev->magiclist[hash].tail) { |
107 | dev->magiclist[hash].tail->next = entry; | 109 | dev->magiclist[hash].tail->next = entry; |
108 | dev->magiclist[hash].tail = entry; | 110 | dev->magiclist[hash].tail = entry; |
109 | } else { | 111 | } else { |
110 | dev->magiclist[hash].head = entry; | 112 | dev->magiclist[hash].head = entry; |
111 | dev->magiclist[hash].tail = entry; | 113 | dev->magiclist[hash].tail = entry; |
112 | } | 114 | } |
113 | up(&dev->struct_sem); | 115 | up(&dev->struct_sem); |
114 | 116 | ||
@@ -117,19 +119,18 @@ static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic) | |||
117 | 119 | ||
118 | /** | 120 | /** |
119 | * Remove a magic number. | 121 | * Remove a magic number. |
120 | * | 122 | * |
121 | * \param dev DRM device. | 123 | * \param dev DRM device. |
122 | * \param magic magic number. | 124 | * \param magic magic number. |
123 | * | 125 | * |
124 | * Searches and unlinks the entry in drm_device::magiclist with the magic | 126 | * Searches and unlinks the entry in drm_device::magiclist with the magic |
125 | * number hash key, while holding the drm_device::struct_sem lock. | 127 | * number hash key, while holding the drm_device::struct_sem lock. |
126 | */ | 128 | */ |
127 | static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic) | 129 | static int drm_remove_magic(drm_device_t * dev, drm_magic_t magic) |
128 | { | 130 | { |
129 | drm_magic_entry_t *prev = NULL; | 131 | drm_magic_entry_t *prev = NULL; |
130 | drm_magic_entry_t *pt; | 132 | drm_magic_entry_t *pt; |
131 | int hash; | 133 | int hash; |
132 | |||
133 | 134 | ||
134 | DRM_DEBUG("%d\n", magic); | 135 | DRM_DEBUG("%d\n", magic); |
135 | hash = drm_hash_magic(magic); | 136 | hash = drm_hash_magic(magic); |
@@ -171,21 +172,22 @@ static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic) | |||
171 | * filp. | 172 | * filp. |
172 | */ | 173 | */ |
173 | int drm_getmagic(struct inode *inode, struct file *filp, | 174 | int drm_getmagic(struct inode *inode, struct file *filp, |
174 | unsigned int cmd, unsigned long arg) | 175 | unsigned int cmd, unsigned long arg) |
175 | { | 176 | { |
176 | static drm_magic_t sequence = 0; | 177 | static drm_magic_t sequence = 0; |
177 | static DEFINE_SPINLOCK(lock); | 178 | static DEFINE_SPINLOCK(lock); |
178 | drm_file_t *priv = filp->private_data; | 179 | drm_file_t *priv = filp->private_data; |
179 | drm_device_t *dev = priv->head->dev; | 180 | drm_device_t *dev = priv->head->dev; |
180 | drm_auth_t auth; | 181 | drm_auth_t auth; |
181 | 182 | ||
182 | /* Find unique magic */ | 183 | /* Find unique magic */ |
183 | if (priv->magic) { | 184 | if (priv->magic) { |
184 | auth.magic = priv->magic; | 185 | auth.magic = priv->magic; |
185 | } else { | 186 | } else { |
186 | do { | 187 | do { |
187 | spin_lock(&lock); | 188 | spin_lock(&lock); |
188 | if (!sequence) ++sequence; /* reserve 0 */ | 189 | if (!sequence) |
190 | ++sequence; /* reserve 0 */ | ||
189 | auth.magic = sequence++; | 191 | auth.magic = sequence++; |
190 | spin_unlock(&lock); | 192 | spin_unlock(&lock); |
191 | } while (drm_find_file(dev, auth.magic)); | 193 | } while (drm_find_file(dev, auth.magic)); |
@@ -194,7 +196,7 @@ int drm_getmagic(struct inode *inode, struct file *filp, | |||
194 | } | 196 | } |
195 | 197 | ||
196 | DRM_DEBUG("%u\n", auth.magic); | 198 | DRM_DEBUG("%u\n", auth.magic); |
197 | if (copy_to_user((drm_auth_t __user *)arg, &auth, sizeof(auth))) | 199 | if (copy_to_user((drm_auth_t __user *) arg, &auth, sizeof(auth))) |
198 | return -EFAULT; | 200 | return -EFAULT; |
199 | return 0; | 201 | return 0; |
200 | } | 202 | } |
@@ -211,14 +213,14 @@ int drm_getmagic(struct inode *inode, struct file *filp, | |||
211 | * Checks if \p filp is associated with the magic number passed in \arg. | 213 | * Checks if \p filp is associated with the magic number passed in \arg. |
212 | */ | 214 | */ |
213 | int drm_authmagic(struct inode *inode, struct file *filp, | 215 | int drm_authmagic(struct inode *inode, struct file *filp, |
214 | unsigned int cmd, unsigned long arg) | 216 | unsigned int cmd, unsigned long arg) |
215 | { | 217 | { |
216 | drm_file_t *priv = filp->private_data; | 218 | drm_file_t *priv = filp->private_data; |
217 | drm_device_t *dev = priv->head->dev; | 219 | drm_device_t *dev = priv->head->dev; |
218 | drm_auth_t auth; | 220 | drm_auth_t auth; |
219 | drm_file_t *file; | 221 | drm_file_t *file; |
220 | 222 | ||
221 | if (copy_from_user(&auth, (drm_auth_t __user *)arg, sizeof(auth))) | 223 | if (copy_from_user(&auth, (drm_auth_t __user *) arg, sizeof(auth))) |
222 | return -EFAULT; | 224 | return -EFAULT; |
223 | DRM_DEBUG("%u\n", auth.magic); | 225 | DRM_DEBUG("%u\n", auth.magic); |
224 | if ((file = drm_find_file(dev, auth.magic))) { | 226 | if ((file = drm_find_file(dev, auth.magic))) { |