From patchwork Fri Nov 15 17:12:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 291629 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B69162C00A4 for ; Sat, 16 Nov 2013 04:12:18 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VhMwC-0007G1-QO; Fri, 15 Nov 2013 17:12:09 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VhMwB-0002Lt-40; Fri, 15 Nov 2013 17:12:07 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VhMw8-0002LI-Qn for linux-mtd@lists.infradead.org; Fri, 15 Nov 2013 17:12:06 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rAFHBZml032603 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 15 Nov 2013 12:11:36 -0500 Received: from tranklukator.brq.redhat.com (dhcp-1-188.brq.redhat.com [10.34.1.188]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id rAFHBW8R017011; Fri, 15 Nov 2013 12:11:33 -0500 Received: by tranklukator.brq.redhat.com (nbSMTP-1.00) for uid 500 oleg@redhat.com; Fri, 15 Nov 2013 18:13:02 +0100 (CET) Date: Fri, 15 Nov 2013 18:12:59 +0100 From: Oleg Nesterov To: Jeff Liu Subject: introduce list_get_first/last (Was: [PATCH 3/6] gfs2: simplify current_tail() via list_last_entry_or_null()) Message-ID: <20131115171259.GA10687@redhat.com> References: <5285A3F4.4040000@oracle.com> <20131115163957.GA28467@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20131115163957.GA28467@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131115_121205_015185_63B00E56 X-CRM114-Status: GOOD ( 15.37 ) X-Spam-Score: -6.9 (------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-6.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [209.132.183.28 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: jfs-discussion@lists.sourceforge.net, jiri@resnulli.us, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, "xfs@oss.sgi.com" , cluster-devel@redhat.com, linux-mtd@lists.infradead.org, akpm@linux-foundation.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org On 11/15, Oleg Nesterov wrote: > > But probably list_last_entry() makes sense in the "else" branch, > athough this is minor. > > > Off-topic. Not sure this really makes sense, but I was thinking about > > list_get_first(pos, head, member) \ > ((pos) = list_first_entry(head, typeof(*pos), member)) > > and list_get_first() last of course. The obvious advantage is that > compared to > > tr = list_last_entry(sdp->sd_ail1_list, struct gfs2_trans, tr_list); > > above you do not need to type "struct gfs2_trans", > > list_get_last(tr, sdp->sd_ail1_list, tr_list); > > looks a bit better. And list.h can use it too. So how about the patch below? I can't decide whether it cleanups or uglfies the code, I do not trust my taste ;) But to me it looks a bit better this way. Oleg. diff --git a/include/linux/list.h b/include/linux/list.h index ef95941..f52aba8 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -372,6 +372,12 @@ static inline void list_splice_tail_init(struct list_head *list, #define list_last_entry(ptr, type, member) \ list_entry((ptr)->prev, type, member) +#define list_get_first(pos, head, member) \ + ((pos) = list_first_entry(head, typeof(*(pos)), member)) + +#define list_get_last(pos, head, member) \ + ((pos) = list_last_entry(head, typeof(*(pos)), member)) + /** * list_first_entry_or_null - get the first element from a list * @ptr: the list head to take the element from. @@ -443,7 +449,7 @@ static inline void list_splice_tail_init(struct list_head *list, * @member: the name of the list_struct within the struct. */ #define list_for_each_entry(pos, head, member) \ - for (pos = list_first_entry(head, typeof(*pos), member); \ + for (list_get_first(pos, head, member); \ &pos->member != (head); \ pos = list_next_entry(pos, member)) @@ -454,7 +460,7 @@ static inline void list_splice_tail_init(struct list_head *list, * @member: the name of the list_struct within the struct. */ #define list_for_each_entry_reverse(pos, head, member) \ - for (pos = list_last_entry(head, typeof(*pos), member); \ + for (list_get_last(pos, head, member); \ &pos->member != (head); \ pos = list_prev_entry(pos, member)) @@ -517,7 +523,7 @@ static inline void list_splice_tail_init(struct list_head *list, * @member: the name of the list_struct within the struct. */ #define list_for_each_entry_safe(pos, n, head, member) \ - for (pos = list_first_entry(head, typeof(*pos), member), \ + for (list_get_first(pos, head, member), \ n = list_next_entry(pos, member); \ &pos->member != (head); \ pos = n, n = list_next_entry(n, member)) @@ -564,7 +570,7 @@ static inline void list_splice_tail_init(struct list_head *list, * of list entry. */ #define list_for_each_entry_safe_reverse(pos, n, head, member) \ - for (pos = list_last_entry(head, typeof(*pos), member), \ + for (list_get_last(pos, head, member), \ n = list_prev_entry(pos, member); \ &pos->member != (head); \ pos = n, n = list_prev_entry(n, member))