From patchwork Wed Nov 13 11:10:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13873438 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 532901FEFDF for ; Wed, 13 Nov 2024 11:10:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496255; cv=none; b=g87PPKgqPJXoSZHvHo6nnmoUmB7MkYH81ZuLGM1itrR7cmMbL2hdoWaZGGzQ0m1qiTvKqOdEuoHgmMSnQQX0HuqSFVTsAkTLjrBOwpX91ezX9gUFx0BZD/naO2xIt0scDGWlenpI95bwPnQ6py20m4BiNRrBgLz7jAkljoL99WM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496255; c=relaxed/simple; bh=SHFRqUBjU4SvvOhAbHK9FlcP6pDBs1xP/EGXgCblm+s=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QRzVO5UMyivmgm1dg+AUFH6wwkJK4Vfge2anyDnKpSEZt+d+wPvgUwAE0AEvYncnFc73pHxkXVPhxJLq1Ri7j5Orwkxf9RjLiyTZGt96tpnC1TEcl18bR/1YcPZVCQ2h6piG1wzPiFJcLKtv1MBeuKeFjNyYLBa7YFZ6/fTNDaQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=OoNT9188; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=5nZNH6L2; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=OoNT9188; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=5nZNH6L2; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="OoNT9188"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="5nZNH6L2"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="OoNT9188"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="5nZNH6L2" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 27DE5211CD; Wed, 13 Nov 2024 11:10:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FEYrPZzHtT3fJElWHZ8R4mXX1v7sCAViocUahfORo98=; b=OoNT9188NhmpVIWUYD/g7LrfbjzZtOIP7nyQ1TsInAxzGyf7naWMEzvveKSvmJAkIwPHPq yZF5hzNNdACBnAHHamQJvfL+lOEXarRdRhDC/Dcy7CBzZ+cqGu7vkHUOC6QFaKiQXUye+w E2wircEAnHv1+it4HPEqBC2XHK8/NPc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FEYrPZzHtT3fJElWHZ8R4mXX1v7sCAViocUahfORo98=; b=5nZNH6L2QWxj8GUBIZeb877eZz2HFWIaoFA9b3c5XzgPnJd0kcgXu8xFKYsGh/xx+TD7aV 6pjzwl71XLr2nkDg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FEYrPZzHtT3fJElWHZ8R4mXX1v7sCAViocUahfORo98=; b=OoNT9188NhmpVIWUYD/g7LrfbjzZtOIP7nyQ1TsInAxzGyf7naWMEzvveKSvmJAkIwPHPq yZF5hzNNdACBnAHHamQJvfL+lOEXarRdRhDC/Dcy7CBzZ+cqGu7vkHUOC6QFaKiQXUye+w E2wircEAnHv1+it4HPEqBC2XHK8/NPc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FEYrPZzHtT3fJElWHZ8R4mXX1v7sCAViocUahfORo98=; b=5nZNH6L2QWxj8GUBIZeb877eZz2HFWIaoFA9b3c5XzgPnJd0kcgXu8xFKYsGh/xx+TD7aV 6pjzwl71XLr2nkDg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0F36813AE3; Wed, 13 Nov 2024 11:10:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id oHtfAjaJNGe3UgAAD6G6ig (envelope-from ); Wed, 13 Nov 2024 11:10:46 +0000 From: Takashi Iwai To: linux-sound@vger.kernel.org Subject: [PATCH 1/5] ALSA: usx2y: Use snd_card_free_when_closed() at disconnection Date: Wed, 13 Nov 2024 12:10:35 +0100 Message-ID: <20241113111042.15058-2-tiwai@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241113111042.15058-1-tiwai@suse.de> References: <20241113111042.15058-1-tiwai@suse.de> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[syzkaller.appspot.com:url,suse.de:email,suse.de:mid]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Flag: NO The USB disconnect callback is supposed to be short and not too-long waiting. OTOH, the current code uses snd_card_free() at disconnection, but this waits for the close of all used fds, hence it can take long. It eventually blocks the upper layer USB ioctls, which may trigger a soft lockup. An easy workaround is to replace snd_card_free() with snd_card_free_when_closed(). This variant returns immediately while the release of resources is done asynchronously by the card device release at the last close. Fixes: 230cd5e24853 ("[ALSA] prevent oops & dead keyboard on usb unplugging while the device is be ing used") Reported-by: syzbot+73582d08864d8268b6fd@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=73582d08864d8268b6fd Signed-off-by: Takashi Iwai --- sound/usb/usx2y/usbusx2y.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/usb/usx2y/usbusx2y.c b/sound/usb/usx2y/usbusx2y.c index 2f9cede242b3..5f81c68fd42b 100644 --- a/sound/usb/usx2y/usbusx2y.c +++ b/sound/usb/usx2y/usbusx2y.c @@ -422,7 +422,7 @@ static void snd_usx2y_disconnect(struct usb_interface *intf) } if (usx2y->us428ctls_sharedmem) wake_up(&usx2y->us428ctls_wait_queue_head); - snd_card_free(card); + snd_card_free_when_closed(card); } static int snd_usx2y_probe(struct usb_interface *intf, From patchwork Wed Nov 13 11:10:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13873436 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1463A1FDFBA for ; Wed, 13 Nov 2024 11:10:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496250; cv=none; b=ENFAXLUY9Bo9XdhfOpbTqTKKNyLeuPY/cEzfcYIiSqEYHMapnsTXgsOaCHBlmcjx01D/OZ9hPo52P9p93hhtny5omLdu/8IyahKWdOARZxKkNSmLlqqohlduJACH1Yxq2OCEKhitzf4p1iuvOMTtWtmyVxINGJTV8s+uZQRopvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496250; c=relaxed/simple; bh=j6gSxfRnzrhCbZAR157s9+Qkgs0pGRxRwm1G7R/tD2c=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iQTKCLxk53by+nI7G3iKoAToZ7oqrO5RKE29ks1/ega3Q2XYzmt4P6PwGD8jpaoUqshbQqxeEF9y2TeNyAiZrFPrwfd5tDcDSB0Wh6RYxyRvNHzRqkd5kk+51bWk5Nj/rzcgqqeiznStBLVKIJZFcq8OPsE4xvpKqE6JoTm7Go4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=ByGpY6CG; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=4GFKoJ+v; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=ByGpY6CG; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=4GFKoJ+v; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ByGpY6CG"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="4GFKoJ+v"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ByGpY6CG"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="4GFKoJ+v" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4FE3C1F38C; Wed, 13 Nov 2024 11:10:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DkCU0pI44EbXKVEJZ7z8wt+JZ9PcIL1nv5AI6h2c0Po=; b=ByGpY6CGl7K0THNJffTIIev8NjDL8TdEDahj+1MjDdAAvNVM+OrAfv339SwVQP7SJXbjqg 3W8/DWvOhbX+VvSkp/1I871q9tRFQWVUwCt58KCUDsesSMntzFEhRQB2qdvyAZHBhJImFC Vb5pvfcRoHqyetsh4nb+Jwmb0/kOpUE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DkCU0pI44EbXKVEJZ7z8wt+JZ9PcIL1nv5AI6h2c0Po=; b=4GFKoJ+vOldAgWPACYgelgq9nY9FaW4vqfTN4k8NZoMi7EfY2Py0DUL8RjbYeGSy+b1ACb qtp10CU35cQZKwAA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ByGpY6CG; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=4GFKoJ+v DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DkCU0pI44EbXKVEJZ7z8wt+JZ9PcIL1nv5AI6h2c0Po=; b=ByGpY6CGl7K0THNJffTIIev8NjDL8TdEDahj+1MjDdAAvNVM+OrAfv339SwVQP7SJXbjqg 3W8/DWvOhbX+VvSkp/1I871q9tRFQWVUwCt58KCUDsesSMntzFEhRQB2qdvyAZHBhJImFC Vb5pvfcRoHqyetsh4nb+Jwmb0/kOpUE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DkCU0pI44EbXKVEJZ7z8wt+JZ9PcIL1nv5AI6h2c0Po=; b=4GFKoJ+vOldAgWPACYgelgq9nY9FaW4vqfTN4k8NZoMi7EfY2Py0DUL8RjbYeGSy+b1ACb qtp10CU35cQZKwAA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3227813301; Wed, 13 Nov 2024 11:10:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id IJ4ECzaJNGe3UgAAD6G6ig (envelope-from ); Wed, 13 Nov 2024 11:10:46 +0000 From: Takashi Iwai To: linux-sound@vger.kernel.org Subject: [PATCH 2/5] ALSA: us122l: Use snd_card_free_when_closed() at disconnection Date: Wed, 13 Nov 2024 12:10:36 +0100 Message-ID: <20241113111042.15058-3-tiwai@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241113111042.15058-1-tiwai@suse.de> References: <20241113111042.15058-1-tiwai@suse.de> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4FE3C1F38C X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_DN_NONE(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,suse.de:mid]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Spam-Flag: NO The USB disconnect callback is supposed to be short and not too-long waiting. OTOH, the current code uses snd_card_free() at disconnection, but this waits for the close of all used fds, hence it can take long. It eventually blocks the upper layer USB ioctls, which may trigger a soft lockup. An easy workaround is to replace snd_card_free() with snd_card_free_when_closed(). This variant returns immediately while the release of resources is done asynchronously by the card device release at the last close. The loop of us122l->mmap_count check is dropped as well. The check is useless for the asynchronous operation with *_when_closed(). Fixes: 030a07e44129 ("ALSA: Add USB US122L driver") Signed-off-by: Takashi Iwai --- sound/usb/usx2y/us122l.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c index 1be0e980feb9..ca5fac03ec79 100644 --- a/sound/usb/usx2y/us122l.c +++ b/sound/usb/usx2y/us122l.c @@ -606,10 +606,7 @@ static void snd_us122l_disconnect(struct usb_interface *intf) usb_put_intf(usb_ifnum_to_if(us122l->dev, 1)); usb_put_dev(us122l->dev); - while (atomic_read(&us122l->mmap_count)) - msleep(500); - - snd_card_free(card); + snd_card_free_when_closed(card); } static int snd_us122l_suspend(struct usb_interface *intf, pm_message_t message) From patchwork Wed Nov 13 11:10:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13873435 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 146961FE0EB for ; Wed, 13 Nov 2024 11:10:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496249; cv=none; b=ME0mujOGstLCldrBVoAtA1NfzHL25E5IQSmBa47n/o8G1ufmoUphvrmJTh/o7rOfMSo5EU8HFSYpgV8XvJsHdHDAkHacqQgD+8j0yJYTCPEjS/Epp2osHMbobUdlYe+peD7NM298ip9grOR/Zg26QApDTNuHhwkVu0d7IDMeTHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496249; c=relaxed/simple; bh=z9c4ZlwpR5IpFOyWCXbKrN2DtHZVam5uRc1k0BDl8PM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aw/21hcZuocRmkGPk1sIHaXa7DtC7v7NiuMJl319iT9uG15kyO+KadvDEd8DWDi2O5Mkblv4XMTfrEvUBscIRY+bvlqL62IfFSVW1wkzDtBvgGIH2Kbhylp9+1OiC4ilvrcKCCBgsMXDlLRENccq2wQFHHLDSMApcLIk8J7+MsQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=GLSLZqom; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=nA6cPbNL; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=GLSLZqom; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=nA6cPbNL; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="GLSLZqom"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="nA6cPbNL"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="GLSLZqom"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="nA6cPbNL" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 714AC1F399; Wed, 13 Nov 2024 11:10:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L9iHD7ZRv80KBf28sc2u8+9NwHpQZ1EMb6WNtgk5dFY=; b=GLSLZqomfe3Q62193yKETzM+U+37aKo7ITyG13vCK2vx9TnaBy2DYx1IAfVLuqYmRbm9cS BQxhQY67tihE9+xTCPKr7CfAimvj6BAqNzALkD/+T6zwY5PZeMcT6S7BaLlUddXiUu5zmc S3DZLxWP6sJwL6peDUOXZg2MIpMfycs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L9iHD7ZRv80KBf28sc2u8+9NwHpQZ1EMb6WNtgk5dFY=; b=nA6cPbNLMkBIfLp2yafZ8MUl1gUVn3ZgNDOYhOqxDMzNW1icpN2IewHz7Yi1VeE2ft12Hz ms4CPLPegIn35kBA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=GLSLZqom; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=nA6cPbNL DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L9iHD7ZRv80KBf28sc2u8+9NwHpQZ1EMb6WNtgk5dFY=; b=GLSLZqomfe3Q62193yKETzM+U+37aKo7ITyG13vCK2vx9TnaBy2DYx1IAfVLuqYmRbm9cS BQxhQY67tihE9+xTCPKr7CfAimvj6BAqNzALkD/+T6zwY5PZeMcT6S7BaLlUddXiUu5zmc S3DZLxWP6sJwL6peDUOXZg2MIpMfycs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L9iHD7ZRv80KBf28sc2u8+9NwHpQZ1EMb6WNtgk5dFY=; b=nA6cPbNLMkBIfLp2yafZ8MUl1gUVn3ZgNDOYhOqxDMzNW1icpN2IewHz7Yi1VeE2ft12Hz ms4CPLPegIn35kBA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 52B8813AE6; Wed, 13 Nov 2024 11:10:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id GHr2EjaJNGe3UgAAD6G6ig (envelope-from ); Wed, 13 Nov 2024 11:10:46 +0000 From: Takashi Iwai To: linux-sound@vger.kernel.org Subject: [PATCH 3/5] ALSA: us122l: Drop mmap_count field Date: Wed, 13 Nov 2024 12:10:37 +0100 Message-ID: <20241113111042.15058-4-tiwai@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241113111042.15058-1-tiwai@suse.de> References: <20241113111042.15058-1-tiwai@suse.de> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 714AC1F399 X-Spam-Score: -3.01 X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_DN_NONE(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:mid,suse.de:email]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Flag: NO X-Spam-Level: us122l.mmap_count field was used for counting the hwdep mmap opens and syncing at disconnection. But such a manual sync isn't needed, as the refcount check is done in the ALSA core side. So let's drop it. Signed-off-by: Takashi Iwai --- sound/usb/usx2y/us122l.c | 16 ---------------- sound/usb/usx2y/us122l.h | 2 -- 2 files changed, 18 deletions(-) diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c index ca5fac03ec79..6bcf8b859ebb 100644 --- a/sound/usb/usx2y/us122l.c +++ b/sound/usb/usx2y/us122l.c @@ -89,13 +89,6 @@ static void pt_info_set(struct usb_device *dev, u8 v) v, 0, NULL, 0, 1000, GFP_NOIO); } -static void usb_stream_hwdep_vm_open(struct vm_area_struct *area) -{ - struct us122l *us122l = area->vm_private_data; - - atomic_inc(&us122l->mmap_count); -} - static vm_fault_t usb_stream_hwdep_vm_fault(struct vm_fault *vmf) { unsigned long offset; @@ -132,17 +125,9 @@ static vm_fault_t usb_stream_hwdep_vm_fault(struct vm_fault *vmf) return VM_FAULT_SIGBUS; } -static void usb_stream_hwdep_vm_close(struct vm_area_struct *area) -{ - struct us122l *us122l = area->vm_private_data; - - atomic_dec(&us122l->mmap_count); -} static const struct vm_operations_struct usb_stream_hwdep_vm_ops = { - .open = usb_stream_hwdep_vm_open, .fault = usb_stream_hwdep_vm_fault, - .close = usb_stream_hwdep_vm_close, }; static int usb_stream_hwdep_open(struct snd_hwdep *hw, struct file *file) @@ -218,7 +203,6 @@ static int usb_stream_hwdep_mmap(struct snd_hwdep *hw, if (!read) vm_flags_set(area, VM_DONTEXPAND); area->vm_private_data = us122l; - atomic_inc(&us122l->mmap_count); out: mutex_unlock(&us122l->mutex); return err; diff --git a/sound/usb/usx2y/us122l.h b/sound/usb/usx2y/us122l.h index c32ae5e981e9..8e59b78d3514 100644 --- a/sound/usb/usx2y/us122l.h +++ b/sound/usb/usx2y/us122l.h @@ -16,8 +16,6 @@ struct us122l { struct file *slave; struct list_head midi_list; - atomic_t mmap_count; - bool is_us144; }; From patchwork Wed Nov 13 11:10:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13873439 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 531991FEFA6 for ; Wed, 13 Nov 2024 11:10:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496255; cv=none; b=k9kTcyfyVXJRS/vwrNlm1L+ZXx3kqxH3es1UlPU3kvYw1z/MOJdL9NJvGUCDVXGFKv0f9itjt510q9alUzuhbAz3Ba3gf0GUArS5IVajL9J8jkFzjVNEIPLBKaoHfSA9HKk18Eo3OcINtNRvxByqEQj/da8Hp0XRGcEeGuuVelk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496255; c=relaxed/simple; bh=n8kk9fAdulkxyo5yiwKDBqWKVID99Q+2VGSJwhUTXCg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DiJdynBCEhEBilNzzh65Qe9PwLS/uG2XK1ZuqfWhXz5OwyUypC7yICGL8YB//Ra2U7ZPFplDxnqeu3mVu5Y+B7+I2oL0QRSynyksZiLFKPze6X6ItAAJtM6Wd2Rnj4kyLTN7nlvOBUmyMKDP3RmFWSqyuoUrd2DFUk+LK0QR+Kg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=CzhjNl1y; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=F8U76HdI; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=CzhjNl1y; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=F8U76HdI; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="CzhjNl1y"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="F8U76HdI"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="CzhjNl1y"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="F8U76HdI" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 90247211CF; Wed, 13 Nov 2024 11:10:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+EEvaJUTdqv5jMUtdBpCHUSV0Zi1wZ54yuBvEmB8Mi8=; b=CzhjNl1yH1htso7898FcZSgzeM4clLcWYil8YjKK5PO/iFX1edkxQqCrNLDCgMnzwP8YgO u6uQ7M4uS09cFFLr5wsurnSoaDAAEYSSiRB6UGPyeoJRENg5dEMl5Or90YFdtuURKwY5Vp JsMo4u0MfoeRj/H7sU0HcYZ8f3Iy9DA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+EEvaJUTdqv5jMUtdBpCHUSV0Zi1wZ54yuBvEmB8Mi8=; b=F8U76HdIR7l206mpZEeP4Z0sjpkkNmAhh5SBcw+229tqnbLZKTVHlnFBsQSuA/x4n5yV3/ 5rQABDoFRUMe7HBQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+EEvaJUTdqv5jMUtdBpCHUSV0Zi1wZ54yuBvEmB8Mi8=; b=CzhjNl1yH1htso7898FcZSgzeM4clLcWYil8YjKK5PO/iFX1edkxQqCrNLDCgMnzwP8YgO u6uQ7M4uS09cFFLr5wsurnSoaDAAEYSSiRB6UGPyeoJRENg5dEMl5Or90YFdtuURKwY5Vp JsMo4u0MfoeRj/H7sU0HcYZ8f3Iy9DA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+EEvaJUTdqv5jMUtdBpCHUSV0Zi1wZ54yuBvEmB8Mi8=; b=F8U76HdIR7l206mpZEeP4Z0sjpkkNmAhh5SBcw+229tqnbLZKTVHlnFBsQSuA/x4n5yV3/ 5rQABDoFRUMe7HBQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7679313AE3; Wed, 13 Nov 2024 11:10:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id +JKaGzaJNGe3UgAAD6G6ig (envelope-from ); Wed, 13 Nov 2024 11:10:46 +0000 From: Takashi Iwai To: linux-sound@vger.kernel.org Subject: [PATCH 4/5] ALSA: caiaq: Use snd_card_free_when_closed() at disconnection Date: Wed, 13 Nov 2024 12:10:38 +0100 Message-ID: <20241113111042.15058-5-tiwai@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241113111042.15058-1-tiwai@suse.de> References: <20241113111042.15058-1-tiwai@suse.de> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.977]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Flag: NO The USB disconnect callback is supposed to be short and not too-long waiting. OTOH, the current code uses snd_card_free() at disconnection, but this waits for the close of all used fds, hence it can take long. It eventually blocks the upper layer USB ioctls, which may trigger a soft lockup. An easy workaround is to replace snd_card_free() with snd_card_free_when_closed(). This variant returns immediately while the release of resources is done asynchronously by the card device release at the last close. This patch also splits the code to the disconnect and the free phases; the former is called immediately at the USB disconnect callback while the latter is called from the card destructor. Fixes: 523f1dce3743 ("[ALSA] Add Native Instrument usb audio device support") Signed-off-by: Takashi Iwai --- sound/usb/caiaq/audio.c | 10 ++++++++-- sound/usb/caiaq/audio.h | 1 + sound/usb/caiaq/device.c | 19 +++++++++++++++---- sound/usb/caiaq/input.c | 12 +++++++++--- sound/usb/caiaq/input.h | 1 + 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c index 772c0ecb7077..05f964347ed6 100644 --- a/sound/usb/caiaq/audio.c +++ b/sound/usb/caiaq/audio.c @@ -858,14 +858,20 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *cdev) return 0; } -void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *cdev) +void snd_usb_caiaq_audio_disconnect(struct snd_usb_caiaqdev *cdev) { struct device *dev = caiaqdev_to_dev(cdev); dev_dbg(dev, "%s(%p)\n", __func__, cdev); stream_stop(cdev); +} + +void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *cdev) +{ + struct device *dev = caiaqdev_to_dev(cdev); + + dev_dbg(dev, "%s(%p)\n", __func__, cdev); free_urbs(cdev->data_urbs_in); free_urbs(cdev->data_urbs_out); kfree(cdev->data_cb_info); } - diff --git a/sound/usb/caiaq/audio.h b/sound/usb/caiaq/audio.h index 869bf6264d6a..07f5d064456c 100644 --- a/sound/usb/caiaq/audio.h +++ b/sound/usb/caiaq/audio.h @@ -3,6 +3,7 @@ #define CAIAQ_AUDIO_H int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *cdev); +void snd_usb_caiaq_audio_disconnect(struct snd_usb_caiaqdev *cdev); void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *cdev); #endif /* CAIAQ_AUDIO_H */ diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c index b5cbf1f195c4..dfd820483849 100644 --- a/sound/usb/caiaq/device.c +++ b/sound/usb/caiaq/device.c @@ -376,6 +376,17 @@ static void setup_card(struct snd_usb_caiaqdev *cdev) dev_err(dev, "Unable to set up control system (ret=%d)\n", ret); } +static void card_free(struct snd_card *card) +{ + struct snd_usb_caiaqdev *cdev = caiaqdev(card); + +#ifdef CONFIG_SND_USB_CAIAQ_INPUT + snd_usb_caiaq_input_free(cdev); +#endif + snd_usb_caiaq_audio_free(cdev); + usb_reset_device(cdev->chip.dev); +} + static int create_card(struct usb_device *usb_dev, struct usb_interface *intf, struct snd_card **cardp) @@ -489,6 +500,7 @@ static int init_card(struct snd_usb_caiaqdev *cdev) cdev->vendor_name, cdev->product_name, usbpath); setup_card(cdev); + card->private_free = card_free; return 0; err_kill_urb: @@ -534,15 +546,14 @@ static void snd_disconnect(struct usb_interface *intf) snd_card_disconnect(card); #ifdef CONFIG_SND_USB_CAIAQ_INPUT - snd_usb_caiaq_input_free(cdev); + snd_usb_caiaq_input_disconnect(cdev); #endif - snd_usb_caiaq_audio_free(cdev); + snd_usb_caiaq_audio_disconnect(cdev); usb_kill_urb(&cdev->ep1_in_urb); usb_kill_urb(&cdev->midi_out_urb); - snd_card_free(card); - usb_reset_device(interface_to_usbdev(intf)); + snd_card_free_when_closed(card); } diff --git a/sound/usb/caiaq/input.c b/sound/usb/caiaq/input.c index 84f26dce7f5d..a9130891bb69 100644 --- a/sound/usb/caiaq/input.c +++ b/sound/usb/caiaq/input.c @@ -829,15 +829,21 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *cdev) return ret; } -void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *cdev) +void snd_usb_caiaq_input_disconnect(struct snd_usb_caiaqdev *cdev) { if (!cdev || !cdev->input_dev) return; usb_kill_urb(cdev->ep4_in_urb); + input_unregister_device(cdev->input_dev); +} + +void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *cdev) +{ + if (!cdev || !cdev->input_dev) + return; + usb_free_urb(cdev->ep4_in_urb); cdev->ep4_in_urb = NULL; - - input_unregister_device(cdev->input_dev); cdev->input_dev = NULL; } diff --git a/sound/usb/caiaq/input.h b/sound/usb/caiaq/input.h index c42891e7be88..fbe267f85d02 100644 --- a/sound/usb/caiaq/input.h +++ b/sound/usb/caiaq/input.h @@ -4,6 +4,7 @@ void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev *cdev, char *buf, unsigned int len); int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *cdev); +void snd_usb_caiaq_input_disconnect(struct snd_usb_caiaqdev *cdev); void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *cdev); #endif From patchwork Wed Nov 13 11:10:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13873440 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4689B1AC427 for ; Wed, 13 Nov 2024 11:10:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496255; cv=none; b=mVsWT5V/mWRI9QWp7YL8FypLDQvbRi76iqB86uuXwNthgAHn+Ktdx2sXEZARjHAjZN9+db7TW7wAYpGpPF4zTgv2OSDmLtix5HKTmaG2zIOgqe3fFvvDDhqGX0/iIXuSZDYIvPMbHGDZ2n73aEE0PCYo0pCtkbhZY8EyVjy1Smc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496255; c=relaxed/simple; bh=h0kheS2rTC1Ne6UzIbajj5dBPzgqR4oGMTT/LXF7ZpQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PGZlr9L5lAwCBEroOUih7jDalxHk10mt+DwmCXlunP33PKlRXgbQ9zsWVEa4qCOGbc09KLlBuRwRSrj9NPIBozWooEDN+GhYzUckSzgCoqHyNdmdZ/6xOf8al03MoBm3UkqSI+9XLolSDmknV0CAMufT3YOYNgkrc6PzLEYOkSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=SdSrm5o4; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=5qqItf3S; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=SdSrm5o4; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=5qqItf3S; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="SdSrm5o4"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="5qqItf3S"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="SdSrm5o4"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="5qqItf3S" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B368D211D0; Wed, 13 Nov 2024 11:10:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=umwm5iVF5t7iDU7YBE3mKtrWNtGE6HgJMuiAWjRE/t8=; b=SdSrm5o4iM9PoI/udugrFJtvwnwcJyyQHHx7PD8K60wNY7k9hRAMbJYy/egi8gH/RWySpk 4Lk+TU0ZfBq8NVqV/JfTJbAaVyIY+iKhynagwfF9tvfw+ZL9gDeGUxYnCCBfrM5dBiMpVO uCFQe/ntI+OSNgo7b1rGdw/sGWX7A2U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=umwm5iVF5t7iDU7YBE3mKtrWNtGE6HgJMuiAWjRE/t8=; b=5qqItf3SYop/7K+9RSG3uCnkFXvR40hcfJkjamHj5dX3xghX+U6thp0cMgsH8sQy+1LfAA Q4DSRCVFDNGHieAw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=SdSrm5o4; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=5qqItf3S DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=umwm5iVF5t7iDU7YBE3mKtrWNtGE6HgJMuiAWjRE/t8=; b=SdSrm5o4iM9PoI/udugrFJtvwnwcJyyQHHx7PD8K60wNY7k9hRAMbJYy/egi8gH/RWySpk 4Lk+TU0ZfBq8NVqV/JfTJbAaVyIY+iKhynagwfF9tvfw+ZL9gDeGUxYnCCBfrM5dBiMpVO uCFQe/ntI+OSNgo7b1rGdw/sGWX7A2U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731496246; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=umwm5iVF5t7iDU7YBE3mKtrWNtGE6HgJMuiAWjRE/t8=; b=5qqItf3SYop/7K+9RSG3uCnkFXvR40hcfJkjamHj5dX3xghX+U6thp0cMgsH8sQy+1LfAA Q4DSRCVFDNGHieAw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 96C7D13301; Wed, 13 Nov 2024 11:10:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id SFZrIzaJNGe3UgAAD6G6ig (envelope-from ); Wed, 13 Nov 2024 11:10:46 +0000 From: Takashi Iwai To: linux-sound@vger.kernel.org Subject: [PATCH 5/5] ALSA: 6fire: Release resources at card release Date: Wed, 13 Nov 2024 12:10:39 +0100 Message-ID: <20241113111042.15058-6-tiwai@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241113111042.15058-1-tiwai@suse.de> References: <20241113111042.15058-1-tiwai@suse.de> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: B368D211D0 X-Spam-Score: -3.01 X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_DN_NONE(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:mid,suse.de:email]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Flag: NO X-Spam-Level: The current 6fire code tries to release the resources right after the call of usb6fire_chip_abort(). But at this moment, the card object might be still in use (as we're calling snd_card_free_when_closed()). For avoid potential UAFs, move the release of resources to the card's private_free instead of the manual call of usb6fire_chip_destroy() at the USB disconnect callback. Fixes: c6d43ba816d1 ("ALSA: usb/6fire - Driver for TerraTec DMX 6Fire USB") Signed-off-by: Takashi Iwai --- sound/usb/6fire/chip.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sound/usb/6fire/chip.c b/sound/usb/6fire/chip.c index 33e962178c93..d562a30b087f 100644 --- a/sound/usb/6fire/chip.c +++ b/sound/usb/6fire/chip.c @@ -61,8 +61,10 @@ static void usb6fire_chip_abort(struct sfire_chip *chip) } } -static void usb6fire_chip_destroy(struct sfire_chip *chip) +static void usb6fire_card_free(struct snd_card *card) { + struct sfire_chip *chip = card->private_data; + if (chip) { if (chip->pcm) usb6fire_pcm_destroy(chip); @@ -72,8 +74,6 @@ static void usb6fire_chip_destroy(struct sfire_chip *chip) usb6fire_comm_destroy(chip); if (chip->control) usb6fire_control_destroy(chip); - if (chip->card) - snd_card_free(chip->card); } } @@ -136,6 +136,7 @@ static int usb6fire_chip_probe(struct usb_interface *intf, chip->regidx = regidx; chip->intf_count = 1; chip->card = card; + card->private_free = usb6fire_card_free; ret = usb6fire_comm_init(chip); if (ret < 0) @@ -162,7 +163,7 @@ static int usb6fire_chip_probe(struct usb_interface *intf, return 0; destroy_chip: - usb6fire_chip_destroy(chip); + snd_card_free(card); return ret; } @@ -181,7 +182,6 @@ static void usb6fire_chip_disconnect(struct usb_interface *intf) chip->shutdown = true; usb6fire_chip_abort(chip); - usb6fire_chip_destroy(chip); } } }