From nobody Tue Jan 28 14:05:06 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Yj6Vp3Hbgz5lVBj; Tue, 28 Jan 2025 14:05:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Yj6Vp1q8xz3Swg; Tue, 28 Jan 2025 14:05:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1738073106; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6VYu/Xwzu6RTZKYvhDl/In48b5asbxR48LneOvNiszg=; b=f+rnBdEPTyXfVJXQvS7ZKBZThO/KRx2D6O4v1Kq26Rhcg/9L4qwi/WF1Rxnjw4ZRzv/JIG 5x9EJpEyeUnS0IwyzwLZJf0C9E70a41IgtBBYQYwtp4tj67g458KfhjNjmBPE61NUcrecL Bts6Ti3oQg72yrjyUJ0p1rGvu3REYv0XGww5ISN9WBwEJhX5msz+jFJY/Berqp+TaXt7m8 a9lPSRn83IIPYoEKeg+m9wf2faPie0rfRZDm0CEQQNJ5Asl4ZUx2/eK6eJUZhEaHeRURPl WUzDohwOV9rdtVLUeNc806gXRGXV6Z3SVWjQyCOlKTCbQ7+PUlmjvK+Mcb82fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1738073106; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6VYu/Xwzu6RTZKYvhDl/In48b5asbxR48LneOvNiszg=; b=tdVAtyt9fzP4YEl0t1DOuAx+shvU2ZloyleLSPU/XWYmReZLYwGrfdMGYZ1hKQnGnnGBYM WzSt1n56S/p8AI8Zo9vWN2Ktqk86QujuZ9W/sxcrEhvyauR2FDpIeShmiMMCrsk9o/bbTi KppzrRKhVep+RvrOLDCuaR8LHW0s1CBloJtL+hp9n+XR08k6LydzOMbqX7h8EHVy1fkRLO ZlVVUWeZ3RrDS+5j+V/DDGzwNSe+GbxGfNzxznFTE+EN2SusYgwJBjzGFA1lYm2ZOJ+rX6 EXKNl8ssMYkgKgBSII0c0K2T1CulNH/7aOcgMKbdlKcHunIRkyCX6PiMUsPyCQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1738073106; a=rsa-sha256; cv=none; b=yx/eBq2NoJav19aMpkjcTNdt8MqtKRnidX1eF90oT4frONyzpibTfugOJ/V21AMRcgHYw8 IH3QscSEmyizRmlfxL3A4F0hStPSkThsR4rYbHaKms4bIFSsx2xs4R1+X3x4RaA2JjgTMK I4KxC3gthYsNs1UjlhK0we056drg4hlRvrzHwfTJyLodwdbYJSrRiMVgEY2I4tUZFEdyyb WM/Ql10RFQ7aRqcYlIfJUZmk/mM6+hXcGBR2BOZgSYx9S9gINuEGR8i42CdzlPNJjHHpuy n5ZGmP7TrrKZ9/Mih/N80I/JskRu5dO+Dgv1Z/v8Y52w5w5x5ae8xeBVc0mUMQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Yj6Vp1FDQz3HM; Tue, 28 Jan 2025 14:05:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50SE56DH020787; Tue, 28 Jan 2025 14:05:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50SE566L020784; Tue, 28 Jan 2025 14:05:06 GMT (envelope-from git) Date: Tue, 28 Jan 2025 14:05:06 GMT Message-Id: <202501281405.50SE566L020784@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Christos Margiolis Subject: git: 6819621ec999 - stable/14 - sound: Safely remove channel from list in one pass List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 6819621ec9994689cd8626af3e935fbbaa20cd5a Auto-Submitted: auto-generated The branch stable/14 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=6819621ec9994689cd8626af3e935fbbaa20cd5a commit 6819621ec9994689cd8626af3e935fbbaa20cd5a Author: Florian Walpen AuthorDate: 2025-01-21 11:59:12 +0000 Commit: Christos Margiolis CommitDate: 2025-01-28 14:04:52 +0000 sound: Safely remove channel from list in one pass The CHN_REMOVE_SAFE() macro did two traversals of the channel list to remove a channel, one to check whether the channel is an element of the list, and a second traversal through SLIST_REMOVE(). Reduce this to one traversal, while still preventing a NULL dereference in case the channel in question is not present in the list. While here, rename the macro arguments to something more descriptive. MFC after: 1 week Reviewed by: christos Differential Revision: https://reviews.freebsd.org/D48207 (cherry picked from commit 27b932e32faba1137ff307d05b787d837ccadda8) --- sys/dev/sound/pcm/channel.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/sys/dev/sound/pcm/channel.h b/sys/dev/sound/pcm/channel.h index 67f5019f4727..58fedd284ecb 100644 --- a/sys/dev/sound/pcm/channel.h +++ b/sys/dev/sound/pcm/channel.h @@ -175,6 +175,7 @@ struct pcm_channel { #define CHN_LINK(y) y.link #define CHN_EMPTY(x, y) SLIST_EMPTY(CHN_HEAD(x, y)) #define CHN_FIRST(x, y) SLIST_FIRST(CHN_HEAD(x, y)) +#define CHN_NEXT(elm, list) SLIST_NEXT((elm), CHN_LINK(list)) #define CHN_FOREACH(x, y, z) \ SLIST_FOREACH(x, CHN_HEAD(y, z), CHN_LINK(z)) @@ -188,8 +189,8 @@ struct pcm_channel { #define CHN_INSERT_AFTER(x, y, z) \ SLIST_INSERT_AFTER(x, y, CHN_LINK(z)) -#define CHN_REMOVE(x, y, z) \ - SLIST_REMOVE(CHN_HEAD(x, z), y, pcm_channel, CHN_LINK(z)) +#define CHN_REMOVE(holder, elm, list) \ + SLIST_REMOVE(CHN_HEAD(holder, list), elm, pcm_channel, CHN_LINK(list)) #define CHN_INSERT_HEAD_SAFE(x, y, z) do { \ struct pcm_channel *t = NULL; \ @@ -211,14 +212,18 @@ struct pcm_channel { CHN_INSERT_AFTER(x, y, z); \ } while (0) -#define CHN_REMOVE_SAFE(x, y, z) do { \ - struct pcm_channel *t = NULL; \ - CHN_FOREACH(t, x, z) { \ - if (t == y) \ - break; \ - } \ - if (t == y) \ - CHN_REMOVE(x, y, z); \ +#define CHN_REMOVE_SAFE(holder, elm, list) do { \ + if (CHN_FIRST(holder, list) == (elm)) { \ + SLIST_REMOVE_HEAD(CHN_HEAD(holder, list), CHN_LINK(list)); \ + } else { \ + struct pcm_channel *t = NULL; \ + CHN_FOREACH(t, holder, list) { \ + if (CHN_NEXT(t, list) == (elm)) { \ + SLIST_REMOVE_AFTER(t, CHN_LINK(list)); \ + break; \ + } \ + } \ + } \ } while (0) #define CHN_INSERT_SORT(w, x, y, z) do { \