Skip to content

Commit 6b441fa

Browse files
David HerrmannGustavo F. Padovan
authored andcommitted
Bluetooth: bfusb: Fix error path on firmware load
When loading the usb-configuration we do not signal the end of configuration on memory allocation error. This patch moves the memory allocation to the top so every error path uses "goto error" now to correctly send the usb-ctrl message when detecting some error. This also replaces GFP_ATOMIC with GFP_KERNEL as we are allowed to sleep here. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com> Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
1 parent b91a4e3 commit 6b441fa

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎drivers/bluetooth/bfusb.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -568,22 +568,23 @@ static int bfusb_load_firmware(struct bfusb_data *data,
568568

569569
BT_INFO("BlueFRITZ! USB loading firmware");
570570

571+
buf = kmalloc(BFUSB_MAX_BLOCK_SIZE + 3, GFP_KERNEL);
572+
if (!buf) {
573+
BT_ERR("Can't allocate memory chunk for firmware");
574+
return -ENOMEM;
575+
}
576+
571577
pipe = usb_sndctrlpipe(data->udev, 0);
572578

573579
if (usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,
574580
0, 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT) < 0) {
575581
BT_ERR("Can't change to loading configuration");
582+
kfree(buf);
576583
return -EBUSY;
577584
}
578585

579586
data->udev->toggle[0] = data->udev->toggle[1] = 0;
580587

581-
buf = kmalloc(BFUSB_MAX_BLOCK_SIZE + 3, GFP_ATOMIC);
582-
if (!buf) {
583-
BT_ERR("Can't allocate memory chunk for firmware");
584-
return -ENOMEM;
585-
}
586-
587588
pipe = usb_sndbulkpipe(data->udev, data->bulk_out_ep);
588589

589590
while (count) {

0 commit comments

Comments
 (0)