Commit 9c724357 authored by Marcel Holtmann's avatar Marcel Holtmann Committed by David S. Miller

[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: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 0a85b964
This diff is collapsed.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* Copyright (C) 2000-2001 Qualcomm Incorporated * Copyright (C) 2000-2001 Qualcomm Incorporated
* Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com> * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
* Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org> * Copyright (C) 2004-2006 Marcel Holtmann <marcel@holtmann.org>
* *
* *
* This program is free software; you can redistribute it and/or modify * 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,21 +72,21 @@ static int vhci_open_dev(struct hci_dev *hdev)
static int vhci_close_dev(struct hci_dev *hdev) static int vhci_close_dev(struct hci_dev *hdev)
{ {
struct vhci_data *vhci = hdev->driver_data; struct vhci_data *data = hdev->driver_data;
if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
return 0; return 0;
skb_queue_purge(&vhci->readq); skb_queue_purge(&data->readq);
return 0; return 0;
} }
static int vhci_flush(struct hci_dev *hdev) static int vhci_flush(struct hci_dev *hdev)
{ {
struct vhci_data *vhci = hdev->driver_data; struct vhci_data *data = hdev->driver_data;
skb_queue_purge(&vhci->readq); skb_queue_purge(&data->readq);
return 0; return 0;
} }
...@@ -94,7 +94,7 @@ static int vhci_flush(struct hci_dev *hdev) ...@@ -94,7 +94,7 @@ static int vhci_flush(struct hci_dev *hdev)
static int vhci_send_frame(struct sk_buff *skb) static int vhci_send_frame(struct sk_buff *skb)
{ {
struct hci_dev* hdev = (struct hci_dev *) skb->dev; struct hci_dev* hdev = (struct hci_dev *) skb->dev;
struct vhci_data *vhci; struct vhci_data *data;
if (!hdev) { if (!hdev) {
BT_ERR("Frame for unknown HCI device (hdev=NULL)"); BT_ERR("Frame for unknown HCI device (hdev=NULL)");
...@@ -104,15 +104,15 @@ static int vhci_send_frame(struct sk_buff *skb) ...@@ -104,15 +104,15 @@ static int vhci_send_frame(struct sk_buff *skb)
if (!test_bit(HCI_RUNNING, &hdev->flags)) if (!test_bit(HCI_RUNNING, &hdev->flags))
return -EBUSY; return -EBUSY;
vhci = hdev->driver_data; data = hdev->driver_data;
memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
skb_queue_tail(&vhci->readq, skb); skb_queue_tail(&data->readq, skb);
if (vhci->flags & VHCI_FASYNC) if (data->flags & VHCI_FASYNC)
kill_fasync(&vhci->fasync, SIGIO, POLL_IN); kill_fasync(&data->fasync, SIGIO, POLL_IN);
wake_up_interruptible(&vhci->read_wait); wake_up_interruptible(&data->read_wait);
return 0; return 0;
} }
...@@ -122,7 +122,7 @@ static void vhci_destruct(struct hci_dev *hdev) ...@@ -122,7 +122,7 @@ static void vhci_destruct(struct hci_dev *hdev)
kfree(hdev->driver_data); kfree(hdev->driver_data);
} }
static inline ssize_t vhci_get_user(struct vhci_data *vhci, static inline ssize_t vhci_get_user(struct vhci_data *data,
const char __user *buf, size_t count) const char __user *buf, size_t count)
{ {
struct sk_buff *skb; struct sk_buff *skb;
...@@ -139,7 +139,7 @@ static inline ssize_t vhci_get_user(struct vhci_data *vhci, ...@@ -139,7 +139,7 @@ static inline ssize_t vhci_get_user(struct vhci_data *vhci,
return -EFAULT; return -EFAULT;
} }
skb->dev = (void *) vhci->hdev; skb->dev = (void *) data->hdev;
bt_cb(skb)->pkt_type = *((__u8 *) skb->data); bt_cb(skb)->pkt_type = *((__u8 *) skb->data);
skb_pull(skb, 1); skb_pull(skb, 1);
...@@ -148,7 +148,7 @@ static inline ssize_t vhci_get_user(struct vhci_data *vhci, ...@@ -148,7 +148,7 @@ static inline ssize_t vhci_get_user(struct vhci_data *vhci,
return count; return count;
} }
static inline ssize_t vhci_put_user(struct vhci_data *vhci, static inline ssize_t vhci_put_user(struct vhci_data *data,
struct sk_buff *skb, char __user *buf, int count) struct sk_buff *skb, char __user *buf, int count)
{ {
char __user *ptr = buf; char __user *ptr = buf;
...@@ -161,42 +161,43 @@ static inline ssize_t vhci_put_user(struct vhci_data *vhci, ...@@ -161,42 +161,43 @@ static inline ssize_t vhci_put_user(struct vhci_data *vhci,
total += len; total += len;
vhci->hdev->stat.byte_tx += len; data->hdev->stat.byte_tx += len;
switch (bt_cb(skb)->pkt_type) { switch (bt_cb(skb)->pkt_type) {
case HCI_COMMAND_PKT: case HCI_COMMAND_PKT:
vhci->hdev->stat.cmd_tx++; data->hdev->stat.cmd_tx++;
break; break;
case HCI_ACLDATA_PKT: case HCI_ACLDATA_PKT:
vhci->hdev->stat.acl_tx++; data->hdev->stat.acl_tx++;
break; break;
case HCI_SCODATA_PKT: case HCI_SCODATA_PKT:
vhci->hdev->stat.cmd_tx++; data->hdev->stat.cmd_tx++;
break; break;
}; };
return total; return total;
} }
static loff_t vhci_llseek(struct file * file, loff_t offset, int origin) static loff_t vhci_llseek(struct file *file, loff_t offset, int origin)
{ {
return -ESPIPE; return -ESPIPE;
} }
static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, loff_t *pos) static ssize_t vhci_read(struct file *file,
char __user *buf, size_t count, loff_t *pos)
{ {
DECLARE_WAITQUEUE(wait, current); DECLARE_WAITQUEUE(wait, current);
struct vhci_data *vhci = file->private_data; struct vhci_data *data = file->private_data;
struct sk_buff *skb; struct sk_buff *skb;
ssize_t ret = 0; ssize_t ret = 0;
add_wait_queue(&vhci->read_wait, &wait); add_wait_queue(&data->read_wait, &wait);
while (count) { while (count) {
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
skb = skb_dequeue(&vhci->readq); skb = skb_dequeue(&data->readq);
if (!skb) { if (!skb) {
if (file->f_flags & O_NONBLOCK) { if (file->f_flags & O_NONBLOCK) {
ret = -EAGAIN; ret = -EAGAIN;
...@@ -213,7 +214,7 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo ...@@ -213,7 +214,7 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo
} }
if (access_ok(VERIFY_WRITE, buf, count)) if (access_ok(VERIFY_WRITE, buf, count))
ret = vhci_put_user(vhci, skb, buf, count); ret = vhci_put_user(data, skb, buf, count);
else else
ret = -EFAULT; ret = -EFAULT;
...@@ -221,7 +222,7 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo ...@@ -221,7 +222,7 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo
break; break;
} }
set_current_state(TASK_RUNNING); set_current_state(TASK_RUNNING);
remove_wait_queue(&vhci->read_wait, &wait); remove_wait_queue(&data->read_wait, &wait);
return ret; return ret;
} }
...@@ -229,21 +230,21 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo ...@@ -229,21 +230,21 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo
static ssize_t vhci_write(struct file *file, static ssize_t vhci_write(struct file *file,
const char __user *buf, size_t count, loff_t *pos) const char __user *buf, size_t count, loff_t *pos)
{ {
struct vhci_data *vhci = file->private_data; struct vhci_data *data = file->private_data;
if (!access_ok(VERIFY_READ, buf, count)) if (!access_ok(VERIFY_READ, buf, count))
return -EFAULT; return -EFAULT;
return vhci_get_user(vhci, buf, count); return vhci_get_user(data, buf, count);
} }
static unsigned int vhci_poll(struct file *file, poll_table *wait) static unsigned int vhci_poll(struct file *file, poll_table *wait)
{ {
struct vhci_data *vhci = file->private_data; struct vhci_data *data = file->private_data;
poll_wait(file, &vhci->read_wait, wait); poll_wait(file, &data->read_wait, wait);
if (!skb_queue_empty(&vhci->readq)) if (!skb_queue_empty(&data->readq))
return POLLIN | POLLRDNORM; return POLLIN | POLLRDNORM;
return POLLOUT | POLLWRNORM; return POLLOUT | POLLWRNORM;
...@@ -257,26 +258,26 @@ static int vhci_ioctl(struct inode *inode, struct file *file, ...@@ -257,26 +258,26 @@ static int vhci_ioctl(struct inode *inode, struct file *file,
static int vhci_open(struct inode *inode, struct file *file) static int vhci_open(struct inode *inode, struct file *file)
{ {
struct vhci_data *vhci; struct vhci_data *data;
struct hci_dev *hdev; struct hci_dev *hdev;
vhci = kzalloc(sizeof(struct vhci_data), GFP_KERNEL); data = kzalloc(sizeof(struct vhci_data), GFP_KERNEL);
if (!vhci) if (!data)
return -ENOMEM; return -ENOMEM;
skb_queue_head_init(&vhci->readq); skb_queue_head_init(&data->readq);
init_waitqueue_head(&vhci->read_wait); init_waitqueue_head(&data->read_wait);
hdev = hci_alloc_dev(); hdev = hci_alloc_dev();
if (!hdev) { if (!hdev) {
kfree(vhci); kfree(data);
return -ENOMEM; return -ENOMEM;
} }
vhci->hdev = hdev; data->hdev = hdev;
hdev->type = HCI_VHCI; hdev->type = HCI_VHCI;
hdev->driver_data = vhci; hdev->driver_data = data;
hdev->open = vhci_open_dev; hdev->open = vhci_open_dev;
hdev->close = vhci_close_dev; hdev->close = vhci_close_dev;
...@@ -288,20 +289,20 @@ static int vhci_open(struct inode *inode, struct file *file) ...@@ -288,20 +289,20 @@ static int vhci_open(struct inode *inode, struct file *file)
if (hci_register_dev(hdev) < 0) { if (hci_register_dev(hdev) < 0) {
BT_ERR("Can't register HCI device"); BT_ERR("Can't register HCI device");
kfree(vhci); kfree(data);
hci_free_dev(hdev); hci_free_dev(hdev);
return -EBUSY; return -EBUSY;
} }
file->private_data = vhci; file->private_data = data;
return nonseekable_open(inode, file); return nonseekable_open(inode, file);
} }
static int vhci_release(struct inode *inode, struct file *file) static int vhci_release(struct inode *inode, struct file *file)
{ {
struct vhci_data *vhci = file->private_data; struct vhci_data *data = file->private_data;
struct hci_dev *hdev = vhci->hdev; struct hci_dev *hdev = data->hdev;
if (hci_unregister_dev(hdev) < 0) { if (hci_unregister_dev(hdev) < 0) {
BT_ERR("Can't unregister HCI device %s", hdev->name); 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,17 +317,17 @@ static int vhci_release(struct inode *inode, struct file *file)
static int vhci_fasync(int fd, struct file *file, int on) static int vhci_fasync(int fd, struct file *file, int on)
{ {
struct vhci_data *vhci = file->private_data; struct vhci_data *data = file->private_data;
int err; int err;
err = fasync_helper(fd, file, on, &vhci->fasync); err = fasync_helper(fd, file, on, &data->fasync);
if (err < 0) if (err < 0)
return err; return err;
if (on) if (on)
vhci->flags |= VHCI_FASYNC; data->flags |= VHCI_FASYNC;
else else
vhci->flags &= ~VHCI_FASYNC; data->flags &= ~VHCI_FASYNC;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment