Skip to contentSkip to conversation

Bluetooth: bfusb: Fix error path on firmware load

PATCH Applied David Herrmann 3 participants 3 messages Oct 26, 2011 – Oct 31, 2011 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 drivers/bluetooth/bfusb.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
drivers/bluetooth/bfusb.c +7 -6
index 6580d50..a936763 100644
@@ -568,22 +568,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) {
Signature · 1 line
1.7.7.1
maintainer Acked-by on v1 1/1
#1 lore raw

Hi David,

Quoted 11 lines

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.

---
 drivers/bluetooth/bfusb.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

Regards

Marcel

#2 lore raw
In reply to David Herrmann

Hi David,

Quoted 11 lines · David Herrmann

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.

---
 drivers/bluetooth/bfusb.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

Applied, thanks.

Gustavo