Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1093983imw; Fri, 8 Jul 2022 18:55:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t3J4ndiPXFXBqP5UVHdzPOAP4spoTTSDG4+zkPZYgzC8qhSXfTkU/FQaPR2oLbBgnK1P21 X-Received: by 2002:a05:6402:14a:b0:43a:a1a7:abbd with SMTP id s10-20020a056402014a00b0043aa1a7abbdmr8779661edu.137.1657331705434; Fri, 08 Jul 2022 18:55:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657331705; cv=none; d=google.com; s=arc-20160816; b=pSnQZEBhXpyC4Q27zmMc6Tz+H8i3LyVv954vTpd1TCDgxeBzp5uEQsbZCks6yXq7KR Ly7jm0kwa9kk6YISfsCa4iuWvfIczvC/J+L0PjrfZfi2EjUiPXX0jz/T9mpIiiiQXduN lCdlCAvkLoEiRGZz5j6fpPa2V8S06D2zLdjkbwbapYm0bRmrOqUeZDUgiO+vJqfYdYOM xBsvWPI5idVP4hdETOYBvKlOymjXn40ZT/dTdod+hXLZY5L6ftzNUR1aoIB1C7iB0gbL yzWeco1NhGX1gnd+OD6CS3izw4zf0xF2v94ffFtqUMVJEs2mJm0ySvk1xMVa08oVFODb /1tw== 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=S3E9pZoO/WI8MW6CXC0gVp7KsJmdK9UMOk1BjJxzNq176xTJD1/h3ZazfvEMLSwVWM jE+v1Qq9tHX0Gl8cAelAKL0TXsqMw/jAmFlShKztb5CDSJgwVst235z/ZsM6iIlOpKSd SMWKiqdEr6Awf/ZWoNOHmwWXKyk5awI6L1A0QLZyZ4g/l8kMzCL9yUgJ4nf0YRFJWzUV 0zgtMee1hojsD5bpZ1o+mddAfqCLRoFLZprXs/55iwMc9HJdBIBORATnZUJ2s1/BpjJf dVqt6P9b/hWLdvld47Ski582bjTyQ4bM+Jfj4HfU6F/f4nfSYHSMFnLcYTMgrN9AtbAF ALFA== 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 x22-20020a170906711600b006feed02de33si266465ejj.481.2022.07.08.18.54.40; Fri, 08 Jul 2022 18:55:05 -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 S229600AbiGIBxJ (ORCPT + 99 others); Fri, 8 Jul 2022 21:53:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229493AbiGIBxD (ORCPT ); Fri, 8 Jul 2022 21:53:03 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22AA07358F; Fri, 8 Jul 2022 18:53:02 -0700 (PDT) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4LftS91yVWzFq06; Sat, 9 Jul 2022 09:52:09 +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; Sat, 9 Jul 2022 09:53:00 +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; Sat, 9 Jul 2022 09:52:59 +0800 From: Yang Jihong To: , , , , , , , , , CC: Subject: [RFC v3 05/17] tools lib: Add list_last_entry_or_null Date: Sat, 9 Jul 2022 09:50:21 +0800 Message-ID: <20220709015033.38326-6-yangjihong1@huawei.com> X-Mailer: git-send-email 2.30.GIT In-Reply-To: <20220709015033.38326-1-yangjihong1@huawei.com> References: <20220709015033.38326-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: dggems702-chm.china.huawei.com (10.3.19.179) 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