Received: by 2002:a17:90a:8582:0:0:0:0 with SMTP id m2csp2415489pjn; Tue, 2 Apr 2019 16:07:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkzU8S8Mne13u+eLpnEA4W7jbCcd0eoUQZOE/Shq0wBJTgAPcUIyjyx0wTKZ0p6w4ylZHM X-Received: by 2002:a63:5a20:: with SMTP id o32mr66556753pgb.225.1554246449582; Tue, 02 Apr 2019 16:07:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554246449; cv=none; d=google.com; s=arc-20160816; b=kbSsrj6fccoemxdbUz/RyPGk4aCMpV4JjQ4R8y4CqWHbcVs8umufVM/Ksh1u/3wjpX HK/IXx1dEFrjGIIlUXln5ooa85z+h0Y+ABPaDGDCss1KMTWQDEFwnwCnZMyagoHjn/ZJ J+rTaSLuMQkZodtpRobdXSXtp0B7zzFqZfQHlFCrzoG7YRMF1LP7QOZdx3rS+AnFaIqv 6/pwzjq8Yqokx49wr0UWhFF9/woeDZKkpdvZ1W9Tft9mbgo+4RLNYT1evSKnO8Hj5RDg RnYb+71fxcrg7gb/BphvVCYIK8kRSc/gEdWQXXJvTOW6UcsxUy1wp5GUtu0ga9Io4R9S ViTw== 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=WyIL3jAshSjdBFnKxRJVP8UxjvsL3RiIiqvjpUWI/P8=; b=Whv+Hixqs04pJC15ULnedm1z3G8vh0Ohvg44v+sn3wfM+AwL/7LhRlEBdAAWEATCJu grBClgWSgs0PbOvChCT8LgjcrZ/bx/PtiAaqvajwzg/Fa5OhS3h889qCESRR5ZbKXaqH yXPtIfeDwfDLC6i0zPMeKL2TVJZON5fSD1iN+vFqDUqS5U9/kms+bluhU8P0ntbTlUmS rikpKINxPVNzUjDPtkuH9wM7sfWHHB5/j1OzBep/b286F7Xb+f2kUVRQCZkeMTEiUh06 7Cg+UpeHK0Uwh4OiJEthFCSlRq1TAnzkTx9vz4MgLSpTQLMC8EgZeIFusVm/c6zIvjZX 4neg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=S9YZIJcE; 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 e4si12390919pgn.237.2019.04.02.16.07.13; Tue, 02 Apr 2019 16:07:29 -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=S9YZIJcE; 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 S1726607AbfDBXGb (ORCPT + 99 others); Tue, 2 Apr 2019 19:06:31 -0400 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:50801 "EHLO out2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726083AbfDBXG3 (ORCPT ); Tue, 2 Apr 2019 19:06:29 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 606BB20B63; Tue, 2 Apr 2019 19:06:29 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 02 Apr 2019 19:06:29 -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=WyIL3jAshSjdBFnKxRJVP8UxjvsL3RiIiqvjpUWI/P8=; b=S9YZIJcE ioLWYGHJy9xvw0Z+EIbMaGsCAADIx/5Nw2oDC/AowE5OE8MjNuQ+sqBwuY2qyDC8 s9O9em3R9HRwWRLDyOjBCpdG7ol8zYFeYr1u8ckmdXRFOAWa6mJ4wjPTIIjn2dsx 38slfK7mNrfaEJaEsOVBy/a16YkhWbK7oMk3K5dqkBSS1EL/wh/1bdrxaDV9vXIP WUvdHHuR+EuFQTpeCnFjNzBXZIIbJ+HTdIV8CIJsK1K+uvNSd63Z6UIsK6zzKXJl JT79i6i8j8eOx7Jm9xkNMreAop2jfoHI2ra8ZDE2S1ISpOqY/Dw3FAo6z+nqU0my Tk2caoQt3XN1mA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrtddugdduieculddtuddrgedutddrtddtmd cutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhvffufffkofgjfhgggfestdekredtredttden ucfhrhhomhepfdfvohgsihhnucevrdcujfgrrhguihhnghdfuceothhosghinheskhgvrh hnvghlrdhorhhgqeenucfkphepuddvgedrudeiledrvdejrddvtdeknecurfgrrhgrmhep mhgrihhlfhhrohhmpehtohgsihhnsehkvghrnhgvlhdrohhrghenucevlhhushhtvghruf hiiigvpedt X-ME-Proxy: Received: from eros.localdomain (124-169-27-208.dyn.iinet.net.au [124.169.27.208]) by mail.messagingengine.com (Postfix) with ESMTPA id CDCFC10310; Tue, 2 Apr 2019 19:06:25 -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 v5 1/7] list: Add function list_rotate_to_front() Date: Wed, 3 Apr 2019 10:05:39 +1100 Message-Id: <20190402230545.2929-2-tobin@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190402230545.2929-1-tobin@kernel.org> References: <20190402230545.2929-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 58aa3adf94e6..9e9a6403dbe4 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