mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-30 13:23:02 -04:00
ALSA: 6fire: Use auto-cleanup for firmware loading
Clean up the code for managing the firmware loading in the 6fire driver with __free(firmware) and __free(kfree), so that the loaded firmware and the name string are cleaned up automatically. Only the code refactoring, no functional changes. Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20260729083735.120219-2-tiwai@suse.de
This commit is contained in:
@@ -194,23 +194,20 @@ static int usb6fire_fw_ezusb_upload(
|
||||
int ret;
|
||||
u8 data;
|
||||
struct usb_device *device = interface_to_usbdev(intf);
|
||||
const struct firmware *fw = NULL;
|
||||
struct ihex_record *rec = kmalloc_obj(struct ihex_record);
|
||||
struct ihex_record *rec __free(kfree) = kmalloc_obj(struct ihex_record);
|
||||
|
||||
if (!rec)
|
||||
return -ENOMEM;
|
||||
|
||||
const struct firmware *fw __free(firmware) = NULL;
|
||||
ret = request_firmware(&fw, fwname, &device->dev);
|
||||
if (ret < 0) {
|
||||
kfree(rec);
|
||||
dev_err(&intf->dev,
|
||||
"error requesting ezusb firmware %s.\n", fwname);
|
||||
return ret;
|
||||
}
|
||||
ret = usb6fire_fw_ihex_init(fw, rec);
|
||||
if (ret < 0) {
|
||||
kfree(rec);
|
||||
release_firmware(fw);
|
||||
dev_err(&intf->dev,
|
||||
"error validating ezusb firmware %s.\n", fwname);
|
||||
return ret;
|
||||
@@ -219,8 +216,6 @@ static int usb6fire_fw_ezusb_upload(
|
||||
data = 0x01; /* stop ezusb cpu */
|
||||
ret = usb6fire_fw_ezusb_write(device, 0xa0, 0xe600, &data, 1);
|
||||
if (ret) {
|
||||
kfree(rec);
|
||||
release_firmware(fw);
|
||||
dev_err(&intf->dev,
|
||||
"unable to upload ezusb firmware %s: begin message.\n",
|
||||
fwname);
|
||||
@@ -231,8 +226,6 @@ static int usb6fire_fw_ezusb_upload(
|
||||
ret = usb6fire_fw_ezusb_write(device, 0xa0, rec->address,
|
||||
rec->data, rec->len);
|
||||
if (ret) {
|
||||
kfree(rec);
|
||||
release_firmware(fw);
|
||||
dev_err(&intf->dev,
|
||||
"unable to upload ezusb firmware %s: data urb.\n",
|
||||
fwname);
|
||||
@@ -240,8 +233,6 @@ static int usb6fire_fw_ezusb_upload(
|
||||
}
|
||||
}
|
||||
|
||||
release_firmware(fw);
|
||||
kfree(rec);
|
||||
if (postdata) { /* write data after firmware has been uploaded */
|
||||
ret = usb6fire_fw_ezusb_write(device, 0xa0, postaddr,
|
||||
postdata, postlen);
|
||||
@@ -270,19 +261,18 @@ static int usb6fire_fw_fpga_upload(
|
||||
int ret;
|
||||
int i;
|
||||
struct usb_device *device = interface_to_usbdev(intf);
|
||||
u8 *buffer = kmalloc(FPGA_BUFSIZE, GFP_KERNEL);
|
||||
u8 *buffer __free(kfree) = kmalloc(FPGA_BUFSIZE, GFP_KERNEL);
|
||||
const char *c;
|
||||
const char *end;
|
||||
const struct firmware *fw;
|
||||
|
||||
if (!buffer)
|
||||
return -ENOMEM;
|
||||
|
||||
const struct firmware *fw __free(firmware) = NULL;
|
||||
ret = request_firmware(&fw, fwname, &device->dev);
|
||||
if (ret < 0) {
|
||||
dev_err(&intf->dev, "unable to get fpga firmware %s.\n",
|
||||
fwname);
|
||||
kfree(buffer);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
@@ -291,8 +281,6 @@ static int usb6fire_fw_fpga_upload(
|
||||
|
||||
ret = usb6fire_fw_ezusb_write(device, 8, 0, NULL, 0);
|
||||
if (ret) {
|
||||
kfree(buffer);
|
||||
release_firmware(fw);
|
||||
dev_err(&intf->dev,
|
||||
"unable to upload fpga firmware: begin urb.\n");
|
||||
return ret;
|
||||
@@ -304,15 +292,11 @@ static int usb6fire_fw_fpga_upload(
|
||||
|
||||
ret = usb6fire_fw_fpga_write(device, buffer, i);
|
||||
if (ret < 0) {
|
||||
release_firmware(fw);
|
||||
kfree(buffer);
|
||||
dev_err(&intf->dev,
|
||||
"unable to upload fpga firmware: fw urb.\n");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
release_firmware(fw);
|
||||
kfree(buffer);
|
||||
|
||||
ret = usb6fire_fw_ezusb_write(device, 9, 0, NULL, 0);
|
||||
if (ret) {
|
||||
|
||||
Reference in New Issue
Block a user