Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3847279pxk; Tue, 29 Sep 2020 07:44:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMqGAPNt/Rj4pWR4992PLMRKsQwN9KnJ8HDuw3QQCGB2x5yq2kD7W0uqTO0vBTfMSgYM9Q X-Received: by 2002:aa7:c0d3:: with SMTP id j19mr3775626edp.40.1601390652404; Tue, 29 Sep 2020 07:44:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601390652; cv=none; d=google.com; s=arc-20160816; b=hJ9fckEWZVz0z6U0ewWzfosxcBIKVca929IP9F/ucW+6C/EDFXPuvATD/qIQCCf1H1 QG9LRi5wWdE3w/no7QaOGhP3kc2nMdcFby5yFsmnIF598997EoD/EGLeDIL6CBgayXE+ qhpg/ITzp99e7YAkwPGCz+yrfZpyxc5R+vvgWeIYBo15UaqOnUTRkPa/BKc93oxGYzCZ Fs2iGKvfl6SAgtgViwJ6jB/Iv0eCglNPn32qYeBSQEU9PNE9OWOlS+1wf+YRv0AA9UTu 0yagORfK4ThTaualQhumr8S5G1Qgsj3xDiJlHZ0/sWjz1aRO/PW5uRiIw13hGdVfSVcP msNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :dlp-version:dlp-reaction:dlp-product:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=HUDI0ORu38AYR2xkE/r9U9k4nc1rpzIij7Ok72CtJqE=; b=iDCxIBqF1wH95lqvgdkoQyqTiOqGcffSsbfVIg7l2o6iJNVutvjgMvzti+uGTK3dPR nOkxfyAaJn1/fbUNLWbA6VX7p8++P/Gj3CRp05Sfjz4uzgGm2Ff5rbt9wQrmG1hSS+O6 EP0liTjkXzFrdjQZcylTibrnxHCFTEjh7Js4ov6Lf8T/PfeC4ngCzuN+kgJj2rWUly1V o2I9KhJOQL6/UGi9wifV489juoTvhiGn4weAJLNXlcRvkBKFbd2Eo1UfKzy4gm59hDhs 2b8YN3KRdLmEo5vWV/whNUWVO9hJgJn1/URGHURPwGNykLK2K5IKT2IhYXDmU8WTpyiw +png== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ox26si1452811ejb.730.2020.09.29.07.43.49; Tue, 29 Sep 2020 07:44:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731477AbgI2Oka convert rfc822-to-8bit (ORCPT + 99 others); Tue, 29 Sep 2020 10:40:30 -0400 Received: from mga09.intel.com ([134.134.136.24]:6246 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731420AbgI2Ok0 (ORCPT ); Tue, 29 Sep 2020 10:40:26 -0400 IronPort-SDR: vRDWGH6FOVcYL5eSl+8FzHWbSGlUb5ZOiiLgWdt1GNZlJ+4R+iLln+eTQDY6SWhDAwNIZVhavZ 7OaSzg3ZGe3w== X-IronPort-AV: E=McAfee;i="6000,8403,9758"; a="163078429" X-IronPort-AV: E=Sophos;i="5.77,319,1596524400"; d="scan'208";a="163078429" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2020 07:40:24 -0700 IronPort-SDR: +wZ7CksQQGgpYoSu7T9vjla7Z7LXHP4nUC66KD+iy+ZE+tDTtX+LPy1y98ZBdBUPec+1xZycL9 aYqZuQ+jA89A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,319,1596524400"; d="scan'208";a="324693822" Received: from irsmsx606.ger.corp.intel.com ([163.33.146.139]) by orsmga002.jf.intel.com with ESMTP; 29 Sep 2020 07:40:24 -0700 Received: from irsmsx601.ger.corp.intel.com (163.33.146.7) by IRSMSX606.ger.corp.intel.com (163.33.146.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 29 Sep 2020 15:40:23 +0100 Received: from irsmsx601.ger.corp.intel.com ([163.33.146.7]) by irsmsx601.ger.corp.intel.com ([163.33.146.7]) with mapi id 15.01.1713.004; Tue, 29 Sep 2020 15:40:23 +0100 From: "Rojewski, Cezary" To: Andy Shevchenko CC: "linux-kernel@vger.kernel.org" , "Andrew Morton" Subject: Re: [PATCH v2] list: Add a macro to test if entry is pointing to the head Thread-Topic: [PATCH v2] list: Add a macro to test if entry is pointing to the head Thread-Index: AQHWlmaO97X0AF+CMUuhSjA0mQ6lcal/rq5g Date: Tue, 29 Sep 2020 14:40:23 +0000 Message-ID: <5f95bede9603416ca9f1c6ee17d54b35@intel.com> References: <20200929134342.51489-1-andriy.shevchenko@linux.intel.com> In-Reply-To: <20200929134342.51489-1-andriy.shevchenko@linux.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 x-originating-ip: [163.33.253.164] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-09-29 3:43 PM, Andy Shevchenko wrote: > Add a macro to test if entry is pointing to the head of the list > which is useful in cases like: > > list_for_each_entry(pos, &head, member) { > if (cond) > break; > } > if (list_entry_is_head(pos, &head, member)) > return -ERRNO; > > that allows to avoid additional variable to be added to track if loop > has not been stopped in the middle. > > While here, convert list_for_each_entry*() family of macros to use a new one. > > Signed-off-by: Andy Shevchenko > --- > v2: converted users inside list.h, dropped ambiguous description Reviewed-by: Cezary Rojewski This is a good addition to the list of helper macros found in list.h. When looking at below: > /** > * list_for_each_entry - iterate over list of given type > * @pos: the type * to use as a loop cursor. > @@ -617,7 +626,7 @@ static inline void list_splice_tail_init(struct list_head *list, > */ > #define list_for_each_entry(pos, head, member) \ > for (pos = list_first_entry(head, typeof(*pos), member); \ > - &pos->member != (head); \ > + !list_entry_is_head(pos, head, member); \ > pos = list_next_entry(pos, member)) > it seems such helper should have been here a long time ago (notice the usage of helpers for initial assignment and cursor update while the loop-exit check was devoid of such). Czarek