Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Patrick Lai <plai@codeaurora.org>
Cc: alsa-devel <alsa-devel@alsa-project.org>
Subject: Re: Compiler warning - overriding codec compress type
Date: Mon, 18 Apr 2011 11:25:43 +0200	[thread overview]
Message-ID: <4DAC0397.6040803@ladisch.de> (raw)
In-Reply-To: <4DABDC2E.9080103@codeaurora.org>

Patrick Lai wrote:
> I got a compiler warning soc-core.c: In function
> 'snd_soc_instantiate_cards' warning: 'compress_type' may be used
> uninitialized in this function. In reality, compress_type is defined as
> local variable in snd_soc_instantiate_card().

Please note that this warning is merely a tool to find errors in the
code; the word "may" indicates that the compilter isn't sure about this.

> I think the fix should look like the following:
> 
> list_for_each_entry(codec, &codec_list, list) {
>                  if (codec->cache_init)
>                          continue;
> +               compress_type = 0;
>                  /* check to see if we need to override the compress_type */
>                  for (i = 0; i < card->num_configs; ++i) {
>                          codec_conf = &card->codec_conf[i];

When the for loop does not find an override, the following if() will
jump out of the outer list_for_each_entry loop before the compress_type
could be used, so it is not actually necessary to initialize this
variable; a better way would be to use uninitialized_var.

> My kernel version is 2.6.38. Has the warning being addressed in 2.6.39 
> or 2.6.40 patches?

... and an even better way is to simplify the logic:
http://git.alsa-project.org/?p=alsa-kernel.git;a=commitdiff;h=3110b8b0206cba978d95895723a3d901fb0f738d


Regards,
Clemens

  reply	other threads:[~2011-04-18  9:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-18  6:37 Compiler warning - overriding codec compress type Patrick Lai
2011-04-18  9:25 ` Clemens Ladisch [this message]
2011-04-18 10:30 ` Mark Brown
2011-04-18 18:53   ` Patrick Lai

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=4DAC0397.6040803@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=plai@codeaurora.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox