From patchwork Wed May 29 15:02:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 247280 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 4EBED2C0296 for ; Thu, 30 May 2013 01:03:12 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966547Ab3E2PDG (ORCPT ); Wed, 29 May 2013 11:03:06 -0400 Received: from mail-wi0-f179.google.com ([209.85.212.179]:48779 "EHLO mail-wi0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966447Ab3E2PDE (ORCPT ); Wed, 29 May 2013 11:03:04 -0400 Received: by mail-wi0-f179.google.com with SMTP id hq7so3599252wib.6 for ; Wed, 29 May 2013 08:03:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=QmM/Yr0M0/kzJ5YLBsV22KyN77yFafh0RUGTv68I4Jo=; b=NG5jibf71E/aAKpLgyKqH+meNrO36oudh+qesk6q7uoZ+jK+dNwLDwNNWx17gfTp1t ABC6rmbUPMF/Xn5J2bbERcfIsFOKFOoFoB2ImNkww4E8QUvdxLm3ORNfY5h53YH2k4ip KZ3W6fLta2Aflg4b3FK4ximdLYiieXGKR1nqg42OZdT5IuYRM3qm7eMb6jWrHEzmP0J3 LrucANqBB4kZ5v/FKAE1AkJpBPZI3+Qi+opmxXdLpKRayOImfEtnm13RkKqXgDm0RE+Y eq7+hx6q6/JpLTo8Ts+cW4xoLPas8KqX976XREuPmej0OF1cFzjL8zV4jmeEvBXbaxV2 ioxA== X-Received: by 10.180.90.70 with SMTP id bu6mr1845917wib.34.1369839783114; Wed, 29 May 2013 08:03:03 -0700 (PDT) Received: from localhost (ip-89-176-152-199.net.upcbroadband.cz. [89.176.152.199]) by mx.google.com with ESMTPSA id eq15sm31753308wic.4.2013.05.29.08.03.01 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 29 May 2013 08:03:02 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, eric.dumazet@gmail.com, paulmck@linux.vnet.ibm.com, sasha.levin@oracle.com, akpm@linux-foundation.org Subject: [patch net 1/2] list: introduce list_first_entry_or_null Date: Wed, 29 May 2013 17:02:56 +0200 Message-Id: <1369839777-19158-2-git-send-email-jiri@resnulli.us> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1369839777-19158-1-git-send-email-jiri@resnulli.us> References: <1369839777-19158-1-git-send-email-jiri@resnulli.us> X-Gm-Message-State: ALoCoQkpLIapTueKaoM0fBUcMKYJxgHXlH98VOSUOc6CGnEtwqnpFhD5/zRcKbE8Oscp1J+kZ5MV Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org non-rcu variant of list_first_or_null_rcu Signed-off-by: Jiri Pirko --- include/linux/list.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/list.h b/include/linux/list.h index 6a1f8df..b83e565 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -362,6 +362,17 @@ static inline void list_splice_tail_init(struct list_head *list, list_entry((ptr)->next, type, member) /** + * list_first_entry_or_null - get the first element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_struct within the struct. + * + * Note that if the list is empty, it returns NULL. + */ +#define list_first_entry_or_null(ptr, type, member) \ + (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL) + +/** * list_for_each - iterate over a list * @pos: the &struct list_head to use as a loop cursor. * @head: the head for your list.