From patchwork Fri Feb 2 15:58:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 195930 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp527434dyc; Fri, 2 Feb 2024 08:05:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGFrVnGiwXSCA6bhLBxRWVfqHLdV38ID8wlGi2+04CpclHNvX1scy2kPECKZYdU8DVxTd5 X-Received: by 2002:a17:90b:2397:b0:296:5219:bbf7 with SMTP id mr23-20020a17090b239700b002965219bbf7mr883220pjb.7.1706889952721; Fri, 02 Feb 2024 08:05:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706889952; cv=pass; d=google.com; s=arc-20160816; b=fBORsu0/1EypWN8xyKfrQMDrzfoWOQr2S50WkLSNOE+uZsXqqaiphs3XKF5DhY/b+5 9fFIGik0tnp6uSF6/THubHcqZyZUhzYrtN+lj730KRD9xPZW1X8gunHin8lpCSLX2Id8 txX+b/I5Yq+8lHOSnvf+uKbnQYQphDphZbVFu+wyxdTCY7dStC6seD1OLGTy2GrUAxGA WlcaUybBX+Wd/0E/BqMXmnBMKfCYGdOXL+ya61RGnSzyRpfGdKjVgyE7THaGUGHyrk4k BW3EsH6YH3cQ7wY31vE1RsUyVveKE/BW131e4s2GXq7ps2aoiPNpfH03ppqmaTVWU/KY El6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=OJMTHrb6k7HiiJX5n4dSfDnrUVYspQvdZe4Nzjm+u/s=; fh=D8CZTk1hfZ4PNw+QOIYGBqkWFcFik46YlrPI6vkcx8A=; b=gJHIjpKL3WCtkRjWREP59Ycse5wblHw6y604lSbBmT/Mdfn48aqKW6UTw/UO96Z6ZK cgC0pPC6JtA1vvqFIA7Dr32ipTREeVJ5OxUnMU20/6L6XoR1WYzS07c8KC3Vmo/5aSX6 0d0EBkNqQwpVAJg/Nfxw0NSp+bu7eHk/fxAgUMq8sIBJdiVOZHwiQDpIfV8g9tt/Xh4A Y/bPVJtNMATa/aIU/79mSjP4yfo8i6EZppUhhkpDSDhgvtui2OQbBgC6Dr4vcGOMWXAm hHtwimE52tLgk6NYKjPPMpiZYT+MBsgs2AISIMeiy4y4I6R3+lOAxuaQ7o53Xa/zDcKE bW6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Z/EWCSl2"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50081-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50081-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCUqxYwD//e/sEq5R8UwMZA+rLMpOQCXQk0DRanz4RoS+q1XOtPQSOwHx4sJTAFA1K356G9ZgOtsj3aBbGOVhMJDCDkRxg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id gb18-20020a17090b061200b00296451f8c25si129888pjb.159.2024.02.02.08.05.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 08:05:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50081-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Z/EWCSl2"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50081-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50081-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0C2DC283519 for ; Fri, 2 Feb 2024 16:04:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06C60151CCC; Fri, 2 Feb 2024 15:58:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z/EWCSl2" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 46ED01509B6; Fri, 2 Feb 2024 15:58:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889534; cv=none; b=WJjUxp7D6m73b3lTXrqQatYbT2IarpHN06FwMaTys1ZDRdjxBnP1g5efcN6Y4qJP0IF7ZGPWvHBzbNMMh4tbEVgBuEJ4eKTl0PIIe+yaS1NWrSOu3Yf6F1SbZ5VkYLMFLROKy0N7ZUUcbsUcb6BC+2rvSOm9EO6/NGKSxaPk1Zo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889534; c=relaxed/simple; bh=2A96WogbH0kuSA8JLvJzBsQjD8uKlSboQJQx9UBHSVM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dwLW0oOugQKEeqTizwTgdNEsganYYeljTxjHshNnxpJFebweGUEoGB6feo636GNczjbR/W49urSaOQwPk5F60N1tAR+15eUKNGOiWG/po8cRRptUs0MEb4mRbEQXNWKTkXO/N1zaf9Jg1WWyWyPv5gh37cZs0N0Qfu2tecofvVA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z/EWCSl2; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2571CC43394; Fri, 2 Feb 2024 15:58:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889533; bh=2A96WogbH0kuSA8JLvJzBsQjD8uKlSboQJQx9UBHSVM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z/EWCSl2wBAICpgIpF3Sra8aDM769fUjPgXy22zP6Hnk9+HH6P6Em6GY9UF0trg1q REgk3P9wJ50M51fGTYcDUurjxWqD1JSZNM/yvU816xfS5+hrdnE3mPWZlnGwa3AjUo Kg/nybbp39tKyCbUUUX+L+6G2nfFbpZ+wbtDiUzXRgRu7QsgInG/eqxulvFbgQlmuF lvFy6cITEHYpaI61fN5F7FY+KTbUDpEItD0mdzs9DX2nkSNOF44+AwMMuYunEYdP3l oStfxAitf73WOmLaV/tL+jlkDf0s4brhojGMpbAVtBh3vsAW6VlIq8QVGYqoTGl+MG IpO7Hui4vz1Xw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 21/27] kconfig: import more list macros and inline functions Date: Sat, 3 Feb 2024 00:58:19 +0900 Message-Id: <20240202155825.314567-22-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240202155825.314567-1-masahiroy@kernel.org> References: <20240202155825.314567-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789803838947216644 X-GMAIL-MSGID: 1789803838947216644 Import more macros and inline functions from include/linux/list.h and include/linux/types.h. Signed-off-by: Masahiro Yamada --- scripts/kconfig/list.h | 69 ++++++++++++++++++++++++++++++++++++ scripts/kconfig/list_types.h | 8 +++++ 2 files changed, 77 insertions(+) diff --git a/scripts/kconfig/list.h b/scripts/kconfig/list.h index 2bce2b8f21d1..882859ddf9f4 100644 --- a/scripts/kconfig/list.h +++ b/scripts/kconfig/list.h @@ -70,6 +70,19 @@ static inline void __list_add(struct list_head *new, prev->next = new; } +/** + * list_add - add a new entry + * @new: new entry to be added + * @head: list head to add it after + * + * Insert a new entry after the specified head. + * This is good for implementing stacks. + */ +static inline void list_add(struct list_head *new, struct list_head *head) +{ + __list_add(new, head, head->next); +} + /** * list_add_tail - add a new entry * @new: new entry to be added @@ -114,6 +127,16 @@ static inline void list_del(struct list_head *entry) entry->prev = LIST_POISON2; } +/** + * list_is_head - tests whether @list is the list @head + * @list: the entry to test + * @head: the head of the list + */ +static inline int list_is_head(const struct list_head *list, const struct list_head *head) +{ + return list == head; +} + /** * list_empty - tests whether a list is empty * @head: the list to test. @@ -184,4 +207,50 @@ static inline int list_empty(const struct list_head *head) !list_entry_is_head(pos, head, member); \ pos = n, n = list_next_entry(n, member)) +/* + * Double linked lists with a single pointer list head. + * Mostly useful for hash tables where the two pointer list head is + * too wasteful. + * You lose the ability to access the tail in O(1). + */ + +#define HLIST_HEAD_INIT { .first = NULL } + +/** + * hlist_add_head - add a new entry at the beginning of the hlist + * @n: new entry to be added + * @h: hlist head to add it after + * + * Insert a new entry after the specified head. + * This is good for implementing stacks. + */ +static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) +{ + struct hlist_node *first = h->first; + + n->next = first; + if (first) + first->pprev = &n->next; + h->first = n; + n->pprev = &h->first; +} + +#define hlist_entry(ptr, type, member) container_of(ptr, type, member) + +#define hlist_entry_safe(ptr, type, member) \ + ({ typeof(ptr) ____ptr = (ptr); \ + ____ptr ? hlist_entry(____ptr, type, member) : NULL; \ + }) + +/** + * hlist_for_each_entry - iterate over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry(pos, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\ + pos; \ + pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) + #endif /* LIST_H */ diff --git a/scripts/kconfig/list_types.h b/scripts/kconfig/list_types.h index 32899f424983..d935b7c5aa81 100644 --- a/scripts/kconfig/list_types.h +++ b/scripts/kconfig/list_types.h @@ -6,4 +6,12 @@ struct list_head { struct list_head *next, *prev; }; +struct hlist_head { + struct hlist_node *first; +}; + +struct hlist_node { + struct hlist_node *next, **pprev; +}; + #endif /* LIST_TYPES_H */