ALSA: Use auto-cleanup for firmware loading
Subsystems (2)
cover ALSA: Use auto-cleanup for firmware loading
This is a series of trivial patches that replace the manual release_firmware() calls with the auto-cleanup via __free(firmware).
It doesn't cover all drivers but just a few as a start.
Takashi
===
Takashi Iwai (14):
ALSA: 6fire: Use auto-cleanup for firmware loading
ALSA: hda: ca0132: Use auto-cleanup for firmware loading
ALSA: hda: intel: Use auto-cleanup for firmware loading
ALSA: msnd: Use auto-cleanup for firmware loading
ALSA: hda: cs35l41: Use auto-cleanup for firmware loading
ALSA: hda: cs35l56: Use auto-cleanup for firmware loading
ALSA: sscape: Use auto-cleanup for firmware loading
ALSA: wavefront: Use auto-cleanup for firmware loading
ALSA: asihpi: Use auto-cleanup for firmware loading
ALSA: cs46xx: Use auto-cleanup for firmware loading
ALSA: korg1212: Use auto-cleanup for firmware loading
ALSA: mixart: Use auto-cleanup for firmware loading
ALSA: pcxhr: Use auto-cleanup for firmware loading
ALSA: sh: Use auto-cleanup for firmware loading
sound/hda/codecs/ca0132.c | 12 ++------ sound/hda/codecs/side-codecs/cs35l41_hda.c | 33 ++++++++------------ sound/hda/codecs/side-codecs/cs35l56_hda.c | 35 ++++++---------------- sound/hda/controllers/intel.c | 3 +- sound/isa/msnd/msnd_pinnacle.c | 18 ++++------- sound/isa/sscape.c | 8 ++--- sound/isa/wavefront/wavefront_fx.c | 23 +++++--------- sound/isa/wavefront/wavefront_synth.c | 4 +-- sound/pci/asihpi/hpidspcd.c | 18 +++++------ sound/pci/cs46xx/cs46xx_lib.c | 30 +++++++------------ sound/pci/korg1212/korg1212.c | 8 ++--- sound/pci/mixart/mixart_hwdep.c | 4 +-- sound/pci/pcxhr/pcxhr_hwdep.c | 3 +- sound/sh/aica.c | 4 +-- sound/usb/6fire/firmware.c | 24 +++------------ 15 files changed, 69 insertions(+), 158 deletions(-)
Signature · 1 line
2.55.0
PATCH 1/14 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.
--- sound/usb/6fire/firmware.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-)
sound/usb/6fire/firmware.c +4 -20
@@ -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) {
Signature · 1 line
2.55.0
PATCH 2/14 ALSA: hda: ca0132: Use auto-cleanup for firmware loading
In reply to Takashi IwaiSimplify the code to manage the firmware loading with __free(firmware) auto-cleanup.
Only the code refactoring, no functional changes.
--- sound/hda/codecs/ca0132.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
sound/hda/codecs/ca0132.c +3 -9
@@ -8530,10 +8530,9 @@ static void ca0132_set_dsp_msr(struct hda_codec *codec, bool is96k)static bool ca0132_download_dsp_images (struct hda_codec *codec) { -bool dsp_loaded = false;struct ca0132_spec *spec = codec->spec;const struct dsp_image_seg *dsp_os_image; -const struct firmware *fw_entry =NULL ; + const struct firmware *fw_entry __free(firmware) = NULL;/* * Alternate firmwares for different variants. The Recon3Di apparently * can use the default firmware, but I'll leave the option in case
@@ -8573,15 +8572,10 @@ static bool ca0132_download_dsp_images(struct hda_codec *codec) dsp_os_image = (struct dsp_image_seg *)(fw_entry->data);if (dspload_image (codec, dsp_os_image,0 ,0 , true,0 )) {codec_err (codec,"ca0132 DSP load image failed\n" ); - goto exit_download; +return false; } - dsp_loaded =dspload_wait_loaded (codec); - -exit_download: -release_firmware (fw_entry); - -return dsp_loaded; +return dspload_wait_loaded (codec); }static void ca0132_download_dsp (struct hda_codec *codec)
Signature · 1 line
2.55.0
PATCH 3/14 ALSA: hda: intel: Use auto-cleanup for firmware loading
In reply to Takashi IwaiSimplify the code to manage the firmware loading with __free(firmware) auto-cleanup.
Only the code refactoring, no functional changes.
--- sound/hda/controllers/intel.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sound/hda/controllers/intel.c +1 -2
@@ -2387,7 +2387,7 @@ static int azx_probe_continue(struct azx *chip)#ifdef CONFIG_SND_HDA_PATCH_LOADER if (patch[dev] && *patch[dev]) { -const struct firmware *fw =NULL ; + const struct firmware *fw __free(firmware) = NULL;dev_info (&pci->dev,"Applying patch firmware '%s'\n" , patch[dev]);
@@ -2396,7 +2396,6 @@ static int azx_probe_continue(struct azx *chip) "Cannot load firmware, continue without patching\n"); }else { err =snd_hda_load_patch (&chip->bus, fw->size, fw->data); -release_firmware (fw);if (err <0 ) goto out_free; }
Signature · 1 line
2.55.0
PATCH 4/14 ALSA: msnd: Use auto-cleanup for firmware loading
In reply to Takashi IwaiSimplify the code to manage the firmware loading with __free(firmware) auto-cleanup.
Only the code refactoring, no functional changes.
--- sound/isa/msnd/msnd_pinnacle.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
sound/isa/msnd/msnd_pinnacle.c +6 -12
@@ -367,7 +367,8 @@ static int snd_msnd_init_sma(struct snd_msnd *chip)static int upload_dsp_code (struct snd_card *card) {struct snd_msnd *chip = card->private_data; -const struct firmware *init_fw =NULL , *perm_fw =NULL ; + const struct firmware *init_fw __free(firmware) = NULL; + const struct firmware *perm_fw __free(firmware) = NULL;int err;outb (HPBLKSEL_0 , chip->io +HP_BLKS );
@@ -375,28 +376,21 @@ static int upload_dsp_code(struct snd_card *card) err =request_firmware (&init_fw,INITCODEFILE , card->dev);if (err <0 ) {dev_err (card->dev,LOGNAME ": Error loading " INITCODEFILE ); - goto cleanup1; +return err; } err =request_firmware (&perm_fw,PERMCODEFILE , card->dev);if (err <0 ) {dev_err (card->dev,LOGNAME ": Error loading " PERMCODEFILE ); - goto cleanup; +return err; }memcpy_toio (chip->mappedbase, perm_fw->data, perm_fw->size);if (snd_msnd_upload_host (chip, init_fw->data, init_fw->size) <0 ) {dev_warn (card->dev,LOGNAME ": Error uploading to DSP\n" ); - err = -ENODEV ; - goto cleanup; +return -ENODEV ; }dev_info (card->dev,LOGNAME ": DSP firmware uploaded\n" ); - err =0 ; - -cleanup: -release_firmware (perm_fw); -cleanup1: -release_firmware (init_fw); -return err; +return 0 ; }#ifdef MSND_CLASSIC
Signature · 1 line
2.55.0
PATCH 5/14 ALSA: hda: cs35l41: Use auto-cleanup for firmware loading
In reply to Takashi IwaiSimplify the code to manage the firmware loading with auto-cleanup with __free(firmware). A NULL clear is added at cs35l41_request_firmware_file() for avoiding the double-free.
Note that the driver still keeps a few manual firmware releases because it retries with different firmware files when one of firmware pairs fails.
Only the code refactoring, no functional changes.
--- sound/hda/codecs/side-codecs/cs35l41_hda.c | 33 ++++++++-------------- 1 file changed, 12 insertions(+), 21 deletions(-)
sound/hda/codecs/side-codecs/cs35l41_hda.c +12 -21
@@ -170,6 +170,7 @@ static int cs35l41_request_firmware_file(struct cs35l41_hda *cs35l41,char *s, c;int ret =0 ; + *firmware =NULL ;if (spkid >-1 && ssid && amp_name) *filename = kasprintf(GFP_KERNEL, "cirrus/%s-%s-%s-%s-spkid%d-%s.%s", CS35L41_PART, dsp_name, cs35l41_hda_fw_ids[cs35l41->firmware_type],
@@ -528,8 +529,8 @@ static int cs35l41_read_tuning_params(struct cs35l41_hda *cs35l41, const structstatic int cs35l41_load_tuning_params (struct cs35l41_hda *cs35l41,char *tuning_filename) { -const struct firmware *tuning_param_file =NULL ; -char *tuning_param_filename =NULL ; + const struct firmware *tuning_param_file __free(firmware) = NULL; + char *tuning_param_filename __free(kfree) = NULL;int ret; ret = cs35l41_request_tuning_param_file(cs35l41, tuning_filename, &tuning_param_file,
@@ -548,19 +549,16 @@ static int cs35l41_load_tuning_params(struct cs35l41_hda *cs35l41, char *tuning_cs35l41_set_default_tuning_params (cs35l41); } -release_firmware (tuning_param_file); -kfree (tuning_param_filename); -return ret; }static int cs35l41_init_dsp (struct cs35l41_hda *cs35l41) { -const struct firmware *coeff_firmware =NULL ; -const struct firmware *wmfw_firmware =NULL ; + const struct firmware *coeff_firmware __free(firmware) = NULL; + const struct firmware *wmfw_firmware __free(firmware) = NULL;struct cs_dsp *dsp = &cs35l41->cs_dsp; -char *coeff_filename =NULL ; -char *wmfw_filename =NULL ; + char *coeff_filename __free(kfree) = NULL; + char *wmfw_filename __free(kfree) = NULL;int ret;if (!cs35l41->halo_initialized) {
@@ -592,20 +590,13 @@ static int cs35l41_init_dsp(struct cs35l41_hda *cs35l41) ret =cs_dsp_power_up (dsp, wmfw_firmware, wmfw_filename, coeff_firmware, coeff_filename, cs35l41_hda_fw_ids[cs35l41->firmware_type]); -if (ret) - goto err; +if (ret) { +cs35l41_set_default_tuning_params (cs35l41); +return ret; + }cs35l41_hda_apply_calibration (cs35l41); - -err: -if (ret) -cs35l41_set_default_tuning_params (cs35l41); -release_firmware (wmfw_firmware); -release_firmware (coeff_firmware); -kfree (wmfw_filename); -kfree (coeff_filename); - -return ret; +return 0 ; }static void cs35l41_shutdown_dsp (struct cs35l41_hda *cs35l41)
Signature · 1 line
2.55.0
PATCH 6/14 ALSA: hda: cs35l56: Use auto-cleanup for firmware loading
In reply to Takashi IwaiSimplify the code to manage the firmware loading with auto-cleanup. By the use of __free(firmware), we can replace the manual mutex locks with guard() gracefully, too.
Only the code refactoring, no functional changes.
--- sound/hda/codecs/side-codecs/cs35l56_hda.c | 35 ++++++---------------- 1 file changed, 9 insertions(+), 26 deletions(-)
sound/hda/codecs/side-codecs/cs35l56_hda.c +9 -26
@@ -527,18 +527,6 @@ static void cs35l56_hda_request_firmware_files(struct cs35l56_hda *cs35l56, base_name, NULL, NULL, "bin"); } -static void cs35l56_hda_release_firmware_files (const struct firmware *wmfw_firmware, -char *wmfw_filename, -const struct firmware *coeff_firmware, -char *coeff_filename) -{ -release_firmware (wmfw_firmware); -kfree (wmfw_filename); - -release_firmware (coeff_firmware); -kfree (coeff_filename); -} -static int cs35l56_hda_apply_calibration (struct cs35l56_hda *cs35l56) {int ret;
@@ -561,10 +549,10 @@ static int cs35l56_hda_apply_calibration(struct cs35l56_hda *cs35l56)static void cs35l56_hda_fw_load (struct cs35l56_hda *cs35l56) { -const struct firmware *coeff_firmware =NULL ; -const struct firmware *wmfw_firmware =NULL ; -char *coeff_filename =NULL ; -char *wmfw_filename =NULL ; + const struct firmware *coeff_firmware __free(firmware) = NULL; + const struct firmware *wmfw_firmware __free(firmware) = NULL; + char *coeff_filename __free(kfree) = NULL; + char *wmfw_filename __free(kfree) = NULL;unsigned int preloaded_fw_ver;bool firmware_missing;int ret;
@@ -606,14 +594,14 @@ static void cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56)if (firmware_missing) {if (!wmfw_firmware) {dev_err (cs35l56->base.dev,".%s file required but not found\n" ,"wmfw" ); - goto err_fw_release; +return ; }else if (!coeff_firmware) {dev_err (cs35l56->base.dev,".%s file required but not found\n" ,"bin" ); - goto err_fw_release; +return ; } } -mutex_lock (&cs35l56->base.irq_lock); +guard (mutex)(&cs35l56->base.irq_lock);/* * If the firmware hasn't been patched it must be shutdown before
@@ -624,14 +612,14 @@ static void cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56)if (firmware_missing && (wmfw_firmware || coeff_firmware)) { ret =cs35l56_firmware_shutdown (&cs35l56->base);if (ret) - goto err; +return ; } ret =cs_dsp_power_up (&cs35l56->cs_dsp, wmfw_firmware, wmfw_filename, coeff_firmware, coeff_filename,"misc" );if (ret) {dev_dbg (cs35l56->base.dev,"%s: cs_dsp_power_up ret %d\n" , __func__, ret); - goto err; +return ; }if (wmfw_filename)
@@ -679,11 +667,6 @@ static void cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56) err_powered_up:if (!cs35l56->base.fw_patched)cs_dsp_power_down (&cs35l56->cs_dsp); -err: -mutex_unlock (&cs35l56->base.irq_lock); -err_fw_release: -cs35l56_hda_release_firmware_files (wmfw_firmware, wmfw_filename, - coeff_firmware, coeff_filename); }static void cs35l56_hda_dsp_work (struct work_struct *work)
Signature · 1 line
2.55.0
Re: [PATCH 06/14] ALSA: hda: cs35l56: Use auto-cleanup for firmware loading
Quoted 36 lines · Takashi Iwai
Simplify the code to manage the firmware loading with auto-cleanup. By the use of
__free(firmware), we can replace the manual mutex locks withguard()gracefully, too.Only the code refactoring, no functional changes.
Signed-off-by Takashi Iwai <[email protected]>--- sound/hda/codecs/side-codecs/cs35l56_hda.c | 35 ++++++---------------- 1 file changed, 9 insertions(+), 26 deletions(-)sound/hda/codecs/side-codecs/cs35l56_hda.c +0
-12@@ -527,18 +527,6 @@ static void cs35l56_hda_request_firmware_files(struct cs35l56_hda *cs35l56, base_name, NULL, NULL, "bin"); } -static void cs35l56_hda_release_firmware_files (const struct firmware *wmfw_firmware, -char *wmfw_filename, -const struct firmware *coeff_firmware, -char *coeff_filename) -{ -release_firmware (wmfw_firmware); -kfree (wmfw_filename); - -release_firmware (coeff_firmware); -kfree (coeff_filename); -} -static int cs35l56_hda_apply_calibration (struct cs35l56_hda *cs35l56) {int ret;
sound/hda/codecs/side-codecs/cs35l56_hda.c static int cs35l56_hda_apply_calibration(struct cs35l56_hda *cs35l56) · line 553
Quoted 9 lines
sound/hda/codecs/side-codecs/cs35l56_hda.c +2
-4@@ -561,10 +549,10 @@ static int cs35l56_hda_apply_calibration(struct cs35l56_hda *cs35l56)static void cs35l56_hda_fw_load (struct cs35l56_hda *cs35l56) { -const struct firmware *coeff_firmware =NULL ; -const struct firmware *wmfw_firmware =NULL ; -char *coeff_filename =NULL ; -char *wmfw_filename =NULL ; + const struct firmware *coeff_firmware __free(firmware) = NULL; + const struct firmware *wmfw_firmware __free(firmware) = NULL;
Is it definitely safe to replace release_firmware with kfree? In most cases that is all release_firmware does, but it looks like it does different stuff if someone built the firmware into the kernel?
Thanks,
Charles
Re: [PATCH 06/14] ALSA: hda: cs35l56: Use auto-cleanup for firmware loading
Quoted 39 lines · Charles Keepax
Quoted 37 lines · Takashi Iwai
Simplify the code to manage the firmware loading with auto-cleanup. By the use of
__free(firmware), we can replace the manual mutex locks withguard()gracefully, too.Only the code refactoring, no functional changes.
Signed-off-by Takashi Iwai <[email protected]>--- sound/hda/codecs/side-codecs/cs35l56_hda.c | 35 ++++++---------------- 1 file changed, 9 insertions(+), 26 deletions(-)sound/hda/codecs/side-codecs/cs35l56_hda.c +0
-12@@ -527,18 +527,6 @@ static void cs35l56_hda_request_firmware_files(struct cs35l56_hda *cs35l56, base_name, NULL, NULL, "bin"); } -static void cs35l56_hda_release_firmware_files (const struct firmware *wmfw_firmware, -char *wmfw_filename, -const struct firmware *coeff_firmware, -char *coeff_filename) -{ -release_firmware (wmfw_firmware); -kfree (wmfw_filename); - -release_firmware (coeff_firmware); -kfree (coeff_filename); -} -static int cs35l56_hda_apply_calibration (struct cs35l56_hda *cs35l56) {int ret;@@ -561,10 +549,10 @@ static int cs35l56_hda_apply_calibration(struct cs35l56_hda *cs35l56)
Quoted 13 lines
sound/hda/codecs/side-codecs/cs35l56_hda.c static int cs35l56_hda_apply_calibration(struct cs35l56_hda *cs35l56) · line 553
Quoted 8 lines
sound/hda/codecs/side-codecs/cs35l56_hda.c +2
-4static void cs35l56_hda_fw_load (struct cs35l56_hda *cs35l56) { -const struct firmware *coeff_firmware =NULL ; -const struct firmware *wmfw_firmware =NULL ; -char *coeff_filename =NULL ; -char *wmfw_filename =NULL ; + const struct firmware *coeff_firmware __free(firmware) = NULL; + const struct firmware *wmfw_firmware __free(firmware) = NULL;Is it definitely safe to replace
release_firmwarewith kfree? In most cases that is allrelease_firmwaredoes, but it looks like it does different stuff if someone built the firmware into the kernel?
It's __free(firmware), not __free(kfree) :)
Takashi
Re: [PATCH 06/14] ALSA: hda: cs35l56: Use auto-cleanup for firmware loading
Quoted 55 lines · Takashi Iwai
Quoted 39 lines · Charles Keepax
Quoted 37 lines · Takashi Iwai
Simplify the code to manage the firmware loading with auto-cleanup. By the use of
__free(firmware), we can replace the manual mutex locks withguard()gracefully, too.Only the code refactoring, no functional changes.
Signed-off-by Takashi Iwai <[email protected]>--- sound/hda/codecs/side-codecs/cs35l56_hda.c | 35 ++++++---------------- 1 file changed, 9 insertions(+), 26 deletions(-)sound/hda/codecs/side-codecs/cs35l56_hda.c +0
-12@@ -527,18 +527,6 @@ static void cs35l56_hda_request_firmware_files(struct cs35l56_hda *cs35l56, base_name, NULL, NULL, "bin"); } -static void cs35l56_hda_release_firmware_files (const struct firmware *wmfw_firmware, -char *wmfw_filename, -const struct firmware *coeff_firmware, -char *coeff_filename) -{ -release_firmware (wmfw_firmware); -kfree (wmfw_filename); - -release_firmware (coeff_firmware); -kfree (coeff_filename); -} -static int cs35l56_hda_apply_calibration (struct cs35l56_hda *cs35l56) {int ret;@@ -561,10 +549,10 @@ static int cs35l56_hda_apply_calibration(struct cs35l56_hda *cs35l56)Quoted 13 lines
sound/hda/codecs/side-codecs/cs35l56_hda.c static int cs35l56_hda_apply_calibration(struct cs35l56_hda *cs35l56) · line 553
Quoted 8 lines
sound/hda/codecs/side-codecs/cs35l56_hda.c +2
-4static void cs35l56_hda_fw_load (struct cs35l56_hda *cs35l56) { -const struct firmware *coeff_firmware =NULL ; -const struct firmware *wmfw_firmware =NULL ; -char *coeff_filename =NULL ; -char *wmfw_filename =NULL ; + const struct firmware *coeff_firmware __free(firmware) = NULL; + const struct firmware *wmfw_firmware __free(firmware) = NULL;Is it definitely safe to replace
release_firmwarewith kfree? In most cases that is allrelease_firmwaredoes, but it looks like it does different stuff if someone built the firmware into the kernel?
Quoted 1 line
It's
__free(firmware), not__free(kfree):)
Oops... sorry my bad, must be too early in the morning for me :-)
Thanks,
Charles
Re: [PATCH 06/14] ALSA: hda: cs35l56: Use auto-cleanup for firmware loading
In reply to Takashi IwaiQuoted 11 lines · Takashi Iwai
Simplify the code to manage the firmware loading with auto-cleanup. By the use of
__free(firmware), we can replace the manual mutex locks withguard()gracefully, too.Only the code refactoring, no functional changes.
Signed-off-by Takashi Iwai <[email protected]>--- sound/hda/codecs/side-codecs/cs35l56_hda.c | 35 ++++++---------------- 1 file changed, 9 insertions(+), 26 deletions(-)
PATCH 7/14 ALSA: sscape: Use auto-cleanup for firmware loading
In reply to Takashi IwaiSimplify the code to manage the firmware loading with __free(firmware) auto-cleanup.
Only the code refactoring, no functional changes.
--- sound/isa/sscape.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
sound/isa/sscape.c +2 -6
@@ -526,7 +526,7 @@ static int upload_dma_data(struct soundscape *s, const unsigned char *data,static int sscape_upload_bootblock (struct snd_card *card) {struct soundscape *sscape =get_card_soundscape (card); -const struct firmware *init_fw =NULL ; + const struct firmware *init_fw __free(firmware) = NULL;int data =0 ;int ret;
@@ -537,8 +537,6 @@ static int sscape_upload_bootblock(struct snd_card *card) } ret =upload_dma_data (sscape, init_fw->data, init_fw->size); -release_firmware (init_fw); -guard (spinlock_irqsave)(&sscape->lock);if (ret ==0 ) data =host_read_ctrl_unsafe (sscape->io_base,100 );
@@ -562,7 +560,7 @@ static int sscape_upload_bootblock(struct snd_card *card)static int sscape_upload_microcode (struct snd_card *card,int version) {struct soundscape *sscape =get_card_soundscape (card); -const struct firmware *init_fw =NULL ; + const struct firmware *init_fw __free(firmware) = NULL;char name[14 ];int err;
@@ -579,8 +577,6 @@ static int sscape_upload_microcode(struct snd_card *card, int version)dev_info (card->dev,"sscape: MIDI firmware loaded %zu KBs\n" , init_fw->size >>10 ); -release_firmware (init_fw); -return err; }
Signature · 1 line
2.55.0
PATCH 8/14 ALSA: wavefront: Use auto-cleanup for firmware loading
In reply to Takashi IwaiSimplify the code to manage the firmware loading with __free(firmware) auto-cleanup.
Only the code refactoring, no functional changes.
--- sound/isa/wavefront/wavefront_fx.c | 23 +++++++---------------- sound/isa/wavefront/wavefront_synth.c | 4 +--- 2 files changed, 8 insertions(+), 19 deletions(-)
sound/isa/wavefront/wavefront_fx.c +7 -16
@@ -232,41 +232,32 @@ snd_wavefront_fx_start (snd_wavefront_t *dev) {unsigned int i;int err; -const struct firmware *firmware =NULL ; + const struct firmware *firmware __free(firmware) = NULL;if (dev->fx_initialized)return 0 ; err =request_firmware (&firmware,"yamaha/yss225_registers.bin" , dev->card->dev); -if (err <0 ) { - err =-1 ; - goto out; - } +if (err <0 ) +return -1 ;for (i =0 ; i +1 < firmware->size; i +=2 ) {if (firmware->data[i] >=8 && firmware->data[i] <16 ) {outb (firmware->data[i +1 ], dev->base + firmware->data[i]); }else if (firmware->data[i] ==WAIT_IDLE ) { -if (!wavefront_fx_idle (dev)) { - err =-1 ; - goto out; - } +if (!wavefront_fx_idle (dev)) +return -1 ; }else {dev_err (dev->card->dev,"invalid address in register data\n" ); - err =-1 ; - goto out; +return -1 ; } } dev->fx_initialized =1 ; - err =0 ; - -out: -release_firmware (firmware); -return err; +return 0 ; }MODULE_FIRMWARE ("yamaha/yss225_registers.bin" );
sound/isa/wavefront/wavefront_synth.c +1 -3
@@ -2053,7 +2053,7 @@ wavefront_download_firmware (snd_wavefront_t *dev, char *path)const unsigned char *buf;int len, err;int section_cnt_downloaded =0 ; -const struct firmware *firmware; + const struct firmware *firmware __free(firmware) = NULL; err =request_firmware (&firmware, path, dev->card->dev);if (err <0 ) {
@@ -2108,11 +2108,9 @@ wavefront_download_firmware (snd_wavefront_t *dev, char *path) section_cnt_downloaded++; } -release_firmware (firmware);return 0 ; failure: -release_firmware (firmware);dev_err (dev->card->dev,"firmware download failed!!!\n" );return 1 ; }
Signature · 1 line
2.55.0
PATCH 9/14 ALSA: asihpi: Use auto-cleanup for firmware loading
In reply to Takashi IwaiSimplify the code to manage the firmware loading with __free(firmware) auto-cleanup.
Only the code refactoring, no functional changes.
--- sound/pci/asihpi/hpidspcd.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
sound/pci/asihpi/hpidspcd.c +8 -10
@@ -23,7 +23,7 @@ struct dsp_code_private {short hpi_dsp_code_open (u32 adapter,void *os_data,struct dsp_code *dsp_code,u32 *os_error_code) { -const struct firmware *firmware; + const struct firmware *firmware __free(firmware) = NULL;struct pci_dev *dev = os_data;struct code_header header;char fw_name[20 ];
@@ -37,11 +37,11 @@ short hpi_dsp_code_open(u32 adapter, void *os_data, struct dsp_code *dsp_code,if (err || !firmware) {dev_err (&dev->dev,"%d, request_firmware failed for %s\n" , err, fw_name); - goto error1; + goto error; }if (firmware->size <sizeof (header)) {dev_err (&dev->dev,"Header size too small %s\n" , fw_name); - goto error2; + goto error; }memcpy (&header, firmware->data,sizeof (header));
@@ -51,7 +51,7 @@ short hpi_dsp_code_open(u32 adapter, void *os_data, struct dsp_code *dsp_code,dev_err (&dev->dev,"Invalid firmware header size %d != file %zd\n" , header.size, firmware->size); - goto error2; + goto error; }if (HPI_VER_MAJOR (header.version) !=HPI_VER_MAJOR (HPI_VER )) {
@@ -59,7 +59,7 @@ short hpi_dsp_code_open(u32 adapter, void *os_data, struct dsp_code *dsp_code,dev_err (&dev->dev,"Incompatible firmware version DSP image %X != Driver %X\n" , header.version,HPI_VER ); - goto error2; + goto error; }if (header.version !=HPI_VER ) {
@@ -72,19 +72,17 @@ short hpi_dsp_code_open(u32 adapter, void *os_data, struct dsp_code *dsp_code, dsp_code->pvt =kmalloc_obj (*dsp_code->pvt);if (!dsp_code->pvt) { err_ret =HPI_ERROR_MEMORY_ALLOC ; - goto error2; + goto error; } dsp_code->pvt->dev = dev; - dsp_code->pvt->firmware = firmware; + dsp_code->pvt->firmware =no_free_ptr (firmware); dsp_code->header = header; dsp_code->block_length = header.size /sizeof (u32); dsp_code->word_count =sizeof (header) /sizeof (u32);return 0 ; -error2: -release_firmware (firmware); -error1: +error: dsp_code->block_length =0 ;return err_ret; }
Signature · 1 line
2.55.0
PATCH 10/14 ALSA: cs46xx: Use auto-cleanup for firmware loading
In reply to Takashi IwaiSimplify the code to manage the firmware loading with __free(firmware) auto-cleanup.
Only the code refactoring, no functional changes.
--- sound/pci/cs46xx/cs46xx_lib.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-)
sound/pci/cs46xx/cs46xx_lib.c +10 -20
@@ -387,7 +387,7 @@ static int load_firmware(struct snd_cs46xx *chip,unsigned int nums, fwlen, fwsize;const __le32 *fwdat;struct dsp_module_desc *module =NULL ; -const struct firmware *fw; + const struct firmware *fw __free(firmware) = NULL;char fw_path[32 ];sprintf (fw_path,"cs46xx/%s" , fw_name);
@@ -395,10 +395,8 @@ static int load_firmware(struct snd_cs46xx *chip,if (err <0 )return err; fwsize = fw->size /4 ; -if (fwsize <2 ) { - err = -EINVAL ; - goto error; - } +if (fwsize <2 ) +return -EINVAL ; err = -ENOMEM ; module =kzalloc_obj (*module);
@@ -454,14 +452,12 @@ static int load_firmware(struct snd_cs46xx *chip, } *module_ret = module; -release_firmware (fw);return 0 ; error_inval: err = -EINVAL ; error:free_module_desc (module); -release_firmware (fw);return err; }
@@ -500,22 +496,18 @@ MODULE_FIRMWARE("cs46xx/ba1");static int load_firmware (struct snd_cs46xx *chip) { -const struct firmware *fw; + const struct firmware *fw __free(firmware) = NULL;int i, size, err; err =request_firmware (&fw,"cs46xx/ba1" , &chip->pci->dev);if (err <0 )return err; -if (fw->size !=sizeof (*chip->ba1)) { - err = -EINVAL ; - goto error; - } +if (fw->size !=sizeof (*chip->ba1)) +return -EINVAL ; chip->ba1 =vmalloc (sizeof (*chip->ba1)); -if (!chip->ba1) { - err = -ENOMEM ; - goto error; - } +if (!chip->ba1) +return -ENOMEM ;memcpy_le32 (chip->ba1, fw->data,sizeof (*chip->ba1));
@@ -524,11 +516,9 @@ static int load_firmware(struct snd_cs46xx *chip)for (i =0 ; i <BA1_MEMORY_COUNT ; i++) size += chip->ba1->memory[i].size;if (size >BA1_DWORD_SIZE *4 ) - err = -EINVAL ; +return -EINVAL ; - error: -release_firmware (fw); -return err; +return 0 ; }static __maybe_unused int snd_cs46xx_download_image (struct snd_cs46xx *chip)
Signature · 1 line
2.55.0
PATCH 11/14 ALSA: korg1212: Use auto-cleanup for firmware loading
In reply to Takashi IwaiSimplify the code to manage the firmware loading with __free(firmware) auto-cleanup.
Only the code refactoring, no functional changes.
--- sound/pci/korg1212/korg1212.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
sound/pci/korg1212/korg1212.c +2 -6
@@ -1980,7 +1980,7 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci)__maybe_unused unsigned ioport_size;__maybe_unused unsigned iomem2_size;struct snd_korg1212 *korg1212 = card->private_data; -const struct firmware *dsp_code; + const struct firmware *dsp_code __free(firmware) = NULL; err =pcim_enable_device (pci);if (err <0 )
@@ -2147,10 +2147,8 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci) korg1212->dma_dsp =snd_devm_alloc_pages (&pci->dev,SNDRV_DMA_TYPE_DEV , dsp_code->size); -if (!korg1212->dma_dsp) { -release_firmware (dsp_code); +if (!korg1212->dma_dsp)return -ENOMEM ; - } K1212_DEBUG_PRINTK("K1212_DEBUG: DSP Code area = 0x%p (0x%08x) %d bytes [%s]\n", korg1212->dma_dsp->area, korg1212->dma_dsp->addr, dsp_code->size,
@@ -2158,8 +2156,6 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci)memcpy (korg1212->dma_dsp->area, dsp_code->data, dsp_code->size); -release_firmware (dsp_code); - rc =snd_korg1212_Send1212Command (korg1212, K1212_DB_RebootCard,0 ,0 ,0 ,0 );if (rc)
Signature · 1 line
2.55.0
PATCH 12/14 ALSA: mixart: Use auto-cleanup for firmware loading
In reply to Takashi IwaiSimplify the code to manage the firmware loading with __free(firmware) auto-cleanup.
Only the code refactoring, no functional changes.
--- sound/pci/mixart/mixart_hwdep.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
sound/pci/mixart/mixart_hwdep.c +1 -3
@@ -560,12 +560,11 @@ int snd_mixart_setup_firmware(struct mixart_mgr *mgr)"miXart8.xlx" ,"miXart8.elf" ,"miXart8AES.xlx" };char path[32 ]; - -const struct firmware *fw_entry;int i, err;for (i =0 ; i <3 ; i++) {sprintf (path,"mixart/%s" , fw_files[i]); + const struct firmware *fw_entry __free(firmware) = NULL;if (request_firmware (&fw_entry, path, &mgr->pci->dev)) {dev_err (&mgr->pci->dev,"miXart: can't load firmware %s\n" , path);
@@ -573,7 +572,6 @@ int snd_mixart_setup_firmware(struct mixart_mgr *mgr) }/* fake hwdep dsp record */ err =mixart_dsp_load (mgr, i, fw_entry); -release_firmware (fw_entry);if (err <0 )return err; mgr->dsp_loaded |=1 << i;
Signature · 1 line
2.55.0
PATCH 13/14 ALSA: pcxhr: Use auto-cleanup for firmware loading
In reply to Takashi IwaiSimplify the code to manage the firmware loading with __free(firmware) auto-cleanup.
Only the code refactoring, no functional changes.
--- sound/pci/pcxhr/pcxhr_hwdep.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sound/pci/pcxhr/pcxhr_hwdep.c +1 -2
@@ -367,7 +367,6 @@ int pcxhr_setup_firmware(struct pcxhr_mgr *mgr) };char path[32 ]; -const struct firmware *fw_entry;int i, err;int fw_set = mgr->fw_file_set;
@@ -375,6 +374,7 @@ int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)if (!fw_files[fw_set][i])continue ;sprintf (path,"pcxhr/%s" , fw_files[fw_set][i]); + const struct firmware *fw_entry __free(firmware) = NULL;if (request_firmware (&fw_entry, path, &mgr->pci->dev)) { dev_err(&mgr->pci->dev, "pcxhr: can't load firmware %s\n",
@@ -383,7 +383,6 @@ int pcxhr_setup_firmware(struct pcxhr_mgr *mgr) }/* fake hwdep dsp record */ err =pcxhr_dsp_load (mgr, i, fw_entry); -release_firmware (fw_entry);if (err <0 )return err; mgr->dsp_loaded |=1 << i;
Signature · 1 line
2.55.0
PATCH 14/14 ALSA: sh: Use auto-cleanup for firmware loading
In reply to Takashi IwaiSimplify the code to manage the firmware loading with __free(firmware) auto-cleanup.
Only the code refactoring, no functional changes.
--- sound/sh/aica.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/sh/aica.c +2 -2
@@ -518,8 +518,9 @@ static const struct snd_kcontrol_new snd_aica_pcmvolume_control = {static int load_aica_firmware (void ) {int err; -const struct firmware *fw_entry;spu_reset (); + + const struct firmware *fw_entry __free(firmware) = NULL; err =request_firmware (&fw_entry,"aica_firmware.bin" , &pd->dev);if (unlikely (err))return err;
@@ -527,7 +528,6 @@ static int load_aica_firmware(void)spu_disable ();spu_memload (0 , fw_entry->data, fw_entry->size);spu_enable (); -release_firmware (fw_entry);return err; }
Signature · 1 line
2.55.0