All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Subject: [PATCH 63/66] ALSA: synth: Fix assignment in if condition
Date: Tue,  8 Jun 2021 16:05:37 +0200	[thread overview]
Message-ID: <20210608140540.17885-64-tiwai@suse.de> (raw)
In-Reply-To: <20210608140540.17885-1-tiwai@suse.de>

EMUx synth driver code contains lots of assignments in if condition,
which is a bad coding style that may confuse readers and occasionally
lead to bugs.

This patch is merely for coding-style fixes, no functional changes.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/synth/emux/emux.c        |  3 ++-
 sound/synth/emux/emux_effect.c | 13 ++++++++---
 sound/synth/emux/emux_hwdep.c  |  6 +++--
 sound/synth/emux/soundfont.c   | 40 ++++++++++++++++++++++------------
 4 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/sound/synth/emux/emux.c b/sound/synth/emux/emux.c
index f65e6c7b139f..49d1976a132c 100644
--- a/sound/synth/emux/emux.c
+++ b/sound/synth/emux/emux.c
@@ -104,7 +104,8 @@ int snd_emux_register(struct snd_emux *emu, struct snd_card *card, int index, ch
 	if (emu->sflist == NULL)
 		return -ENOMEM;
 
-	if ((err = snd_emux_init_hwdep(emu)) < 0)
+	err = snd_emux_init_hwdep(emu);
+	if (err < 0)
 		return err;
 
 	snd_emux_init_voices(emu);
diff --git a/sound/synth/emux/emux_effect.c b/sound/synth/emux/emux_effect.c
index afd119b11f39..3c7314f5fb19 100644
--- a/sound/synth/emux/emux_effect.c
+++ b/sound/synth/emux/emux_effect.c
@@ -181,7 +181,10 @@ snd_emux_send_effect(struct snd_emux_port *port, struct snd_midi_channel *chan,
 	fx->flag[type] = mode;
 
 	/* do we need to modify the register in realtime ? */
-	if (! parm_defs[type].update || (offset = parm_defs[type].offset) < 0)
+	if (!parm_defs[type].update)
+		return;
+	offset = parm_defs[type].offset;
+	if (offset < 0)
 		return;
 
 #ifdef SNDRV_LITTLE_ENDIAN
@@ -223,13 +226,17 @@ snd_emux_setup_effect(struct snd_emux_voice *vp)
 	unsigned char *srcp;
 	int i;
 
-	if (! (fx = chan->private))
+	fx = chan->private;
+	if (!fx)
 		return;
 
 	/* modify the register values via effect table */
 	for (i = 0; i < EMUX_FX_END; i++) {
 		int offset;
-		if (! fx->flag[i] || (offset = parm_defs[i].offset) < 0)
+		if (!fx->flag[i])
+			continue;
+		offset = parm_defs[i].offset;
+		if (offset < 0)
 			continue;
 #ifdef SNDRV_LITTLE_ENDIAN
 		if (parm_defs[i].type & PARM_IS_ALIGN_HI)
diff --git a/sound/synth/emux/emux_hwdep.c b/sound/synth/emux/emux_hwdep.c
index 8a965e2f160a..81719bfb8ed7 100644
--- a/sound/synth/emux/emux_hwdep.c
+++ b/sound/synth/emux/emux_hwdep.c
@@ -116,7 +116,8 @@ snd_emux_init_hwdep(struct snd_emux *emu)
 	struct snd_hwdep *hw;
 	int err;
 
-	if ((err = snd_hwdep_new(emu->card, SNDRV_EMUX_HWDEP_NAME, emu->hwdep_idx, &hw)) < 0)
+	err = snd_hwdep_new(emu->card, SNDRV_EMUX_HWDEP_NAME, emu->hwdep_idx, &hw);
+	if (err < 0)
 		return err;
 	emu->hwdep = hw;
 	strcpy(hw->name, SNDRV_EMUX_HWDEP_NAME);
@@ -127,7 +128,8 @@ snd_emux_init_hwdep(struct snd_emux *emu)
 	hw->ops.ioctl_compat = snd_emux_hwdep_ioctl;
 	hw->exclusive = 1;
 	hw->private_data = emu;
-	if ((err = snd_card_register(emu->card)) < 0)
+	err = snd_card_register(emu->card);
+	if (err < 0)
 		return err;
 
 	return 0;
diff --git a/sound/synth/emux/soundfont.c b/sound/synth/emux/soundfont.c
index 9ebc711afa6b..da3cf8912463 100644
--- a/sound/synth/emux/soundfont.c
+++ b/sound/synth/emux/soundfont.c
@@ -349,7 +349,8 @@ sf_zone_new(struct snd_sf_list *sflist, struct snd_soundfont *sf)
 {
 	struct snd_sf_zone *zp;
 
-	if ((zp = kzalloc(sizeof(*zp), GFP_KERNEL)) == NULL)
+	zp = kzalloc(sizeof(*zp), GFP_KERNEL);
+	if (!zp)
 		return NULL;
 	zp->next = sf->zones;
 	sf->zones = zp;
@@ -381,7 +382,8 @@ sf_sample_new(struct snd_sf_list *sflist, struct snd_soundfont *sf)
 {
 	struct snd_sf_sample *sp;
 
-	if ((sp = kzalloc(sizeof(*sp), GFP_KERNEL)) == NULL)
+	sp = kzalloc(sizeof(*sp), GFP_KERNEL);
+	if (!sp)
 		return NULL;
 
 	sp->next = sf->samples;
@@ -451,7 +453,8 @@ load_map(struct snd_sf_list *sflist, const void __user *data, int count)
 	}
 
 	/* create a new zone */
-	if ((zp = sf_zone_new(sflist, sf)) == NULL)
+	zp = sf_zone_new(sflist, sf);
+	if (!zp)
 		return -ENOMEM;
 
 	zp->bank = map.map_bank;
@@ -514,7 +517,8 @@ load_info(struct snd_sf_list *sflist, const void __user *data, long count)
 	int i;
 
 	/* patch must be opened */
-	if ((sf = sflist->currsf) == NULL)
+	sf = sflist->currsf;
+	if (!sf)
 		return -EINVAL;
 
 	if (is_special_type(sf->type))
@@ -579,9 +583,9 @@ load_info(struct snd_sf_list *sflist, const void __user *data, long count)
 			init_voice_parm(&tmpzone.v.parm);
 
 		/* create a new zone */
-		if ((zone = sf_zone_new(sflist, sf)) == NULL) {
+		zone = sf_zone_new(sflist, sf);
+		if (!zone)
 			return -ENOMEM;
-		}
 
 		/* copy the temporary data */
 		zone->bank = tmpzone.bank;
@@ -700,7 +704,8 @@ load_data(struct snd_sf_list *sflist, const void __user *data, long count)
 	long off;
 
 	/* patch must be opened */
-	if ((sf = sflist->currsf) == NULL)
+	sf = sflist->currsf;
+	if (!sf)
 		return -EINVAL;
 
 	if (is_special_type(sf->type))
@@ -723,7 +728,8 @@ load_data(struct snd_sf_list *sflist, const void __user *data, long count)
 	}
 
 	/* Allocate a new sample structure */
-	if ((sp = sf_sample_new(sflist, sf)) == NULL)
+	sp = sf_sample_new(sflist, sf);
+	if (!sp)
 		return -ENOMEM;
 
 	sp->v = sample_info;
@@ -958,7 +964,8 @@ load_guspatch(struct snd_sf_list *sflist, const char __user *data,
 	sf = newsf(sflist, SNDRV_SFNT_PAT_TYPE_GUS|SNDRV_SFNT_PAT_SHARED, NULL);
 	if (sf == NULL)
 		return -ENOMEM;
-	if ((smp = sf_sample_new(sflist, sf)) == NULL)
+	smp = sf_sample_new(sflist, sf);
+	if (!smp)
 		return -ENOMEM;
 	sample_id = sflist->sample_counter;
 	smp->v.sample = sample_id;
@@ -996,7 +1003,8 @@ load_guspatch(struct snd_sf_list *sflist, const char __user *data,
 	smp->v.sf_id = sf->id;
 
 	/* set up voice info */
-	if ((zone = sf_zone_new(sflist, sf)) == NULL) {
+	zone = sf_zone_new(sflist, sf);
+	if (!zone) {
 		sf_sample_delete(sflist, sf, smp);
 		return -ENOMEM;
 	}
@@ -1181,7 +1189,8 @@ add_preset(struct snd_sf_list *sflist, struct snd_sf_zone *cur)
 	}
 
 	/* prepend this zone */
-	if ((index = get_index(cur->bank, cur->instr, cur->v.low)) < 0)
+	index = get_index(cur->bank, cur->instr, cur->v.low);
+	if (index < 0)
 		return;
 	cur->next_zone = zone; /* zone link */
 	cur->next_instr = sflist->presets[index]; /* preset table link */
@@ -1197,7 +1206,8 @@ delete_preset(struct snd_sf_list *sflist, struct snd_sf_zone *zp)
 	int index;
 	struct snd_sf_zone *p;
 
-	if ((index = get_index(zp->bank, zp->instr, zp->v.low)) < 0)
+	index = get_index(zp->bank, zp->instr, zp->v.low);
+	if (index < 0)
 		return;
 	for (p = sflist->presets[index]; p; p = p->next_instr) {
 		while (p->next_instr == zp) {
@@ -1257,7 +1267,8 @@ search_first_zone(struct snd_sf_list *sflist, int bank, int preset, int key)
 	int index;
 	struct snd_sf_zone *zp;
 
-	if ((index = get_index(bank, preset, key)) < 0)
+	index = get_index(bank, preset, key);
+	if (index < 0)
 		return NULL;
 	for (zp = sflist->presets[index]; zp; zp = zp->next_instr) {
 		if (zp->instr == preset && zp->bank == bank)
@@ -1386,7 +1397,8 @@ snd_sf_new(struct snd_sf_callback *callback, struct snd_util_memhdr *hdr)
 {
 	struct snd_sf_list *sflist;
 
-	if ((sflist = kzalloc(sizeof(*sflist), GFP_KERNEL)) == NULL)
+	sflist = kzalloc(sizeof(*sflist), GFP_KERNEL);
+	if (!sflist)
 		return NULL;
 
 	mutex_init(&sflist->presets_mutex);
-- 
2.26.2


  parent reply	other threads:[~2021-06-08 14:22 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08 14:04 [PATCH 00/66] ALSA: Fix assignment in if condition Takashi Iwai
2021-06-08 14:04 ` [PATCH 01/66] ALSA: sb: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 02/66] ALSA: sb: Minor coding style fixes Takashi Iwai
2021-06-08 14:04 ` [PATCH 03/66] ALSA: sb: Fix potential double-free of CSP mixer elements Takashi Iwai
2021-06-08 14:04 ` [PATCH 04/66] ALSA: gus: Fix assignment in if condition Takashi Iwai
2021-06-08 14:04 ` [PATCH 05/66] ALSA: ad1816a: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 06/66] ALSA: wavefront: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 07/66] ALSA: cs423x: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 08/66] ALSA: opti9xx: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 09/66] ALSA: opl3sa2: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 10/66] ALSA: es18xx: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 11/66] ALSA: cmi8330: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 12/66] ALSA: als100: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 13/66] ALSA: azt2320: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 14/66] ALSA: isa: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 15/66] ALSA: ad1889: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 16/66] ALSA: ak4531: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 17/66] ALSA: als300: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 18/66] ALSA: als4000: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 19/66] ALSA: atiixp: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 20/66] ALSA: azt3328: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 21/66] ALSA: bt87x: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 22/66] ALSA: cmipci: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 23/66] ALSA: cs4281: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 24/66] ALSA: ens137x: " Takashi Iwai
2021-06-08 14:04 ` [PATCH 25/66] ALSA: es1938: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 26/66] ALSA: es1968: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 27/66] ALSA: fm801: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 28/66] ALSA: intel8x0: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 29/66] ALSA: maestro3: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 30/66] ALSA: rme32: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 31/66] ALSA: rme96: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 32/66] ALSA: sonicvibes: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 33/66] ALSA: via82xx: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 34/66] ALSA: ac97: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 35/66] ALSA: au88x0: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 36/66] ALSA: ca0106: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 37/66] ALSA: cs46xx: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 38/66] ALSA: cs5535audio: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 39/66] ALSA: echoaudio: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 40/66] ALSA: emu10k1: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 41/66] ALSA: emu10k1x: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 42/66] ALSA: ice1712: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 43/66] ALSA: korg1212: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 44/66] ALSA: mixart: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 45/66] ALSA: nm256: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 46/66] ALSA: pcxhr: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 47/66] ALSA: riptide: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 48/66] ALSA: hdsp: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 49/66] ALSA: rme9652: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 50/66] ALSA: trident: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 51/66] ALSA: vx222: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 52/66] ALSA: ymfpci: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 53/66] ALSA: core: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 54/66] ALSA: pcm: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 55/66] ALSA: oss: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 56/66] ALSA: seq: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 57/66] ALSA: pcmcia: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 58/66] ALSA: sparc: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 59/66] ALSA: mpu401: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 60/66] ALSA: vx: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 61/66] ALSA: opl3: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 62/66] ALSA: serial: " Takashi Iwai
2021-06-08 14:05 ` Takashi Iwai [this message]
2021-06-08 14:05 ` [PATCH 64/66] ALSA: poewrmac: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 65/66] ALSA: i2c: " Takashi Iwai
2021-06-08 14:05 ` [PATCH 66/66] ALSA: parisc: " Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210608140540.17885-64-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.