From nobody Tue Apr 7 02:54:32 2026 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (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 14ABA25228D for ; Mon, 16 Mar 2026 13:40:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773668407; cv=none; b=LIs+BN+RkiIPrOq+ONjLUW5Dmssua3TOUfGAQT9bex3fGvBmXyzkkLInC5ESmTKYcgISMKYb5qzewYrr+PItZ3dQya26o5ByXqu/oRmzJYPQ3fY758K8/k9gJsYTrtjZ6bmHtuRmryvbhS8c9dr2PXxRcsOU1+7GEEnR9MIGKmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773668407; c=relaxed/simple; bh=sKyQH35ghxIj5e5o1dSdTuIDLY+HV1BGPGzDv+i/p8s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=CVcGYIvHPP/74H9UBpxBeF5710jp/VOvJe4w7gfbzeEQFtpUcR0qOZ37jDVAyd0UUnmyO4JHZbQ+w1hN72GAOn+C3NZJOVMqHN6ZbUJlBrRsyZw5wFNDPP5fJX/TSXvS72DSexmDCAU5EPf8RLmk8dKOYhmb4PFWamyzQSpdzZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=V3dpIPnf; arc=none smtp.client-ip=74.125.82.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V3dpIPnf" Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-2c0bcd8f194so1931412eec.1 for ; Mon, 16 Mar 2026 06:40:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773668405; x=1774273205; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=UAkxgZR7Mfx6piu37ajKAIMdT55O/YxifamFQJCQ4oc=; b=V3dpIPnfZFdCaPvs8RPqCsiwjdvz+ylCixv13RnHTVsj5jElWhl++5JpFa4ritFY8j ipgrJ1mL66TuqyuIX45dij3I1ccthyn+2j2BWf3s6LHHiAJvq7C6z2LzXVH7yqs4y8ho n71jFIMucZbJGeSDUFMwNTfi3b3wOYSJFPyHJJ2MMYU/voN2DDcoIjuQp1U4wJg23052 m2R8qq/XEbi9PK6POdfYVTxK8JgvsK4IjLfZdMgk6MlOOi7b0LaoX5uVIUDNbSgwmzcT 4esw7GGhQvT1xHVCrii46pz1Ooj/+TnhJrwxh29uSI+zlHCea5K9bCM+HJh8l/VGNY43 GzKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773668405; x=1774273205; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=UAkxgZR7Mfx6piu37ajKAIMdT55O/YxifamFQJCQ4oc=; b=BaIvpjIr7mgz6cAuzLBXuIF9eamWRif4gmdrFslpaVs7XMMgWndobqhnEGclRZS8XV bv41w5dCCkDLuEgPqt9WtpAHYvjml0/qd27lq9TKg0BuTqQLRKapODQoOiYDOXhy2rfv HgGyNF2+irE2LVA53RIFqAQVNXPa3f7yezA8T3DG3accEZV1tl/b/p7oL5AqXtTHjqCX MZ+L0aTEC2SPE2+r0aFMHEVW/RGhGtfjvezId9xyAfN56pY8ZnQgdWpy1BBejCR3/q8u sOjw6F/P3pMHA/gP3pwlbgfm6djxFMAWmvVQzN/KfU1QzTwlW/UEYOiskLk4tnwEtwXV v+gw== X-Forwarded-Encrypted: i=1; AJvYcCUcTc0jh00ZOXDJKTlGWdzGcOAyQHiVF6z0+nrb58tv/OfrBg7ndfo8QNH4eJ8KthuwtqNtCZMQWMiXpr8=@vger.kernel.org X-Gm-Message-State: AOJu0YzADaEbmnhyuubZgpjLmj+J4un2WO2hKmgcCE1LZ1J77F7Su08K uiTu7tTWnVuhxvk7kTnyTNwBjc8Zy0ZQ5pIKWorHjj1F7aSQSvsqYk4h X-Gm-Gg: ATEYQzyp1PUVqdqUOQjMRrU7xtv75+Nv4kmxV5ELd9TuQBwCnKQngAkm2CPU/++McjX kbKfieQGg9aUZIFVvEk+vhh/L/yQTfs3tvwEHEwAj6O7s8A7mVoY8dXErOeXo9DH0OJrIh7OdpX hoZ88OONTFHFqu0fN5kI+p9XN8u9wSySiT+Y/jSH9Bieu6HDfd48/ioiHro4nTjJO7S4jlbTABu vVm0i1xWcaYFNUL3aDHDRAG1HrNC30mCvxUys4ouMbWQLMj8/CfSnQ4Cv4RG/RANBexjqbzTlRG jHPpTwl8t1FIqZXVjk7iUUZaK07Zd/DiQO6rX4ilmHMiRaZHn7jlSe4r3M9ZQQU9lUoEtOTURRG wV69NU9CXRoBaATo4VFxUXIlnIagtKC5xo9hEbAdVUkot4UGyfe3PfCCFhexK2ILRJttE+hLALR BF1/9czHYFXE17dzj+L5A1xAOxfx6NmMQcSqqP1pDPNuxwfHm0GlLBo7p/demLICRCjhePaThUU wQ= X-Received: by 2002:a05:693c:3113:b0:2b7:fdb6:ccf6 with SMTP id 5a478bee46e88-2bea547ecd8mr5393919eec.14.1773668404850; Mon, 16 Mar 2026 06:40:04 -0700 (PDT) Received: from [192.168.1.8] (177-4-160-195.user3p.v-tal.net.br. [177.4.160.195]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2beab3a1117sm17403792eec.3.2026.03.16.06.40.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2026 06:40:04 -0700 (PDT) From: =?utf-8?q?C=C3=A1ssio_Gabriel?= Date: Mon, 16 Mar 2026 10:39:38 -0300 Subject: [PATCH] ALSA: timer: keep a list of open masters for slave lookup Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260316-alsa-timer-master-list-v1-1-fb95e547110a@gmail.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/x2MSQqAMAwAvyI5G6hVi/oV8VBtqgE3miKC+HeLp 2EOMw8IBSaBLnsg0MXCx56kyDOYFrvPhOySg1baqLIwaFexGHmjgJuVmLCyRPSaKjfWTd0aByk +A3m+/3E/vO8HAepOjGgAAAA= X-Change-ID: 20260316-alsa-timer-master-list-f2e4db58596d To: Takashi Iwai , Jaroslav Kysela Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?C=C3=A1ssio_Gabriel?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4136; i=cassiogabrielcontato@gmail.com; h=from:subject:message-id; bh=sKyQH35ghxIj5e5o1dSdTuIDLY+HV1BGPGzDv+i/p8s=; b=owGbwMvMwCV2IdZeKur/u2bG02pJDJk7OHQlKp7s65wSoWrPH2DOdbTPYYHK/OdVbFIReikXt s46wVTaUcrCIMbFICumyLI6aZHlnq4HV+vjVnjAzGFlAhnCwMUpABORu83IMHnWBaYLV9857ns3 //fC3tY+ySdPjP9nrtLS+xy27cgbi8MM/8ymHfe/O7XfctOZQ5V32h0MtKtC866+47II6VVkuVf 4gRsA X-Developer-Key: i=cassiogabrielcontato@gmail.com; a=openpgp; fpr=AB62A239BC8AE0D57F5EA848D05D3F1A5AFFEE83 snd_timer_check_slave() still walks all registered timers and all open timer instances to find a matching master for a newly opened slave. Maintain a global list of open master instances that can accept slave links and use it for the slave lookup path instead. This keeps the existing matching semantics while avoiding the nested walk over snd_timer_list and each timer open_list_head. The reverse path in snd_timer_check_master() already scans only the pending slave list, so this makes both lookup paths closer in shape without changing the master/slave linking logic. Signed-off-by: C=C3=A1ssio Gabriel --- include/sound/timer.h | 1 + sound/core/timer.c | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/sound/timer.h b/include/sound/timer.h index 760e132cc0cd..83bafe70cf33 100644 --- a/include/sound/timer.h +++ b/include/sound/timer.h @@ -102,6 +102,7 @@ struct snd_timer_instance { unsigned int slave_id; struct list_head open_list; struct list_head active_list; + struct list_head master_list; struct list_head ack_list; struct list_head slave_list_head; struct list_head slave_active_head; diff --git a/sound/core/timer.c b/sound/core/timer.c index 6a70df7ae019..820901d503af 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -129,6 +129,9 @@ static LIST_HEAD(snd_timer_list); /* list of slave instances */ static LIST_HEAD(snd_timer_slave_list); =20 +/* list of open master instances that can accept slave links */ +static LIST_HEAD(snd_timer_master_list); + /* lock for slave active lists */ static DEFINE_SPINLOCK(slave_active_lock); =20 @@ -161,6 +164,7 @@ struct snd_timer_instance *snd_timer_instance_new(const= char *owner) } INIT_LIST_HEAD(&timeri->open_list); INIT_LIST_HEAD(&timeri->active_list); + INIT_LIST_HEAD(&timeri->master_list); INIT_LIST_HEAD(&timeri->ack_list); INIT_LIST_HEAD(&timeri->slave_list_head); INIT_LIST_HEAD(&timeri->slave_active_head); @@ -245,6 +249,12 @@ static int check_matching_master_slave(struct snd_time= r_instance *master, return 1; } =20 +static bool snd_timer_has_slave_key(const struct snd_timer_instance *timer= i) +{ + return !(timeri->flags & SNDRV_TIMER_IFLG_SLAVE) && + timeri->slave_class > SNDRV_TIMER_SCLASS_NONE; +} + /* * look for a master instance matching with the slave id of the given slav= e. * when found, relink the open_link of the slave. @@ -253,19 +263,15 @@ static int check_matching_master_slave(struct snd_tim= er_instance *master, */ static int snd_timer_check_slave(struct snd_timer_instance *slave) { - struct snd_timer *timer; struct snd_timer_instance *master; int err =3D 0; =20 - /* FIXME: it's really dumb to look up all entries.. */ - list_for_each_entry(timer, &snd_timer_list, device_list) { - list_for_each_entry(master, &timer->open_list_head, open_list) { - err =3D check_matching_master_slave(master, slave); - if (err !=3D 0) /* match found or error */ - goto out; - } + list_for_each_entry(master, &snd_timer_master_list, master_list) { + err =3D check_matching_master_slave(master, slave); + if (err !=3D 0) /* match found or error */ + goto out; } - out: +out: return err < 0 ? err : 0; } =20 @@ -377,6 +383,8 @@ int snd_timer_open(struct snd_timer_instance *timeri, timeri->slave_id =3D slave_id; =20 list_add_tail(&timeri->open_list, &timer->open_list_head); + if (snd_timer_has_slave_key(timeri)) + list_add_tail(&timeri->master_list, &snd_timer_master_list); timer->num_instances++; err =3D snd_timer_check_master(timeri); list_added: @@ -431,6 +439,9 @@ static void snd_timer_close_locked(struct snd_timer_ins= tance *timeri, num_slaves--; } =20 + if (!list_empty(&timeri->master_list)) + list_del_init(&timeri->master_list); + /* force to stop the timer */ snd_timer_stop(timeri); =20 --- base-commit: 6447e32cb0a0b05b75d7a591501660ac3cfe5c31 change-id: 20260316-alsa-timer-master-list-f2e4db58596d Best regards, --=20 C=C3=A1ssio Gabriel