Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49A0CC2D0A3 for ; Tue, 10 Nov 2020 03:21:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D31982067B for ; Tue, 10 Nov 2020 03:21:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="Z/2TE/jA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729706AbgKJDVX (ORCPT ); Mon, 9 Nov 2020 22:21:23 -0500 Received: from mail.codeweavers.com ([50.203.203.244]:42478 "EHLO mail.codeweavers.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729243AbgKJDVX (ORCPT ); Mon, 9 Nov 2020 22:21:23 -0500 X-Greylist: delayed 1027 seconds by postgrey-1.27 at vger.kernel.org; Mon, 09 Nov 2020 22:21:23 EST DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=6377696661; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=/ZuODjsCGNjBdFOIqlZlXT70GJUC3IHxOLn8UfvUPCw=; b=Z/2TE/jAK4uvAAK8H30hGo+5/r kbtQ3MM5J5h2DnTf7S4CNKqs47a5EaqkmIOwCleS9zUszCh7Z0bZpdIbwIsw+1nPsGnBNcc2UNycy pbt6aXbdCDFfygBaWZpfp3QcvmJKNmbM4e6UmAfHcRtGF4F+y/A2VME1ReTevTQM0cR4=; Received: from [64.191.7.9] (helo=watership.localdomain) by mail.codeweavers.com with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kcJx7-0001gI-Q7; Mon, 09 Nov 2020 21:04:15 -0600 From: Zebediah Figura To: linux-media@vger.kernel.org Cc: Zebediah Figura Subject: [PATCH] media: cx231xx: Use snd_card_free_when_closed() instead of snd_card_free(). Date: Mon, 9 Nov 2020 21:04:03 -0600 Message-Id: <20201110030403.118606-1-zfigura@codeweavers.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org cx231xx_close_extension and hence cx231xx_audio_fini() are called with the cx231xx device lock held, but snd_cx231xx_pcm_close() also grabs that mutex when closing the file on behalf of arecord. There seems to be no reason to wait for sound card resources to be released, so let the release be asynchronous. Tested with a Hauppauge 955Q (2040:b123) and Linux 5.9.6; the hang described in the bug no longer occurs and disconnecting the device correctly terminates arecord with ENODEV. Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=204087 Signed-off-by: Zebediah Figura --- On the model of the USB audio driver (among others), I am inclined to believe this is a correct approach. I have also tried to check for any potential use-after-free bugs that might occur as a result of this patch, and been unable to easily find any. However, as a new contributor, I am not familiar with the USB, ALSA, or DVB frameworks, and there is a good chance that I have missed something. drivers/media/usb/cx231xx/cx231xx-audio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/usb/cx231xx/cx231xx-audio.c b/drivers/media/usb/cx231xx/cx231xx-audio.c index de42db6f6ad1..9c71b32552df 100644 --- a/drivers/media/usb/cx231xx/cx231xx-audio.c +++ b/drivers/media/usb/cx231xx/cx231xx-audio.c @@ -670,7 +670,7 @@ static int cx231xx_audio_fini(struct cx231xx *dev) } if (dev->adev.sndcard) { - snd_card_free(dev->adev.sndcard); + snd_card_free_when_closed(dev->adev.sndcard); kfree(dev->adev.alt_max_pkt_size); dev->adev.sndcard = NULL; } -- 2.29.2