From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796201702; b=qaak5SfMLb7/d+uOUatw/VWoG91WyXLgI/zYv9pT3MUbblxTG9ce9W6kT7TdlUW8S+Qx xFsg4BuvnfTegdk6DQxbeycTenDpLnsqEQdWyNXv2vUqOadwe2NaCin+7i5k0kJNGioO/ 81ow41GM/WqVw2dBEdoXJyJ3t3VdaADPbId/O0/coCju8sVoy1fpu4c/9hZtnWpYPM02I NnkIbpo/6RPCz/vSsOHlMHengZET5l6IccWforkqBK3yYz0jVeRcKDn9PUAaAEVdalG7G 26zqR2C/+II9AD2ShAlnivbWY0Pv0GHeDK7JRbkm3UW2lIV4UlmyctwVndvqzcNY0Dg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796201702; h=DMARC-Filter:Received:DKIM-Signature:DKIM-Signature:DKIM-Signature: DKIM-Signature:Received:Received:Date:Message-ID:From:To:Cc:Subject: In-Reply-To:References:User-Agent:MIME-Version:Content-Type: X-Rspamd-Queue-Id:X-Spam-Level:X-Rspamd-Server:X-Rspamd-Action: X-Spam-Flag:X-Spamd-Result:X-Spam-Score; bh=As5EfmmDQuXeJyppwbj/OldgYnlQHzHq9LyA2JgBl+c=; b=5HS/5TJXADUSIiPflOaD4dJ0d3J3I3fs3cJYXYBqIwp/3Xm0gogbFEPbkGINtSafwIQI Rj2cN74+Ns2T19Jeg9ZHcTuYB60tg5wXwdkGSmxZjRpaXdsFxyz/X19YhbjhzRcQff00t jp+JGk1MurlIFeLx6NVw2fjtRRXKpPxNJwE4VjcHt39ClzCSi/ORCi0mEUB4OwrxU+IsC ywwlyMQCE3iZO2gg/2Z2mXh2QuRcCkB8pdebYx+yI9uav6ao87uOR+A7I7y9wn0ejM8Zs lbCLlOEvnZXrOBobHnlss5ads1QcxQQo7hqkOohF6kz8er0/LGOhcHq2FKaMqo2Zxww== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=wYlzBMt1; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=1J5irP09; dkim=pass header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=wYlzBMt1; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=1J5irP09; arc=none smtp.remote-ip=195.135.223.131 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6055C606A332; Wed, 2 Dec 2026 08:54:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6055C606A332 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.a=rsa-sha256 header.s=susede2_rsa header.b=wYlzBMt1; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=1J5irP09; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=wYlzBMt1; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=1J5irP09 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 2FD7B1FB48; Wed, 2 Dec 2026 08:54:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796201696; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=As5EfmmDQuXeJyppwbj/OldgYnlQHzHq9LyA2JgBl+c=; b=wYlzBMt1kUrlTXrYVSxGvfitUb8QiyRFdjN6taI0OQg0iylYkn+0VKMmcSgnv9S9iArWwx m8i7hO9aOCH2FS+K7uoqLzd9aT7tTIpDGj2rF1o6oLC31BdJGXmhCCj/e+rKMgWDZIAUrA 3AP5NzeEt/L7lCuRsr+3YaNL7c8EEZk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796201696; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=As5EfmmDQuXeJyppwbj/OldgYnlQHzHq9LyA2JgBl+c=; b=1J5irP09Se7bxUIrLOf0m20IwnHcRSxiFRftxnF8+SS6/ZvV5BXALJF1nS0dS9S7QXba/J 0/N1nx+N3vyicECg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=wYlzBMt1; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=1J5irP09 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796201696; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=As5EfmmDQuXeJyppwbj/OldgYnlQHzHq9LyA2JgBl+c=; b=wYlzBMt1kUrlTXrYVSxGvfitUb8QiyRFdjN6taI0OQg0iylYkn+0VKMmcSgnv9S9iArWwx m8i7hO9aOCH2FS+K7uoqLzd9aT7tTIpDGj2rF1o6oLC31BdJGXmhCCj/e+rKMgWDZIAUrA 3AP5NzeEt/L7lCuRsr+3YaNL7c8EEZk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796201696; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=As5EfmmDQuXeJyppwbj/OldgYnlQHzHq9LyA2JgBl+c=; b=1J5irP09Se7bxUIrLOf0m20IwnHcRSxiFRftxnF8+SS6/ZvV5BXALJF1nS0dS9S7QXba/J 0/N1nx+N3vyicECg== 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 D553D13505; Wed, 2 Dec 2026 08:54:55 +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 a/hQKt/cD2uKCQAAD6G6ig (envelope-from ); Wed, 02 Dec 2026 08:54:55 +0000 Date: Wed, 02 Dec 2026 09:54:55 +0100 Message-ID: <87jylsxdsw.wl-tiwai@suse.de> From: Takashi Iwai To: Hanxiang Xu Cc: Takashi Iwai , Jaroslav Kysela , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ALSA: control: fix find_id()/find_numid() kerneldoc and lock the usb-mixer dedup loop In-Reply-To: <20261202103400.5-1-xuhx@hust.edu.cn> References: <20261202103400.5-1-xuhx@hust.edu.cn> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/30.2 Mule/6.0 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: 2FD7B1FB48 X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Flag: NO X-Spamd-Result: default: False [-12.51 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,hust.edu.cn:email,suse.de:dkim]; DKIM_TRACE(0.00)[suse.de:+] X-Spam-Score: -12.51 On Wed, 02 Dec 2026 03:34:00 +0100, Hanxiang Xu wrote: > > With CONFIG_SND_CTL_FAST_LOOKUP the fast paths of > snd_ctl_find_id()/snd_ctl_find_numid() are unlocked xa_load() calls > that return an unreferenced struct snd_kcontrol pointer, but their > kerneldoc still states "Note that this function takes > card->controls_rwlock lock internally". Since the removal path frees > the control without a grace period, a caller that relies on that > stale statement dereferences freed memory. > > The jack-creation (get_available_index()) and vmaster-follower > (snd_ctl_add_followers()) callers already hold the lock as of > 7.4-rc5. Fix the two kerneldoc blocks and lock the remaining > unlocked caller, the dedup loop of snd_usb_mixer_add_list() (the > read lock is released before snd_ctl_add() takes the write lock). > > Cc: > Signed-off-by: Hanxiang Xu > --- > sound/core/control.c | 11 +++++++++-- > sound/usb/mixer.c | 6 ++++-- > 2 files changed, 13 insertions(+), 4 deletions(-) > > diff --git a/sound/core/control.c b/sound/core/control.c > index 42f16d2d0e79881159250a43a80063ab775b7907..1808ad405d580b50b12183e5ecfeaf7cc0849ba7 100644 > @@ -813,7 +813,10 @@ > * > * Return: The pointer of the instance if found, or %NULL if not. > * > - * Note that this function takes card->controls_rwlock lock internally. > + * Note that the returned pointer is unreferenced: with > + * CONFIG_SND_CTL_FAST_LOOKUP this is an unlocked xa_load() and the > + * control can be freed concurrently. The caller must hold > + * card->controls_rwsem or otherwise protect the returned object. > */ > struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, > unsigned int numid) > @@ -838,7 +841,11 @@ snd_ctl_find_numid_slow(struct snd_card *card, unsigned int numid) > * > * Return: The pointer of the instance if found, or %NULL if not. > * > - * Note that this function takes card->controls_rwlock lock internally. > + * Note that the returned pointer is unreferenced: with > + * CONFIG_SND_CTL_FAST_LOOKUP the hash/numid paths are unlocked > + * xa_load() calls and the control can be freed concurrently. The > + * caller must hold card->controls_rwsem or otherwise protect the > + * returned object. > */ > struct snd_kcontrol *snd_ctl_find_id(struct snd_card *card, > const struct snd_ctl_elem_id *id) The comment updates are fine, but... > diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c > index 95209ec006b3c650bffe0ad20acf66d0ee61382c..40f280a9c76ce4bf72a49e2daf0e4d1fd75c1ab1 100644 > @@ -664,8 +664,10 @@ > int err; > > if (look_for_empty) { > - while (snd_ctl_find_id(mixer->chip->card, &kctl->id)) > - kctl->id.index++; > + scoped_guard(rwsem_read, &mixer->chip->card->controls_rwsem) { > + while (snd_ctl_find_id(mixer->chip->card, &kctl->id)) > + kctl->id.index++; > + } > } > > err = snd_ctl_add(mixer->chip->card, kctl); this one is rather superfluous. This probe doesn't happen concurrently. And, if any, split to another patch. It's totally different from the documentation update itself. thanks, Takashi