Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp124744pxh; Thu, 7 Apr 2022 16:06:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYTijFEvqT09Gr64d4/d6vc775jLCuZRN591EzxKHjerbS6C/1NB6lXsGSgufWF5IlvFXx X-Received: by 2002:a17:902:ef4d:b0:156:82dc:b7e1 with SMTP id e13-20020a170902ef4d00b0015682dcb7e1mr16449526plx.78.1649372778442; Thu, 07 Apr 2022 16:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649372778; cv=none; d=google.com; s=arc-20160816; b=bfXPF7bPrINNfRhnpY2udRyo84DQ1cK4BALU6xVl0bg50koNsaPWu1x6ccQUIILqUL 6VoN/aAmcSBg6JVTYQsZuWieCujfRlCmqGer8/hY/l6z5Bd7zpcmQ+/ad8YNdzsGgJlE ttRhh6TZY+CFq3wXWblMwakrOoCBJ7stzqc+zaqzRC+nJQeGZs1tlBPBJj55Y6lBVhU6 96L4RfpX1+bwIt3Gu9gd9miE/u5YZFWnSjiUO8L+SiFoinYTm4DzaqTrgu5t5DsJ8PUY HMJJi4RXX0If1epBPZyHXSX8ETe+nf+bJ7Ib4E2ZN06HNlEGSSeX9pnjU2Vy5vt7ITFk d5Vg== 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=6H5SMdlryEWeiGi7k5tn6PZohcKWzJGlT5eW3nVlels=; b=RvSzB2RT4/WyEH0auLqgsHAmibFjTI1XXzTXM9EcCfayWhfQXrUMwdYDBL9b/p2+J/ eEY9UXkm000qR/1JWcj/QfeBCqLvRqubKtDP0EWoTK/x85jQMLHu3wd/381kFHNLi5YF b0YNtGuPURSgh6FANDUBTRklDkY4VfT00OcL+xy2voUCgKsDGexOkX3H9DqabXoqQ569 Q3lCOdmTbmPm6rnkwbhx9OcrGBwUvlbYYT2JBaCR0IC3r+ADNX37jDuAIVzfQHTXZseH tuJV9Av4MBfFn+eYzrO+fVkmEr/DdFC8wNJ0vacsxPpoVE3AorPoi6XNVJrgf0S1QfD/ s9LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XpScJ68z; 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 e18-20020a170902f11200b00156b4ee3bd6si835022plb.354.2022.04.07.16.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 16:06:18 -0700 (PDT) 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=XpScJ68z; 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 993E41275EB; Thu, 7 Apr 2022 15:37:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232117AbiDGWjO (ORCPT + 69 others); Thu, 7 Apr 2022 18:39:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbiDGWjN (ORCPT ); Thu, 7 Apr 2022 18:39:13 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1816129253; Thu, 7 Apr 2022 15:37:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649371031; x=1680907031; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=MHiLlcSaMnahwidQH1EnOY42tA4Hy/pUqwVnkznAwCQ=; b=XpScJ68zD77lDwQqT0+MZZg/tjOVIs7gv1jLfKfttlGOjARdkW5ma4yl vAPswn3706MVASev0pusto34EH8Y6NLAtvHiv13HP3yoK5SJPNzBAt8NN 4wCorJvhhkQ8xDGkNgf47SCSs3Bg7ht0LqrTju3zGyR6hl1aQcGMYT8iq IZeNgFDk4rPQmLk1tjr2qB0J6okktcgmS45/2lJBfClPnxmcWGWvs08yb IYZJFlV8hSYNA6g++NfV8Ps3gfXdBFPW5HQWxTKsrWfGIuluSKZiDFpy/ qme3dXLbdHfnu5ctByQDfr31aJIsWXuXGJtLiT1JYGc0xL12r+vmCDahh Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10310"; a="261449303" X-IronPort-AV: E=Sophos;i="5.90,242,1643702400"; d="scan'208";a="261449303" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 15:37:11 -0700 X-IronPort-AV: E=Sophos;i="5.90,242,1643702400"; d="scan'208";a="659242870" Received: from rmarti10-desk.jf.intel.com ([134.134.150.146]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 15:37:11 -0700 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 v6 01/13] list: Add list_next_entry_circular() and list_prev_entry_circular() Date: Thu, 7 Apr 2022 15:36:17 -0700 Message-Id: <20220407223629.21487-2-ricardo.martinez@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220407223629.21487-1-ricardo.martinez@linux.intel.com> References: <20220407223629.21487-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, URIBL_BLOCKED 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 d7d2bfa1a365..c36e3b9a651b 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