aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/bluetooth/hci_vhci.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2006-07-06 09:45:23 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2006-09-28 21:01:27 -0400
commit9c724357f432df5ddc83a62c8168414a604cd420 (patch)
treed0a31bb522fbc78f4a813a9be81c7a5c34a9426b /drivers/bluetooth/hci_vhci.c
parent0a85b964e141a4b8db6eaf500ceace12f8f52f93 (diff)
[Bluetooth] Code cleanup of the drivers source code
This patch is an attempt to cleanup the drivers source code to make all Bluetooth drivers look more unique. Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'drivers/bluetooth/hci_vhci.c')
-rw-r--r--drivers/bluetooth/hci_vhci.c97
1 files changed, 49 insertions, 48 deletions
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index aac67a3a6019..fc2130f1776a 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -2,9 +2,9 @@
2 * 2 *
3 * Bluetooth virtual HCI driver 3 * Bluetooth virtual HCI driver
4 * 4 *
5 * Copyright (C) 2000-2001 Qualcomm Incorporated 5 * Copyright (C) 2000-2001 Qualcomm Incorporated
6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com> 6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
7 * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org> 7 * Copyright (C) 2004-2006 Marcel Holtmann <marcel@holtmann.org>
8 * 8 *
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
@@ -72,21 +72,21 @@ static int vhci_open_dev(struct hci_dev *hdev)
72 72
73static int vhci_close_dev(struct hci_dev *hdev) 73static int vhci_close_dev(struct hci_dev *hdev)
74{ 74{
75 struct vhci_data *vhci = hdev->driver_data; 75 struct vhci_data *data = hdev->driver_data;
76 76
77 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) 77 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
78 return 0; 78 return 0;
79 79
80 skb_queue_purge(&vhci->readq); 80 skb_queue_purge(&data->readq);
81 81
82 return 0; 82 return 0;
83} 83}
84 84
85static int vhci_flush(struct hci_dev *hdev) 85static int vhci_flush(struct hci_dev *hdev)
86{ 86{
87 struct vhci_data *vhci = hdev->driver_data; 87 struct vhci_data *data = hdev->driver_data;
88 88
89 skb_queue_purge(&vhci->readq); 89 skb_queue_purge(&data->readq);
90 90
91 return 0; 91 return 0;
92} 92}
@@ -94,7 +94,7 @@ static int vhci_flush(struct hci_dev *hdev)
94static int vhci_send_frame(struct sk_buff *skb) 94static int vhci_send_frame(struct sk_buff *skb)
95{ 95{
96 struct hci_dev* hdev = (struct hci_dev *) skb->dev; 96 struct hci_dev* hdev = (struct hci_dev *) skb->dev;
97 struct vhci_data *vhci; 97 struct vhci_data *data;
98 98
99 if (!hdev) { 99 if (!hdev) {
100 BT_ERR("Frame for unknown HCI device (hdev=NULL)"); 100 BT_ERR("Frame for unknown HCI device (hdev=NULL)");
@@ -104,15 +104,15 @@ static int vhci_send_frame(struct sk_buff *skb)
104 if (!test_bit(HCI_RUNNING, &hdev->flags)) 104 if (!test_bit(HCI_RUNNING, &hdev->flags))
105 return -EBUSY; 105 return -EBUSY;
106 106
107 vhci = hdev->driver_data; 107 data = hdev->driver_data;
108 108
109 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); 109 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
110 skb_queue_tail(&vhci->readq, skb); 110 skb_queue_tail(&data->readq, skb);
111 111
112 if (vhci->flags & VHCI_FASYNC) 112 if (data->flags & VHCI_FASYNC)
113 kill_fasync(&vhci->fasync, SIGIO, POLL_IN); 113 kill_fasync(&data->fasync, SIGIO, POLL_IN);
114 114
115 wake_up_interruptible(&vhci->read_wait); 115 wake_up_interruptible(&data->read_wait);
116 116
117 return 0; 117 return 0;
118} 118}
@@ -122,7 +122,7 @@ static void vhci_destruct(struct hci_dev *hdev)
122 kfree(hdev->driver_data); 122 kfree(hdev->driver_data);
123} 123}
124 124
125static inline ssize_t vhci_get_user(struct vhci_data *vhci, 125static inline ssize_t vhci_get_user(struct vhci_data *data,
126 const char __user *buf, size_t count) 126 const char __user *buf, size_t count)
127{ 127{
128 struct sk_buff *skb; 128 struct sk_buff *skb;
@@ -139,7 +139,7 @@ static inline ssize_t vhci_get_user(struct vhci_data *vhci,
139 return -EFAULT; 139 return -EFAULT;
140 } 140 }
141 141
142 skb->dev = (void *) vhci->hdev; 142 skb->dev = (void *) data->hdev;
143 bt_cb(skb)->pkt_type = *((__u8 *) skb->data); 143 bt_cb(skb)->pkt_type = *((__u8 *) skb->data);
144 skb_pull(skb, 1); 144 skb_pull(skb, 1);
145 145
@@ -148,7 +148,7 @@ static inline ssize_t vhci_get_user(struct vhci_data *vhci,
148 return count; 148 return count;
149} 149}
150 150
151static inline ssize_t vhci_put_user(struct vhci_data *vhci, 151static inline ssize_t vhci_put_user(struct vhci_data *data,
152 struct sk_buff *skb, char __user *buf, int count) 152 struct sk_buff *skb, char __user *buf, int count)
153{ 153{
154 char __user *ptr = buf; 154 char __user *ptr = buf;
@@ -161,42 +161,43 @@ static inline ssize_t vhci_put_user(struct vhci_data *vhci,
161 161
162 total += len; 162 total += len;
163 163
164 vhci->hdev->stat.byte_tx += len; 164 data->hdev->stat.byte_tx += len;
165 165
166 switch (bt_cb(skb)->pkt_type) { 166 switch (bt_cb(skb)->pkt_type) {
167 case HCI_COMMAND_PKT: 167 case HCI_COMMAND_PKT:
168 vhci->hdev->stat.cmd_tx++; 168 data->hdev->stat.cmd_tx++;
169 break; 169 break;
170 170
171 case HCI_ACLDATA_PKT: 171 case HCI_ACLDATA_PKT:
172 vhci->hdev->stat.acl_tx++; 172 data->hdev->stat.acl_tx++;
173 break; 173 break;
174 174
175 case HCI_SCODATA_PKT: 175 case HCI_SCODATA_PKT:
176 vhci->hdev->stat.cmd_tx++; 176 data->hdev->stat.cmd_tx++;
177 break; 177 break;
178 }; 178 };
179 179
180 return total; 180 return total;
181} 181}
182 182
183static loff_t vhci_llseek(struct file * file, loff_t offset, int origin) 183static loff_t vhci_llseek(struct file *file, loff_t offset, int origin)
184{ 184{
185 return -ESPIPE; 185 return -ESPIPE;
186} 186}
187 187
188static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, loff_t *pos) 188static ssize_t vhci_read(struct file *file,
189 char __user *buf, size_t count, loff_t *pos)
189{ 190{
190 DECLARE_WAITQUEUE(wait, current); 191 DECLARE_WAITQUEUE(wait, current);
191 struct vhci_data *vhci = file->private_data; 192 struct vhci_data *data = file->private_data;
192 struct sk_buff *skb; 193 struct sk_buff *skb;
193 ssize_t ret = 0; 194 ssize_t ret = 0;
194 195
195 add_wait_queue(&vhci->read_wait, &wait); 196 add_wait_queue(&data->read_wait, &wait);
196 while (count) { 197 while (count) {
197 set_current_state(TASK_INTERRUPTIBLE); 198 set_current_state(TASK_INTERRUPTIBLE);
198 199
199 skb = skb_dequeue(&vhci->readq); 200 skb = skb_dequeue(&data->readq);
200 if (!skb) { 201 if (!skb) {
201 if (file->f_flags & O_NONBLOCK) { 202 if (file->f_flags & O_NONBLOCK) {
202 ret = -EAGAIN; 203 ret = -EAGAIN;
@@ -213,7 +214,7 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo
213 } 214 }
214 215
215 if (access_ok(VERIFY_WRITE, buf, count)) 216 if (access_ok(VERIFY_WRITE, buf, count))
216 ret = vhci_put_user(vhci, skb, buf, count); 217 ret = vhci_put_user(data, skb, buf, count);
217 else 218 else
218 ret = -EFAULT; 219 ret = -EFAULT;
219 220
@@ -221,7 +222,7 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo
221 break; 222 break;
222 } 223 }
223 set_current_state(TASK_RUNNING); 224 set_current_state(TASK_RUNNING);
224 remove_wait_queue(&vhci->read_wait, &wait); 225 remove_wait_queue(&data->read_wait, &wait);
225 226
226 return ret; 227 return ret;
227} 228}
@@ -229,21 +230,21 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo
229static ssize_t vhci_write(struct file *file, 230static ssize_t vhci_write(struct file *file,
230 const char __user *buf, size_t count, loff_t *pos) 231 const char __user *buf, size_t count, loff_t *pos)
231{ 232{
232 struct vhci_data *vhci = file->private_data; 233 struct vhci_data *data = file->private_data;
233 234
234 if (!access_ok(VERIFY_READ, buf, count)) 235 if (!access_ok(VERIFY_READ, buf, count))
235 return -EFAULT; 236 return -EFAULT;
236 237
237 return vhci_get_user(vhci, buf, count); 238 return vhci_get_user(data, buf, count);
238} 239}
239 240
240static unsigned int vhci_poll(struct file *file, poll_table *wait) 241static unsigned int vhci_poll(struct file *file, poll_table *wait)
241{ 242{
242 struct vhci_data *vhci = file->private_data; 243 struct vhci_data *data = file->private_data;
243 244
244 poll_wait(file, &vhci->read_wait, wait); 245 poll_wait(file, &data->read_wait, wait);
245 246
246 if (!skb_queue_empty(&vhci->readq)) 247 if (!skb_queue_empty(&data->readq))
247 return POLLIN | POLLRDNORM; 248 return POLLIN | POLLRDNORM;
248 249
249 return POLLOUT | POLLWRNORM; 250 return POLLOUT | POLLWRNORM;
@@ -257,26 +258,26 @@ static int vhci_ioctl(struct inode *inode, struct file *file,
257 258
258static int vhci_open(struct inode *inode, struct file *file) 259static int vhci_open(struct inode *inode, struct file *file)
259{ 260{
260 struct vhci_data *vhci; 261 struct vhci_data *data;
261 struct hci_dev *hdev; 262 struct hci_dev *hdev;
262 263
263 vhci = kzalloc(sizeof(struct vhci_data), GFP_KERNEL); 264 data = kzalloc(sizeof(struct vhci_data), GFP_KERNEL);
264 if (!vhci) 265 if (!data)
265 return -ENOMEM; 266 return -ENOMEM;
266 267
267 skb_queue_head_init(&vhci->readq); 268 skb_queue_head_init(&data->readq);
268 init_waitqueue_head(&vhci->read_wait); 269 init_waitqueue_head(&data->read_wait);
269 270
270 hdev = hci_alloc_dev(); 271 hdev = hci_alloc_dev();
271 if (!hdev) { 272 if (!hdev) {
272 kfree(vhci); 273 kfree(data);
273 return -ENOMEM; 274 return -ENOMEM;
274 } 275 }
275 276
276 vhci->hdev = hdev; 277 data->hdev = hdev;
277 278
278 hdev->type = HCI_VHCI; 279 hdev->type = HCI_VHCI;
279 hdev->driver_data = vhci; 280 hdev->driver_data = data;
280 281
281 hdev->open = vhci_open_dev; 282 hdev->open = vhci_open_dev;
282 hdev->close = vhci_close_dev; 283 hdev->close = vhci_close_dev;
@@ -288,20 +289,20 @@ static int vhci_open(struct inode *inode, struct file *file)
288 289
289 if (hci_register_dev(hdev) < 0) { 290 if (hci_register_dev(hdev) < 0) {
290 BT_ERR("Can't register HCI device"); 291 BT_ERR("Can't register HCI device");
291 kfree(vhci); 292 kfree(data);
292 hci_free_dev(hdev); 293 hci_free_dev(hdev);
293 return -EBUSY; 294 return -EBUSY;
294 } 295 }
295 296
296 file->private_data = vhci; 297 file->private_data = data;
297 298
298 return nonseekable_open(inode, file); 299 return nonseekable_open(inode, file);
299} 300}
300 301
301static int vhci_release(struct inode *inode, struct file *file) 302static int vhci_release(struct inode *inode, struct file *file)
302{ 303{
303 struct vhci_data *vhci = file->private_data; 304 struct vhci_data *data = file->private_data;
304 struct hci_dev *hdev = vhci->hdev; 305 struct hci_dev *hdev = data->hdev;
305 306
306 if (hci_unregister_dev(hdev) < 0) { 307 if (hci_unregister_dev(hdev) < 0) {
307 BT_ERR("Can't unregister HCI device %s", hdev->name); 308 BT_ERR("Can't unregister HCI device %s", hdev->name);
@@ -316,17 +317,17 @@ static int vhci_release(struct inode *inode, struct file *file)
316 317
317static int vhci_fasync(int fd, struct file *file, int on) 318static int vhci_fasync(int fd, struct file *file, int on)
318{ 319{
319 struct vhci_data *vhci = file->private_data; 320 struct vhci_data *data = file->private_data;
320 int err; 321 int err;
321 322
322 err = fasync_helper(fd, file, on, &vhci->fasync); 323 err = fasync_helper(fd, file, on, &data->fasync);
323 if (err < 0) 324 if (err < 0)
324 return err; 325 return err;
325 326
326 if (on) 327 if (on)
327 vhci->flags |= VHCI_FASYNC; 328 data->flags |= VHCI_FASYNC;
328 else 329 else
329 vhci->flags &= ~VHCI_FASYNC; 330 data->flags &= ~VHCI_FASYNC;
330 331
331 return 0; 332 return 0;
332} 333}