[PATCH] ALSA: ac97_codec: Use common error handling code in snd_ac97_mixer()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 11 Nov 2017 22:30:51 +0100

* Add jump targets so that a bit of exception handling can be better reused
  at the end of this function.

  This issue was detected by using the Coccinelle software.

* The script "checkpatch.pl" pointed information out like the following.

  ERROR: do not use assignment in if condition

  Thus fix three affected source code places.

Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
---
 sound/pci/ac97/ac97_codec.c | 50 +++++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 1ef7cdf1d3e8..2289cdcf2d48 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -2103,8 +2103,8 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
 		ac97_err(ac97,
 			 "AC'97 %d access is not valid [0x%x], removing mixer.\n",
 			 ac97->num, ac97->id);
-		snd_ac97_free(ac97);
-		return -EIO;
+		err = -EIO;
+		goto free_ac;
 	}
 	pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);
 	if (pid)
@@ -2138,8 +2138,8 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
 			ac97_err(ac97,
 				 "AC'97 %d access error (not audio or modem codec)\n",
 				 ac97->num);
-		snd_ac97_free(ac97);
-		return -EACCES;
+		err = -EACCES;
+		goto free_ac;
 	}
 
 	if (bus->ops->reset) // FIXME: always skipping?
@@ -2267,14 +2267,12 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
 			}
 		}
 		sprintf(comp, "AC97a:%08x", ac97->id);
-		if ((err = snd_component_add(card, comp)) < 0) {
-			snd_ac97_free(ac97);
-			return err;
-		}
-		if (snd_ac97_mixer_build(ac97) < 0) {
-			snd_ac97_free(ac97);
-			return -ENOMEM;
-		}
+		err = snd_component_add(card, comp);
+		if (err < 0)
+			goto free_ac;
+
+		if (snd_ac97_mixer_build(ac97) < 0)
+			goto e_nomem;
 	}
 	if (ac97_is_modem(ac97)) {
 		char comp[16];
@@ -2287,24 +2285,28 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
 			}
 		}
 		sprintf(comp, "AC97m:%08x", ac97->id);
-		if ((err = snd_component_add(card, comp)) < 0) {
-			snd_ac97_free(ac97);
-			return err;
-		}
-		if (snd_ac97_modem_build(card, ac97) < 0) {
-			snd_ac97_free(ac97);
-			return -ENOMEM;
-		}
+		err = snd_component_add(card, comp);
+		if (err < 0)
+			goto free_ac;
+
+		if (snd_ac97_modem_build(card, ac97) < 0)
+			goto e_nomem;
 	}
 	if (ac97_is_audio(ac97))
 		update_power_regs(ac97);
 	snd_ac97_proc_init(ac97);
-	if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ac97, &ops)) < 0) {
-		snd_ac97_free(ac97);
-		return err;
-	}
+	err = snd_device_new(card, SNDRV_DEV_CODEC, ac97, &ops);
+	if (err < 0)
+		goto free_ac;
+
 	*rac97 = ac97;
 	return 0;
+
+e_nomem:
+	err = -ENOMEM;
+free_ac:
+	snd_ac97_free(ac97);
+	return err;
 }
 
 EXPORT_SYMBOL(snd_ac97_mixer);
-- 
2.15.0

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux