From nobody Thu Apr 2 22:03:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 318163F9F42 for ; Thu, 26 Mar 2026 13:19:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774531153; cv=none; b=TBPNvcYtF/aWLYa5QgwNtqyDhbdL68VEN8p/48REh6Lt+TsHuRYH13qZi+YBJdNDV9hsPRPBqQyj5DW3W73gH7oEze/pk9kYSST9BynsEHCFO8pUu7qi+SqJL0gU7sapJVFq3Rnu0LrEegwqV2KhZ/1A9Ra2p+yGbFIBCmYcSuE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774531153; c=relaxed/simple; bh=mBKrZtOnIAHd6KsphkSL/iGsCqPyJf6gyUryLPO2bOA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VLnsCunFXki6y7U5LDB24SueLc0oo7km6wYuTpOjv4FQyJn4HPejTCafpD4NIpdvTZ5XS+JpTSnv4P4meX4NVghxUR7raZQnv++omYitRHRz2zpdXa+ymGJ5x0GLbYtV0e26ff/m5BvR5p7F6cBYp5fmE2IcfU0rPkAIp4a7ACw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=jTqkk+mn; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jTqkk+mn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774531151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1w/tzujNq6shO/Yk27oYEh0iCXtTypElru3vLGpkYIY=; b=jTqkk+mn9lj2YE2HAW4Caj9NHboyEwoG8R0LbQtkMv4QaF8MzvJed7tcsG2qdb9qgjuHvd DwQ2cPu4mhAr0zifWwhbgmreLr0c0f+DySlmU/80lMI+Ht/0xatltWJGZuXVJslBKc6qRF Pq9ICU9qdwlytn1VSNtEqcIi7N+F0OM= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-389-SRuUNOehMoCCTIHOHqYf1Q-1; Thu, 26 Mar 2026 09:19:09 -0400 X-MC-Unique: SRuUNOehMoCCTIHOHqYf1Q-1 X-Mimecast-MFC-AGG-ID: SRuUNOehMoCCTIHOHqYf1Q_1774531147 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5C57C19560B4; Thu, 26 Mar 2026 13:19:07 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.44.33.121]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 93EA6180036E; Thu, 26 Mar 2026 13:19:02 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , Marc Dionne , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org, Mathieu Desnoyers , John Johansen , Minas Harutyunyan , Simon Horman , apparmor@lists.ubuntu.com, linux-usb@vger.kernel.org, stable@kernel.org Subject: [PATCH net v3 04/11] list: Move on_list_rcu() to list.h and add on_list() also Date: Thu, 26 Mar 2026 13:18:29 +0000 Message-ID: <20260326131838.634095-5-dhowells@redhat.com> In-Reply-To: <20260326131838.634095-1-dhowells@redhat.com> References: <20260326131838.634095-1-dhowells@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Unfortunately, list_empty() is not usable with an entry that has been removed from a list with list_del_rcu() as ->next must be left pointing at the following entry so as not to break traversal under RCU. Solve this by moving on_list_rcu() from AppArmor to linux/list.h, and turning it into an inline function. Also add an on_list() counterpart (functionally, this is just an antonym for list_empty()), but the name looks less awkward when applied to a non-head element. We probably don't want to use on_list_rcu() generally because it requires an extra check as ->prev is set differently in the two cases. Further, rename the on_list() function in the Designware usb2 drd ip driver to dwc2_on_list() to free up the original name. Signed-off-by: David Howells cc: Mathieu Desnoyers cc: John Johansen cc: Minas Harutyunyan cc: Marc Dionne cc: Eric Dumazet cc: "David S. Miller" cc: Jakub Kicinski cc: Paolo Abeni cc: Simon Horman cc: linux-afs@lists.infradead.org cc: apparmor@lists.ubuntu.com cc: linux-usb@vger.kernel.org cc: netdev@vger.kernel.org cc: stable@kernel.org --- drivers/usb/dwc2/gadget.c | 6 +++--- include/linux/list.h | 26 ++++++++++++++++++++++++++ security/apparmor/include/policy.h | 2 -- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index d216e26c787b..04b6aef8ac13 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -4306,11 +4306,11 @@ static int dwc2_hsotg_ep_disable_lock(struct usb_ep= *ep) } =20 /** - * on_list - check request is on the given endpoint + * dwc2_on_list - check request is on the given endpoint * @ep: The endpoint to check. * @test: The request to test if it is on the endpoint. */ -static bool on_list(struct dwc2_hsotg_ep *ep, struct dwc2_hsotg_req *test) +static bool dwc2_on_list(struct dwc2_hsotg_ep *ep, struct dwc2_hsotg_req *= test) { struct dwc2_hsotg_req *req, *treq; =20 @@ -4338,7 +4338,7 @@ static int dwc2_hsotg_ep_dequeue(struct usb_ep *ep, s= truct usb_request *req) =20 spin_lock_irqsave(&hs->lock, flags); =20 - if (!on_list(hs_ep, hs_req)) { + if (!dwc2_on_list(hs_ep, hs_req)) { spin_unlock_irqrestore(&hs->lock, flags); return -EINVAL; } diff --git a/include/linux/list.h b/include/linux/list.h index 00ea8e5fb88b..d224e7210d1b 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -381,6 +381,32 @@ static inline int list_empty(const struct list_head *h= ead) return READ_ONCE(head->next) =3D=3D head; } =20 +/** + * on_list - Test whether an entry is on a list. + * @entry: The entry to check + * + * Test whether an entry is on a list. Safe to use on an entry initialised + * with INIT_LIST_HEAD() or LIST_HEAD() or removed with things like + * list_del_init(). Not safe for use with list_del() or list_del_rcu(). + */ +static inline bool on_list(const struct list_head *entry) +{ + return !list_empty(entry); +} + +/** + * on_list_rcu - Test whether an entry is on a list (RCU-del safe). + * @entry: The entry to check + * + * Test whether an entry is on a list. Safe to use on an entry initialised + * with INIT_LIST_HEAD() or LIST_HEAD() or removed with things like + * list_del_init(). Also safe for use with list_del() or list_del_rcu(). + */ +static inline bool on_list_rcu(const struct list_head *entry) +{ + return !list_empty(entry) && entry->prev !=3D LIST_POISON2; +} + /** * list_del_init_careful - deletes entry from list and reinitialize it. * @entry: the element to delete from the list. diff --git a/security/apparmor/include/policy.h b/security/apparmor/include= /policy.h index 3895f8774a3f..c3697c23bbed 100644 --- a/security/apparmor/include/policy.h +++ b/security/apparmor/include/policy.h @@ -57,8 +57,6 @@ extern const char *const aa_profile_mode_names[]; =20 #define profile_is_stale(_profile) (label_is_stale(&(_profile)->label)) =20 -#define on_list_rcu(X) (!list_empty(X) && (X)->prev !=3D LIST_POISON2) - /* flags in the dfa accept2 table */ enum dfa_accept_flags { ACCEPT_FLAG_OWNER =3D 1,