From nobody Tue Jan 21 12:03:58 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 4Ycm8G20fwz5l0YJ; Tue, 21 Jan 2025 12:03:58 +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 4Ycm8G1HLCz3fnn; Tue, 21 Jan 2025 12:03:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737461038; 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=GBv2/ylwt8Qoim/ayOUu9i2p39U94BQ2bZG+hab0LDw=; b=r08r8o7dWwcxUwysn23dhDB5fOm+QBmnYaD1d2LSnYb4VEo2PBrxZYO5m/BEH3XgbBFGsO Cp3TO1Bxz11eImhdqgWDjP5YxAUZh+RkPIHebfGdsnUpZ6lu3Sau0YtXlzpIXBazGM3BlD vstw95n1Ke2QK2IsBHCKTzgkmzd6tqZkT4aIJ5IxKshiGsHkSdsVRp3GY0Kb9QvSjmw6Qd iRdoxtZlCCFIl6fAAUJY9kTyNapGvMqIzbtx4Vq3hh8D/It/J4U10ykMuOZbOLQxufv12+ 6GuR+AGmtcOtNG03k8fEH8PqnYj7L1vAs456dKe8MUG+ZzsMAIKaYA759LDPvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737461038; 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=GBv2/ylwt8Qoim/ayOUu9i2p39U94BQ2bZG+hab0LDw=; b=xS1fbFLzPyNcPBbjhHGAneVCWSmrepJdLmqz/QeQdLMaczQQ8qiAoPdxi7QDY4Gb6ZPgFu 1wCfiOMW8FwjDS7kivGI9Db6NcHyc46e9W5grRmAIpBtI/3wGRYIttWwh3DOIH4i2W4U65 VHuPMibbOIc1olhoHfncjg875dF3YHLZVU6fasFojfVkgXpsfS8pY6ex3/mXIgSUGcp0JI 0odS4du6dKqxJeqUDhe1MPudcEbq2pKckfFFyQBarVTKl5gsEiQQ1ZB2DFFrtg3KW9Nbcz NUvOsFui8H7FyTuq5jejsANFAJVm/YPPLoxr20tKXwTLnxckj8N2y/NCafEvkQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737461038; a=rsa-sha256; cv=none; b=U4RIi2zej4YXLpq4yV3jGGwgto44F+509kGPHdU4+e69WpynBw0zuf9aL6fdb9OvuKfDC1 ne/RIeVpHuw1wu/NVciszrfdlr24Ti3YaX6DpUVrvVwchlrUQNjGCl8o/uer47+xprLeHh DmSd+IiSfrEpHatQkfetG0rLHoHySGiKD//CXMHX+slTO12ZKnmq9T04ppnTEffy6Epozc KqwSqPkUQf7w8cE/fRvlFS91TfxJHfCCaXPIqEudOQzsBswlOGyl5I00SFVy7dP/XFpkW/ aJ/YbDaT7/czFCSHwSk6TNbanM0EbwCOXROBmMDXOeILnJP9HqQEQFJfuclxJQ== 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 4Ycm8G0qW6z15KJ; Tue, 21 Jan 2025 12:03:58 +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 50LC3wT0023301; Tue, 21 Jan 2025 12:03:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50LC3wux023298; Tue, 21 Jan 2025 12:03:58 GMT (envelope-from git) Date: Tue, 21 Jan 2025 12:03:58 GMT Message-Id: <202501211203.50LC3wux023298@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 27b932e32fab - main - 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/main X-Git-Reftype: branch X-Git-Commit: 27b932e32faba1137ff307d05b787d837ccadda8 Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=27b932e32faba1137ff307d05b787d837ccadda8 commit 27b932e32faba1137ff307d05b787d837ccadda8 Author: Florian Walpen AuthorDate: 2025-01-21 11:59:12 +0000 Commit: Christos Margiolis CommitDate: 2025-01-21 12:00: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 --- 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 { \