[alsa-devel] [bug report] ASoC: add audio-graph-card support

Dan Carpenter dan.carpenter at oracle.com
Thu May 18 23:33:12 CEST 2017


Hello Kuninori Morimoto,

The patch 2692c1c63c29: "ASoC: add audio-graph-card support" from Apr
20, 2017, leads to the following static checker warning:

	sound/soc/generic/audio-graph-card.c:275 asoc_graph_card_probe()
	info: return a literal instead of 'ret'

sound/soc/generic/audio-graph-card.c
   268                  goto err;
   269          }
   270  
   271          snd_soc_card_set_drvdata(card, priv);
   272  
   273          ret = devm_snd_soc_register_card(dev, card);
   274          if (ret >= 0)
   275                  return ret;

This code is confusing.  I'm pretty sure that devm_snd_soc_register_card()
returns zero on success or negative error codes but why are we checking
>= 0 here?

It's better to do error handling than success handling.  People often
get a bit creative with the last condition in a function...  :/  In
other words, it's cleaner like this:

		ret = devm_snd_soc_register_card(dev, card);
		if (ret)
			goto err;

		return 0;

	err:
		asoc_simple_card_clean_reference(card);

		return ret;


   276  err:
   277          asoc_simple_card_clean_reference(card);
   278  
   279          return ret;
   280  }

regards,
dan carpenter


More information about the Alsa-devel mailing list