Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp272338ybg; Tue, 2 Jun 2020 23:57:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyy8GZR3FRpYRcKpPJ137K9q1a+9p/NsaoJKmcPhY6kuDz3YJceDGaG2h67S9WqugRg3gGX X-Received: by 2002:a17:906:3a43:: with SMTP id a3mr25782429ejf.121.1591167454601; Tue, 02 Jun 2020 23:57:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591167454; cv=none; d=google.com; s=arc-20160816; b=Bw79SZe4SwaLf1Ks9zH0TBYXxx7Lbq5JF+/ZbIZEHFIuhxu0UglBmv4/iiIxPyRaws 2/RviBhEJPlD5SJ7cUyJrk4u8XrlGFH6nPj6op1Rk58lCBhsblCWV7IYfPv1yBykMnI4 f+u8JGR4hOF5u9VFywwjtiC0uqBZrRJ6k+mYnoJRp2/q5mXC3t7d+ZgdRs3sqrbF6oqI Ny/F9gdNxQ4LQCtNt3VMmK9ucPKWOFpDtuPbivy9FtQUZA/1VSNQp9JbVlO1cPJ/M48R bdDI1Vbb0h7FgI67TB1kj/PsuuQA/AJkN6Df9D48fCuUKBqH0GnSKQo3r5anxwjdjBdU ZGRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:subject:cc:to:from:message-id:date; bh=0DVWav5ByT2C9v++9HNHEaC6FRUtsjzVRwQiuzrAEXY=; b=wYRJKixtGZueSUXZuciupXMHUOiP9m4xT8pwWmVf5hjyDa/WVZnWSRJBjOSe7yBY6g 80rUBrK9fLrcvXLpTEUWVwDrTwNS6J16l6WO6Sn9tk2/ikPWnLKg02xeTFG9up98FnTh NYbX4ySZbjqb6D60OGNk/hR/O/8E0wh1vFz/xg7M2wBwT4Lt+b/I+EdVZ7gDwXqyeK9Y jTZNCSV9yKYK80o/jf8wUxVzFtDoTHQFxuyhdYERdYE0zd9SAAbmTeiGpLK3jY7nhqzQ U5pyrj1690qzcV320ietCToTDRsGbkqXYUl1K+QnlblmuIU2q6RMajvC3hzDOJzMf7VE 0RIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b5si645528ejk.381.2020.06.02.23.57.11; Tue, 02 Jun 2020 23:57:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726182AbgFCGy4 (ORCPT + 99 others); Wed, 3 Jun 2020 02:54:56 -0400 Received: from mx2.suse.de ([195.135.220.15]:38324 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726167AbgFCGyz (ORCPT ); Wed, 3 Jun 2020 02:54:55 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 46BC7ABCF; Wed, 3 Jun 2020 06:54:55 +0000 (UTC) Date: Wed, 03 Jun 2020 08:54:51 +0200 Message-ID: From: Takashi Iwai To: Macpaul Lin Cc: Jaroslav Kysela , Takashi Iwai , Matthias Brugger , Alexander Tsoy , Johan Hovold , Hui Wang , Szabolcs =?UTF-8?B?U3rFkWtl?= , , , Mediatek WSD Upstream , Macpaul Lin , , , , Greg Kroah-Hartman Subject: Re: [PATCH] sound: usb: pcm: fix incorrect power state when playing sound after PM_AUTO suspend In-Reply-To: References: <1591153515.23525.50.camel@mtkswgap22> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 03 Jun 2020 08:28:09 +0200, Takashi Iwai wrote: > > And, the most suspicious case is the last one, > chip->num_suspended-intf. It means that the device has multiple > USB interfaces and they went to suspend, while the resume isn't > performed for the all suspended interfaces in return. If this is the cause, a patch like below might help. It gets/puts the all assigned interfaced instead of only the primary one. Takashi --- diff --git a/sound/usb/card.c b/sound/usb/card.c --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -634,7 +634,6 @@ static int usb_audio_probe(struct usb_interface *intf, id, &chip); if (err < 0) goto __error; - chip->pm_intf = intf; break; } else if (vid[i] != -1 || pid[i] != -1) { dev_info(&dev->dev, @@ -651,6 +650,13 @@ static int usb_audio_probe(struct usb_interface *intf, goto __error; } } + + if (chip->num_interfaces >= MAX_CARD_INTERFACES) { + dev_info(&dev->dev, "Too many interfaces assigned to the single USB-audio card\n"); + err = -EINVAL; + goto __error; + } + dev_set_drvdata(&dev->dev, chip); /* @@ -703,6 +709,7 @@ static int usb_audio_probe(struct usb_interface *intf, } usb_chip[chip->index] = chip; + chip->intf[chip->num_interfaces] = intf; chip->num_interfaces++; usb_set_intfdata(intf, chip); atomic_dec(&chip->active); @@ -818,19 +825,36 @@ void snd_usb_unlock_shutdown(struct snd_usb_audio *chip) int snd_usb_autoresume(struct snd_usb_audio *chip) { + int i, err; + if (atomic_read(&chip->shutdown)) return -EIO; - if (atomic_inc_return(&chip->active) == 1) - return usb_autopm_get_interface(chip->pm_intf); + if (atomic_inc_return(&chip->active) != 1) + return 0; + + for (i = 0; i < chip->num_interfaces; i++) { + err = usb_autopm_get_interface(chip->intf[i]); + if (err < 0) { + /* rollback */ + while (--i >= 0) + usb_autopm_put_interface(chip->intf[i]); + return err; + } + } return 0; } void snd_usb_autosuspend(struct snd_usb_audio *chip) { + int i; + if (atomic_read(&chip->shutdown)) return; - if (atomic_dec_and_test(&chip->active)) - usb_autopm_put_interface(chip->pm_intf); + if (!atomic_dec_and_test(&chip->active)) + return; + + for (i = 0; i < chip->num_interfaces; i++) + usb_autopm_put_interface(chip->intf[i]); } static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h @@ -19,11 +19,13 @@ struct media_device; struct media_intf_devnode; +#define MAX_CARD_INTERFACES 16 + struct snd_usb_audio { int index; struct usb_device *dev; struct snd_card *card; - struct usb_interface *pm_intf; + struct usb_interface *intf[MAX_CARD_INTERFACES]; u32 usb_id; struct mutex mutex; unsigned int autosuspended:1;