Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1055870pxm; Wed, 23 Feb 2022 17:00:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJylW6lh0kdi5XdIJWCdGSFNiLlcqBwqYqZiYcXh5SIPV9QxIsu2cdGRP4iqklU7GWxI8lTq X-Received: by 2002:a63:3481:0:b0:372:f3e7:6f8c with SMTP id b123-20020a633481000000b00372f3e76f8cmr360864pga.336.1645664445614; Wed, 23 Feb 2022 17:00:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645664445; cv=none; d=google.com; s=arc-20160816; b=VwIrnT6Eal5dqNbflGDWrSiFLeTEmJ9pg5xrgb9+dP3byHobtehEqowW8av2ajhnnb lT1YNTnS/ahkBk00WSzly6zbn0N/oqfDHZ97AIqPfc1OsXbeByoVMwwKOTeR3IVrNkaf q/DP4RyztsROOrYe2Lw6DyuONL1cin5Us9stDVpDqhx61B7LKPLdEsUVzkjLVyzULBiD bl3FQxkbtVRLr+H3sefL4sFdYbUfPPSNtVeIxEC9KyDDZkSts9krZ0yZ0J40MptAjqkW nUPyo/ZcYaC++H2yS1lR9/KkY0BwaY5uEBpqp0TKGl7GjJG3B20sH44pIwg8pHzAYPmM Mlog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=xjXGPcmvhgNwNGN3HEfbrsO1f7imdIm8fZixcJY9BM4=; b=wzqSYTp4SQHDPdySbWWKwaPyW06pNBZOKJqh7nLpS0Z70+HLL8F4J7xADJTOmxKVOe C2mAKw5rED+Zd6TDvzNgkE/osBGBuiscodLlbaE1HkllOXWIuQnVvXsf1RTkwZMt37Dg Ff02CDubPLy8K4RqrE9eO4ZJEsAQXnbfd1y8GCi7gnq9FDHIc6L/GwRPOJzLsrr8JAbV 12/3N+D419pp2A8UgH+PxZeqdxJQ4HhJIKX2JJibqNFykYpznF2L7w76HgKnrLOrpk/a wOT8CoiOrB65ra21qO8dnUfu9ple6S4BPmOxEY8M5GbuRvK5VkvkmICXwc2JCbHDCgop U/Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gvzttfJ5; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s17si1208930pfu.330.2022.02.23.17.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 17:00:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gvzttfJ5; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 529C9CA31E; Wed, 23 Feb 2022 16:51:52 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244064AbiBWWfi (ORCPT + 73 others); Wed, 23 Feb 2022 17:35:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243645AbiBWWfh (ORCPT ); Wed, 23 Feb 2022 17:35:37 -0500 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 860921C106; Wed, 23 Feb 2022 14:35:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645655708; x=1677191708; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=l44v8W5Bft9bSBP2aodKJZT3sd0EJtHNMPrJkziyrr4=; b=gvzttfJ5gJ0nFv89wH3WUl8r5itmUjYeJWAC3Eehn55uqlZu5fKS0Rwy YTjL9kCy0gsFCDrIbf1zNQZ9dHq6khdPXs1mVHXHQ8h1v9P0x7XB7P8/V 90aa1jaP5kLUrT4SIWVrFH+F2SdftbjgjVuzyAoYUDEf6C2hPRFFFtUvB OzHsQdPGVsJnhcEXH8ckhy6UzXdnYU5x3xUTtUCRt1rh8DL6wmBJBweJ7 i4B2UMdOcsqZcxpuPsX78HA+KiY7EwANgEKFdSf0H0/Rc9YMpAAG3Fovs GDPUUoMFtgATFo4LNatiOQZB476n4nty5VOb2U7XK/wvtOkt3veCfVeju A==; X-IronPort-AV: E=McAfee;i="6200,9189,10267"; a="312812421" X-IronPort-AV: E=Sophos;i="5.88,392,1635231600"; d="scan'208";a="312812421" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2022 14:35:07 -0800 X-IronPort-AV: E=Sophos;i="5.88,392,1635231600"; d="scan'208";a="628252220" Received: from rmarti10-desk.jf.intel.com ([134.134.150.146]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2022 14:35:06 -0800 From: Ricardo Martinez To: netdev@vger.kernel.org, linux-wireless@vger.kernel.org Cc: kuba@kernel.org, davem@davemloft.net, johannes@sipsolutions.net, ryazanov.s.a@gmail.com, loic.poulain@linaro.org, m.chetan.kumar@intel.com, chandrashekar.devegowda@intel.com, linuxwwan@intel.com, chiranjeevi.rapolu@linux.intel.com, haijun.liu@mediatek.com, amir.hanania@intel.com, andriy.shevchenko@linux.intel.com, dinesh.sharma@intel.com, eliot.lee@intel.com, ilpo.johannes.jarvinen@intel.com, moises.veleta@intel.com, pierre-louis.bossart@intel.com, muralidharan.sethuraman@intel.com, Soumya.Prakash.Mishra@intel.com, sreehari.kancharla@intel.com, madhusmita.sahu@intel.com, Ricardo Martinez Subject: [PATCH net-next v5 01/13] list: Add list_next_entry_circular() and list_prev_entry_circular() Date: Wed, 23 Feb 2022 15:33:14 -0700 Message-Id: <20220223223326.28021-2-ricardo.martinez@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220223223326.28021-1-ricardo.martinez@linux.intel.com> References: <20220223223326.28021-1-ricardo.martinez@linux.intel.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Add macros to get the next or previous entries and wraparound if needed. For example, calling list_next_entry_circular() on the last element should return the first element in the list. Signed-off-by: Ricardo Martinez Reviewed-by: Andy Shevchenko --- include/linux/list.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/linux/list.h b/include/linux/list.h index dd6c2041d09c..c147eeb2d39d 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -563,6 +563,19 @@ static inline void list_splice_tail_init(struct list_head *list, #define list_next_entry(pos, member) \ list_entry((pos)->member.next, typeof(*(pos)), member) +/** + * list_next_entry_circular - get the next element in list + * @pos: the type * to cursor. + * @head: the list head to take the element from. + * @member: the name of the list_head within the struct. + * + * Wraparound if pos is the last element (return the first element). + * Note, that list is expected to be not empty. + */ +#define list_next_entry_circular(pos, head, member) \ + (list_is_last(&(pos)->member, head) ? \ + list_first_entry(head, typeof(*(pos)), member) : list_next_entry(pos, member)) + /** * list_prev_entry - get the prev element in list * @pos: the type * to cursor @@ -571,6 +584,19 @@ static inline void list_splice_tail_init(struct list_head *list, #define list_prev_entry(pos, member) \ list_entry((pos)->member.prev, typeof(*(pos)), member) +/** + * list_prev_entry_circular - get the prev element in list + * @pos: the type * to cursor. + * @head: the list head to take the element from. + * @member: the name of the list_head within the struct. + * + * Wraparound if pos is the first element (return the last element). + * Note, that list is expected to be not empty. + */ +#define list_prev_entry_circular(pos, head, member) \ + (list_is_first(&(pos)->member, head) ? \ + list_last_entry(head, typeof(*(pos)), member) : list_prev_entry(pos, member)) + /** * list_for_each - iterate over a list * @pos: the &struct list_head to use as a loop cursor. -- 2.17.1