diff options
Diffstat (limited to 'drivers/bluetooth/bfusb.c')
| -rw-r--r-- | drivers/bluetooth/bfusb.c | 115 | 
1 files changed, 36 insertions, 79 deletions
diff --git a/drivers/bluetooth/bfusb.c b/drivers/bluetooth/bfusb.c index 005919ab043..b2e7e94a677 100644 --- a/drivers/bluetooth/bfusb.c +++ b/drivers/bluetooth/bfusb.c @@ -42,7 +42,7 @@  static struct usb_driver bfusb_driver; -static struct usb_device_id bfusb_table[] = { +static const struct usb_device_id bfusb_table[] = {  	/* AVM BlueFRITZ! USB */  	{ USB_DEVICE(0x057c, 0x2200) }, @@ -131,8 +131,11 @@ static int bfusb_send_bulk(struct bfusb_data *data, struct sk_buff *skb)  	BT_DBG("bfusb %p skb %p len %d", data, skb, skb->len); -	if (!urb && !(urb = usb_alloc_urb(0, GFP_ATOMIC))) -		return -ENOMEM; +	if (!urb) { +		urb = usb_alloc_urb(0, GFP_ATOMIC); +		if (!urb) +			return -ENOMEM; +	}  	pipe = usb_sndbulkpipe(data->udev, data->bulk_out_ep); @@ -218,8 +221,11 @@ static int bfusb_rx_submit(struct bfusb_data *data, struct urb *urb)  	BT_DBG("bfusb %p urb %p", data, urb); -	if (!urb && !(urb = usb_alloc_urb(0, GFP_ATOMIC))) -		return -ENOMEM; +	if (!urb) { +		urb = usb_alloc_urb(0, GFP_ATOMIC); +		if (!urb) +			return -ENOMEM; +	}  	skb = bt_skb_alloc(size, GFP_ATOMIC);  	if (!skb) { @@ -318,7 +324,6 @@ static inline int bfusb_recv_block(struct bfusb_data *data, int hdr, unsigned ch  			return -ENOMEM;  		} -		skb->dev = (void *) data->hdev;  		bt_cb(skb)->pkt_type = pkt_type;  		data->reassembly = skb; @@ -333,7 +338,7 @@ static inline int bfusb_recv_block(struct bfusb_data *data, int hdr, unsigned ch  		memcpy(skb_put(data->reassembly, len), buf, len);  	if (hdr & 0x08) { -		hci_recv_frame(data->reassembly); +		hci_recv_frame(data->hdev, data->reassembly);  		data->reassembly = NULL;  	} @@ -411,7 +416,7 @@ unlock:  static int bfusb_open(struct hci_dev *hdev)  { -	struct bfusb_data *data = hdev->driver_data; +	struct bfusb_data *data = hci_get_drvdata(hdev);  	unsigned long flags;  	int i, err; @@ -437,7 +442,7 @@ static int bfusb_open(struct hci_dev *hdev)  static int bfusb_flush(struct hci_dev *hdev)  { -	struct bfusb_data *data = hdev->driver_data; +	struct bfusb_data *data = hci_get_drvdata(hdev);  	BT_DBG("hdev %p bfusb %p", hdev, data); @@ -448,7 +453,7 @@ static int bfusb_flush(struct hci_dev *hdev)  static int bfusb_close(struct hci_dev *hdev)  { -	struct bfusb_data *data = hdev->driver_data; +	struct bfusb_data *data = hci_get_drvdata(hdev);  	unsigned long flags;  	BT_DBG("hdev %p bfusb %p", hdev, data); @@ -465,26 +470,18 @@ static int bfusb_close(struct hci_dev *hdev)  	return 0;  } -static int bfusb_send_frame(struct sk_buff *skb) +static int bfusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb)  { -	struct hci_dev *hdev = (struct hci_dev *) skb->dev; -	struct bfusb_data *data; +	struct bfusb_data *data = hci_get_drvdata(hdev);  	struct sk_buff *nskb;  	unsigned char buf[3];  	int sent = 0, size, count;  	BT_DBG("hdev %p skb %p type %d len %d", hdev, skb, bt_cb(skb)->pkt_type, skb->len); -	if (!hdev) { -		BT_ERR("Frame for unknown HCI device (hdev=NULL)"); -		return -ENODEV; -	} -  	if (!test_bit(HCI_RUNNING, &hdev->flags))  		return -EBUSY; -	data = hdev->driver_data; -  	switch (bt_cb(skb)->pkt_type) {  	case HCI_COMMAND_PKT:  		hdev->stat.cmd_tx++; @@ -544,20 +541,6 @@ static int bfusb_send_frame(struct sk_buff *skb)  	return 0;  } -static void bfusb_destruct(struct hci_dev *hdev) -{ -	struct bfusb_data *data = hdev->driver_data; - -	BT_DBG("hdev %p bfusb %p", hdev, data); - -	kfree(data); -} - -static int bfusb_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg) -{ -	return -ENOIOCTLCMD; -} -  static int bfusb_load_firmware(struct bfusb_data *data,  			       const unsigned char *firmware, int count)  { @@ -568,22 +551,23 @@ static int bfusb_load_firmware(struct bfusb_data *data,  	BT_INFO("BlueFRITZ! USB loading firmware"); +	buf = kmalloc(BFUSB_MAX_BLOCK_SIZE + 3, GFP_KERNEL); +	if (!buf) { +		BT_ERR("Can't allocate memory chunk for firmware"); +		return -ENOMEM; +	} +  	pipe = usb_sndctrlpipe(data->udev, 0);  	if (usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,  				0, 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT) < 0) {  		BT_ERR("Can't change to loading configuration"); +		kfree(buf);  		return -EBUSY;  	}  	data->udev->toggle[0] = data->udev->toggle[1] = 0; -	buf = kmalloc(BFUSB_MAX_BLOCK_SIZE + 3, GFP_ATOMIC); -	if (!buf) { -		BT_ERR("Can't allocate memory chunk for firmware"); -		return -ENOMEM; -	} -  	pipe = usb_sndbulkpipe(data->udev, data->bulk_out_ep);  	while (count) { @@ -661,7 +645,7 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i  	}  	/* Initialize control structure and load firmware */ -	data = kzalloc(sizeof(struct bfusb_data), GFP_KERNEL); +	data = devm_kzalloc(&intf->dev, sizeof(struct bfusb_data), GFP_KERNEL);  	if (!data) {  		BT_ERR("Can't allocate memory for control structure");  		goto done; @@ -682,7 +666,7 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i  	if (request_firmware(&firmware, "bfubase.frm", &udev->dev) < 0) {  		BT_ERR("Firmware request failed"); -		goto error; +		goto done;  	}  	BT_DBG("firmware data %p size %zu", firmware->data, firmware->size); @@ -698,28 +682,24 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i  	hdev = hci_alloc_dev();  	if (!hdev) {  		BT_ERR("Can't allocate HCI device"); -		goto error; +		goto done;  	}  	data->hdev = hdev;  	hdev->bus = HCI_USB; -	hdev->driver_data = data; +	hci_set_drvdata(hdev, data);  	SET_HCIDEV_DEV(hdev, &intf->dev); -	hdev->open     = bfusb_open; -	hdev->close    = bfusb_close; -	hdev->flush    = bfusb_flush; -	hdev->send     = bfusb_send_frame; -	hdev->destruct = bfusb_destruct; -	hdev->ioctl    = bfusb_ioctl; - -	hdev->owner = THIS_MODULE; +	hdev->open  = bfusb_open; +	hdev->close = bfusb_close; +	hdev->flush = bfusb_flush; +	hdev->send  = bfusb_send_frame;  	if (hci_register_dev(hdev) < 0) {  		BT_ERR("Can't register HCI device");  		hci_free_dev(hdev); -		goto error; +		goto done;  	}  	usb_set_intfdata(intf, data); @@ -729,9 +709,6 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i  release:  	release_firmware(firmware); -error: -	kfree(data); -  done:  	return -EIO;  } @@ -750,9 +727,7 @@ static void bfusb_disconnect(struct usb_interface *intf)  	bfusb_close(hdev); -	if (hci_unregister_dev(hdev) < 0) -		BT_ERR("Can't unregister HCI device %s", hdev->name); - +	hci_unregister_dev(hdev);  	hci_free_dev(hdev);  } @@ -761,28 +736,10 @@ static struct usb_driver bfusb_driver = {  	.probe		= bfusb_probe,  	.disconnect	= bfusb_disconnect,  	.id_table	= bfusb_table, +	.disable_hub_initiated_lpm = 1,  }; -static int __init bfusb_init(void) -{ -	int err; - -	BT_INFO("BlueFRITZ! USB driver ver %s", VERSION); - -	err = usb_register(&bfusb_driver); -	if (err < 0) -		BT_ERR("Failed to register BlueFRITZ! USB driver"); - -	return err; -} - -static void __exit bfusb_exit(void) -{ -	usb_deregister(&bfusb_driver); -} - -module_init(bfusb_init); -module_exit(bfusb_exit); +module_usb_driver(bfusb_driver);  MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");  MODULE_DESCRIPTION("BlueFRITZ! USB driver ver " VERSION);  | 
