Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3536571imc; Wed, 13 Mar 2019 22:32:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSe6vuGdnulPpcZzafy3aHZ3gyEZbjpWj4DyVyoNk6oJaZJcRQ4UZZ1hztAVcYHOv9ldTm X-Received: by 2002:a17:902:7293:: with SMTP id d19mr47361480pll.29.1552541568316; Wed, 13 Mar 2019 22:32:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552541568; cv=none; d=google.com; s=arc-20160816; b=CNJPnBFqy5ynm6jTiatSB3I2lTqxNtYCDZDmQ3ODsC35QFLXtrgK3w8imLcR/7bEFV pre0e22UdrtiC7B2ckpuGRZvrTQhznIkjNmUDGBf/6/Y25odW9Z8zp12Jra80+qdZ5+C cgS426DDfuoW/Veh4+bXSMtW+pUfjwM1+SIu4dJW1U8+ZVo404C+wa5y8xaUtxhak3wX ljbd9QSnNferV8VlssGj2J7gH4UzbdkFMnZR1qBZ/iHneR4OeriPtbPEx+e+W/bHdeqF 7lwMyZipm+8EIV/B5l7Ah2R6CJIP4DjO47AD5Y4hIIH1aOBjBOhn2zK3ZVQS5e8eKC76 scew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=D6RBo2xA005T3vgh61b+8gQHpH8S5KLC0eS56YqC/3o=; b=AyMIH/DtqgGCvoy737ZG83Q4TQpmHKHYa/Ga8pxOTBrLOjQ/5XoAAXdeQTBfDgnd0A /ahCzeXkOSoiIN0T8elE7ABXXJ7wnbfQU8kTU7Cn3gMcNEVRQT3405w4D2YRePCWGrwI MScLTOkiecPkHOyf+8e8lUcoTjwACOTkDwZC0sOKJsGpBUtsWEea0243WdFP9kNk9uCY frGzi4KmXLGg7aAkcXJHTweuPimsUCG9yx07NiwLOyrYNghz02lXbV4aIukpBFSK+p+3 b++/LZ/MJlibnpeslyehZ1Tni75kXV0xo6BB5HQUGOkeRi+ueD75eLpCzQupfVy24jSp aLAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=jokTLtgM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c136si11993266pfb.89.2019.03.13.22.32.31; Wed, 13 Mar 2019 22:32:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=jokTLtgM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726889AbfCNFcJ (ORCPT + 99 others); Thu, 14 Mar 2019 01:32:09 -0400 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:47797 "EHLO out2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726130AbfCNFcJ (ORCPT ); Thu, 14 Mar 2019 01:32:09 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 9482621550; Thu, 14 Mar 2019 01:32:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 14 Mar 2019 01:32:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=D6RBo2xA005T3vgh61b+8gQHpH8S5KLC0eS56YqC/3o=; b=jokTLtgM Pw26V8ZDtMnDR0czqO17EIIcwvEW/JO0xXkBcGUhyIw+0oppZVFCW8NduwfH/UeT 1zQvwPnzk8HwOk5PMEqWQZjm06otbVy4h42L25gnq4mFk35xBjibdPCPvVFbeHTl n8gfNwLz8mjdCZNblYO1EX3wWWe5vmHY1Qm8cXV27ox/rjwGDt7or3jiSBcPSB0E eZSu1ne352wvggS7swjQ23vKAR0wJY2+ode7jQ/hhXFQd4Ub6L5o3kv463FjfzIt v+I3lwVjurRoQ5Zt+PwXLQxloGGAJTnCk+lfUvNXI95APCINQjM1mhfwqWtRNkFU bDPAdWQ2KV943w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrhedugdekgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepfdfvohgsihhn ucevrdcujfgrrhguihhnghdfuceothhosghinheskhgvrhhnvghlrdhorhhgqeenucfkph epuddvgedrudeiledrvdefrddukeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpehtohgs ihhnsehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from eros.localdomain (124-169-23-184.dyn.iinet.net.au [124.169.23.184]) by mail.messagingengine.com (Postfix) with ESMTPA id E4137E41BB; Thu, 14 Mar 2019 01:32:04 -0400 (EDT) From: "Tobin C. Harding" To: Andrew Morton Cc: "Tobin C. Harding" , Roman Gushchin , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/7] list: Add function list_rotate_to_front() Date: Thu, 14 Mar 2019 16:31:29 +1100 Message-Id: <20190314053135.1541-2-tobin@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190314053135.1541-1-tobin@kernel.org> References: <20190314053135.1541-1-tobin@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently if we wish to rotate a list until a specific item is at the front of the list we can call list_move_tail(head, list). Note that the arguments are the reverse way to the usual use of list_move_tail(list, head). This is a hack, it depends on the developer knowing how the list_head operates internally which violates the layer of abstraction offered by the list_head. Also, it is not intuitive so the next developer to come along must study list.h in order to fully understand what is meant by the call, while this is 'good for' the developer it makes reading the code harder. We should have an function appropriately named that does this if there are users for it intree. By grep'ing the tree for list_move_tail() and list_tail() and attempting to guess the argument order from the names it seems there is only one place currently in the tree that does this - the slob allocatator. Add function list_rotate_to_front() to rotate a list until the specified item is at the front of the list. Signed-off-by: Tobin C. Harding --- include/linux/list.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/list.h b/include/linux/list.h index 79626b5ab36c..8ead813e7f1c 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -270,6 +270,24 @@ static inline void list_rotate_left(struct list_head *head) } } +/** + * list_rotate_to_front() - Rotate list to specific item. + * @list: The desired new front of the list. + * @head: The head of the list. + * + * Rotates list so that @list becomes the new front of the list. + */ +static inline void list_rotate_to_front(struct list_head *list, + struct list_head *head) +{ + /* + * Deletes the list head from the list denoted by @head and + * places it as the tail of @list, this effectively rotates the + * list so that @list is at the front. + */ + list_move_tail(head, list); +} + /** * list_is_singular - tests whether a list has just one entry. * @head: the list to test. -- 2.21.0