snd_usx2y_hwdep_dsp_load() sets up the asynchronous sequence URBs and the interrupt URB when the FPGA firmware image with index 1 is loaded, and then creates the ALSA devices. If usx2y_in04_init() or usx2y_create_alsa_devices() fails, the URBs that were already set up are left in place. The core keeps the index unloaded when the callback fails, so user space may issue the same request again. The second attempt then enters usx2y_async_seq04_init() or usx2y_in04_init() with the URBs still allocated and trips WARN_ON(usx2y->as04.buffer) or WARN_ON(usx2y->in04_urb). Release the URBs on these error paths instead, so that a retried request starts from a clean state and the assertions keep their meaning. Releasing the URBs also lets a retried request reach usx2y_create_alsa_devices() again, on a card that keeps the MIDI and PCM devices created by the failed attempt. For the US-428 the audio streams would then index usx2y->subs[] past its end, so do not initialise a partially created card a second time: mark the chip as hung when the ALSA devices could not be created, and refuse further DSP load requests. A failure of usx2y_in04_init() leaves the card untouched and remains retryable. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Co-developed-by: Bin Yu Signed-off-by: Bin Yu Co-developed-by: Cheng Wen Signed-off-by: Cheng Wen Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn> --- v3: do not initialise a partially created card a second time. A failed usx2y_create_alsa_devices() now marks the chip as hung, so a retried DSP load request returns -ENODEV instead of running the ALSA device creation again. sound/usb/usx2y/usX2Yhwdep.c | 6 ++++++ sound/usb/usx2y/usbusx2y.c | 16 ++++++++++++++++ sound/usb/usx2y/usbusx2y.h | 1 + 3 files changed, 23 insertions(+) diff --git a/sound/usb/usx2y/usX2Yhwdep.c b/sound/usb/usx2y/usX2Yhwdep.c index 7f153a2fcdd8..366167c62575 100644 --- a/sound/usb/usx2y/usX2Yhwdep.c +++ b/sound/usb/usx2y/usX2Yhwdep.c @@ -179,6 +179,9 @@ static int snd_usx2y_hwdep_dsp_load(struct snd_hwdep *hw, int lret, err; char *buf; + if (priv->chip_status & USX2Y_STAT_CHIP_HUP) + return -ENODEV; + buf = memdup_user(dsp->image, dsp->length); if (IS_ERR(buf)) return PTR_ERR(buf); @@ -201,11 +204,14 @@ static int snd_usx2y_hwdep_dsp_load(struct snd_hwdep *hw, err = usx2y_in04_init(priv); if (err) { dev_err(&dev->dev, "usx2y_in04_init error\n"); + usx2y_free_urbs(priv); return err; } err = usx2y_create_alsa_devices(hw->card); if (err) { dev_err(&dev->dev, "usx2y_create_alsa_devices error %i\n", err); + usx2y_free_urbs(priv); + priv->chip_status |= USX2Y_STAT_CHIP_HUP; return err; } priv->chip_status |= USX2Y_STAT_CHIP_INIT; diff --git a/sound/usb/usx2y/usbusx2y.c b/sound/usb/usx2y/usbusx2y.c index 108f9bddf9aa..8a551abe47dc 100644 --- a/sound/usb/usx2y/usbusx2y.c +++ b/sound/usb/usx2y/usbusx2y.c @@ -349,6 +349,22 @@ static void usx2y_unlinkseq(struct snd_usx2y_async_seq *s) s->buffer = NULL; } +/* + * Release the URBs set up by usx2y_async_seq04_init() and usx2y_in04_init(). + * Used when a later step of the DSP loading fails. + */ +void usx2y_free_urbs(struct usx2ydev *usx2y) +{ + if (usx2y->in04_urb) { + usb_kill_urb(usx2y->in04_urb); + usb_free_urb(usx2y->in04_urb); + usx2y->in04_urb = NULL; + kfree(usx2y->in04_buf); + usx2y->in04_buf = NULL; + } + usx2y_unlinkseq(&usx2y->as04); +} + static const struct usb_device_id snd_usx2y_usb_id_table[] = { { .match_flags = USB_DEVICE_ID_MATCH_DEVICE, diff --git a/sound/usb/usx2y/usbusx2y.h b/sound/usb/usx2y/usbusx2y.h index 7b6deed17d4b..e5e26ac8dc04 100644 --- a/sound/usb/usx2y/usbusx2y.h +++ b/sound/usb/usx2y/usbusx2y.h @@ -110,6 +110,7 @@ int usx2y_audio_create(struct snd_card *card); int usx2y_async_seq04_init(struct usx2ydev *usx2y); int usx2y_in04_init(struct usx2ydev *usx2y); +void usx2y_free_urbs(struct usx2ydev *usx2y); #define NAME_ALLCAPS "US-X2Y" -- 2.34.1