Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp436215iog; Mon, 13 Jun 2022 06:00:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRW3ehCPezxwxbj5FicZteg+n8BHE3wctIDsSQ3O2xQlYB2Nzc/NmW1hzSQ1tzxRT1O2KD X-Received: by 2002:a05:6402:a4f:b0:42d:db40:f685 with SMTP id bt15-20020a0564020a4f00b0042ddb40f685mr65100729edb.384.1655125251878; Mon, 13 Jun 2022 06:00:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125251; cv=none; d=google.com; s=arc-20160816; b=iaAakUukwOr/KVOZnBs3Mng22EnLGvpd5z5gDV1DkqUC75ZdZHDUqXyiOOwMgnmkQZ o9I7Zn8M42OTiN7j8IJqy8DVDLsgsRqYlEvi2Nbr5VGlaKJiNH/qVC/eMxl6v2minRKy fQ43DdNkA1VrmX1PsAQbVTwk9GHhS+1FE7/KYShiHPGmv3lwIxR2AWYZLVERAXs+JKkj 4G8d8Rb0vwiSkMkLFpeqIkXvTW5S/UrGgAoZGbmUImJmmBC33JAIFqZGKnCYdr62J8BZ aBlzksBcJeYt+TpW7Jzy+Cvd7NnfYEvFXiFZLYuL4ZhTpREwUEal/wZjuqm9zGxa4lF/ tYRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=b4CDS1v2ICVFAPj5J7gJJ69ZHxr1z6eif13sVNbdMUw=; b=XM5ZkjBQN9svHuG6IQQOCIwic/Y6MaWbKXrH4Z0soRqnVZQoL/5bwZ70vIrw5+TUPg NZnKi3xlnQsInnFWfjq+Lsb3Rldo55uS9VSV6Dr4GgYtMiVMMIkFEpVn2UqSdwbpiMp2 SySpdfFujf8nCID8aaVPGl+eA459fQtRABZuV8NJe8vA6r7e4tcAZ77SLBcIi1EAUvJM zBf9/z+cYDzf9tmvDSF2Y5vHFtr8s33nF0iNV/ETw5wg7G0/6qzOa6hFcbTjNXHXRq1B PTaLqmE4/LGHn9KVm6dpwMp9zW3KJk4aws+ttJMPU1CBTCKhH9j3/P/MFal+jE1tlCMu +xqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b9-20020a056402278900b0042dd795f5cesi8991506ede.283.2022.06.13.06.00.16; Mon, 13 Jun 2022 06:00:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240531AbiFMJsq (ORCPT + 99 others); Mon, 13 Jun 2022 05:48:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240656AbiFMJsK (ORCPT ); Mon, 13 Jun 2022 05:48:10 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31B90193F8; Mon, 13 Jun 2022 02:48:08 -0700 (PDT) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LM6D66n53zjXZg; Mon, 13 Jun 2022 17:47:02 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 13 Jun 2022 17:48:05 +0800 Received: from ubuntu1804.huawei.com (10.67.174.61) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 13 Jun 2022 17:48:05 +0800 From: Yang Jihong To: , , , , , , , , CC: Subject: [RFC 05/13] tools lib: Add list_last_entry_or_null Date: Mon, 13 Jun 2022 17:45:57 +0800 Message-ID: <20220613094605.208401-6-yangjihong1@huawei.com> X-Mailer: git-send-email 2.30.GIT In-Reply-To: <20220613094605.208401-1-yangjihong1@huawei.com> References: <20220613094605.208401-1-yangjihong1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.61] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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-kernel@vger.kernel.org Add list_last_entry_or_null to get the last element from a list, returns NULL if the list is empty. Signed-off-by: Yang Jihong --- tools/include/linux/list.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/include/linux/list.h b/tools/include/linux/list.h index b2fc48d5478c..a4dfb6a7cc6a 100644 --- a/tools/include/linux/list.h +++ b/tools/include/linux/list.h @@ -384,6 +384,17 @@ static inline void list_splice_tail_init(struct list_head *list, #define list_first_entry_or_null(ptr, type, member) \ (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL) +/** + * list_last_entry_or_null - get the last 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_head within the struct. + * + * Note that if the list is empty, it returns NULL. + */ +#define list_last_entry_or_null(ptr, type, member) \ + (!list_empty(ptr) ? list_last_entry(ptr, type, member) : NULL) + /** * list_next_entry - get the next element in list * @pos: the type * to cursor -- 2.30.GIT