All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] ALSA: usb-audio: Handle error for the current selector gracefully
@ 2021-05-21 12:21 Dan Carpenter
  2021-05-21 14:18 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2021-05-21 12:21 UTC (permalink / raw)
  To: tiwai; +Cc: alsa-devel

Hello Takashi Iwai,

The patch 481f17c41803: "ALSA: usb-audio: Handle error for the
current selector gracefully" from May 18, 2021, leads to the
following static checker warning:

	sound/usb/clock.c:338 __uac_clock_find_source()
	error: uninitialized symbol 'cur'.

sound/usb/clock.c
   254  static int __uac_clock_find_source(struct snd_usb_audio *chip,
   255                                     const struct audioformat *fmt, int entity_id,
   256                                     unsigned long *visited, bool validate)
   257  {
   258          union uac23_clock_source_desc *source;
   259          union uac23_clock_selector_desc *selector;
   260          union uac23_clock_multiplier_desc *multiplier;
   261          int ret, i, cur, err, pins, clock_id;
                            ^^^

   262          const u8 *sources;
   263          int proto = fmt->protocol;
   264  
   265          entity_id &= 0xff;
   266  
   267          if (test_and_set_bit(entity_id, visited)) {
   268                  usb_audio_warn(chip,
   269                           "%s(): recursive clock topology detected, id %d.\n",
   270                           __func__, entity_id);
   271                  return -EINVAL;
   272          }
   273  
   274          /* first, see if the ID we're looking for is a clock source already */
   275          source = snd_usb_find_clock_source(chip, entity_id, proto);
   276          if (source) {
   277                  entity_id = GET_VAL(source, proto, bClockID);
   278                  if (validate && !uac_clock_source_is_valid(chip, fmt,
   279                                                                  entity_id)) {
   280                          usb_audio_err(chip,
   281                                  "clock source %d is not valid, cannot use\n",
   282                                  entity_id);
   283                          return -ENXIO;
   284                  }
   285                  return entity_id;
   286          }
   287  
   288          selector = snd_usb_find_clock_selector(chip, entity_id, proto);
   289          if (selector) {
   290                  pins = GET_VAL(selector, proto, bNrInPins);
   291                  clock_id = GET_VAL(selector, proto, bClockID);
   292                  sources = GET_VAL(selector, proto, baCSourceID);
   293  
   294                  if (pins == 1) {
   295                          ret = 1;
   296                          goto find_source;
   297                  }
   298  
   299                  /* the entity ID we are looking for is a selector.
   300                   * find out what it currently selects */
   301                  ret = uac_clock_selector_get_val(chip, clock_id);
   302                  if (ret < 0) {
   303                          if (!chip->autoclock)
   304                                  return ret;
   305                          goto find_others;
                                ^^^^^^^^^^^^^^^^^
Assume we hit one of these gotos

   306                  }
   307  
   308                  /* Selector values are one-based */
   309  
   310                  if (ret > pins || ret < 1) {
   311                          usb_audio_err(chip,
   312                                  "%s(): selector reported illegal value, id %d, ret %d\n",
   313                                  __func__, clock_id, ret);
   314  
   315                          if (!chip->autoclock)
   316                                  return -EINVAL;
   317                          ret = 0;
   318                          goto find_others;
                                ^^^^^^^^^^^^^^^^^

   319                  }
   320  
   321          find_source:
   322                  cur = ret;
   323                  ret = __uac_clock_find_source(chip, fmt,
   324                                                sources[ret - 1],
   325                                                visited, validate);
   326                  if (ret > 0) {
   327                          err = uac_clock_selector_set_val(chip, entity_id, cur);
   328                          if (err < 0)
   329                                  return err;
   330                  }
   331  
   332                  if (!validate || ret > 0 || !chip->autoclock)
   333                          return ret;
   334  
   335          find_others:
   336                  /* The current clock source is invalid, try others. */
   337                  for (i = 1; i <= pins; i++) {
   338                          if (i == cur)
                                    ^^^^^^^^

   339                                  continue;
   340  
   341                          ret = __uac_clock_find_source(chip, fmt,
   342                                                        sources[i - 1],
   343 

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [bug report] ALSA: usb-audio: Handle error for the current selector gracefully
  2021-05-21 12:21 [bug report] ALSA: usb-audio: Handle error for the current selector gracefully Dan Carpenter
@ 2021-05-21 14:18 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2021-05-21 14:18 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: alsa-devel

On Fri, 21 May 2021 14:21:11 +0200,
Dan Carpenter wrote:
> 
> Hello Takashi Iwai,
> 
> The patch 481f17c41803: "ALSA: usb-audio: Handle error for the
> current selector gracefully" from May 18, 2021, leads to the
> following static checker warning:
> 
> 	sound/usb/clock.c:338 __uac_clock_find_source()
> 	error: uninitialized symbol 'cur'.

Thanks, this has been already reported by Colin, and the fix is on its
way:
 https://lore.kernel.org/r/s5hfsyhh97t.wl-tiwai@suse.de


Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-21 14:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-21 12:21 [bug report] ALSA: usb-audio: Handle error for the current selector gracefully Dan Carpenter
2021-05-21 14:18 ` Takashi Iwai

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.