Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4473753pxb; Tue, 2 Mar 2021 16:50:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJyU2F09Pbp++G4NZ41R052ZlCZbWPR/DztAEsXtVCwYwgLyQdiF2KxjUI9nJ9YlIyRuT9T1 X-Received: by 2002:a05:6402:5188:: with SMTP id q8mr22831815edd.89.1614732652154; Tue, 02 Mar 2021 16:50:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614732652; cv=none; d=google.com; s=arc-20160816; b=bmWsqIc7Uzbouhf6YBKZOQnIDcJGrpTWsyURTSM11/po9D+dOxItcVZ9CKtXnDfLqD zC7xUETxAG8559ShHNIJP/Torje13pg8cYERJb5t+/r8aTcs4/OYQJ5hEAPU3z0V0Teu pjPA/y6PR1wPfldwyOjyKKR9vJFYOI8NwwTPAAVjiz6X1I9Mmemmp3zvy4TJjDxWcAZa j0opTXG0ppmY2tmMhrf6apQ2PsiExQC3tV92aXxqEb198wnoiupq4Q+MBzXgrLyjk/+8 G0fOL9XqmqthMZMq7MSG4dQUvpi792Ed+ALQjtx/Psb0dMSJAgCEceIIhlGEgPk6bnr1 iQHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=Wyo9CCEF7GwvtLqTjeBki/E9Sc2FEtNu7xO51ozymyM=; b=EfeO/R6e6mKXIdDrH4XwMUU9OYh1Ub0vf1NSHyl4DkaS7G3etdOYSa9ZGdSoR69zJe p7ojr4lwgLlS0fQeVXsS1xXdVzYb1QWkE3Eo04o7IeV/bfJj2FEpziaXQJ8Xk0tT49My biJk+AcK2t5UbEWv5FkrON0dzQZXvPy3XmqjZ8IlFgBGklGCGuUMNSz7HX5Fg4CoVavM d2VhKTL3wgn3aLF6WR9mwMWD9A0ezCkSfutCoDpbM9VBrmLt12kLROKljPYD9gLvjzXi pqGWXWLHZcwt7SMDl4uIPfr+ZWhECgppJYNUDMuMpK76ntOX4mI67FBKJobepahFj5Be cxuA== 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 qh28si6741093ejb.580.2021.03.02.16.50.29; Tue, 02 Mar 2021 16:50:52 -0800 (PST) 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 S233171AbhCAIf1 (ORCPT + 99 others); Mon, 1 Mar 2021 03:35:27 -0500 Received: from mga14.intel.com ([192.55.52.115]:56647 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232895AbhCAIdk (ORCPT ); Mon, 1 Mar 2021 03:33:40 -0500 IronPort-SDR: B1LNH7I/85b68iFtttNsvBcTFtzHBKNy//iJgsiLnuGZxF0yK09pSO8jQYOKaXC4dzbgDQksKG ksJ5IBOb4vtg== X-IronPort-AV: E=McAfee;i="6000,8403,9909"; a="185718758" X-IronPort-AV: E=Sophos;i="5.81,215,1610438400"; d="scan'208";a="185718758" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2021 00:31:41 -0800 IronPort-SDR: hadJVW2c2e/AJp+MHqcDWpB7XBXqewfPlSB7WsdFy6Q/IGf0/gsfiFTEVJAUyHiR1/anheqF0N yXLUlmg5vawg== X-IronPort-AV: E=Sophos;i="5.81,215,1610438400"; d="scan'208";a="435329400" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2021 00:31:12 -0800 Received: from paasikivi.fi.intel.com (localhost [127.0.0.1]) by paasikivi.fi.intel.com (Postfix) with SMTP id DBE0F202DD; Mon, 1 Mar 2021 10:31:04 +0200 (EET) Date: Mon, 1 Mar 2021 10:31:04 +0200 From: Sakari Ailus To: Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Laurent Pinchart Subject: Re: [PATCH 1/2] list: Add list_is_null() to check if a list_head has been initialized Message-ID: <20210301083104.GR3@paasikivi.fi.intel.com> References: <20210226224938.18166-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210226224938.18166-1-laurent.pinchart@ideasonboard.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Laurent, Thanks for the patch. On Sat, Feb 27, 2021 at 12:49:37AM +0200, Laurent Pinchart wrote: > From: Laurent Pinchart > > The new function checks if the list_head prev and next pointers are > NULL, in order to see if a list_head that has been zeroed when allocated > has been initialized with INIT_LIST_HEAD() or added to a list. > > This can be used in cleanup functions that want to support being safely > called when an object has not been initialized, to return immediately. > In most cases other fields of the object can be checked for this > purpose, but in some cases a list_head field is the only option. > > Signed-off-by: Laurent Pinchart > --- > include/linux/list.h | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/include/linux/list.h b/include/linux/list.h > index 85c92555e31f..e4fc6954de3b 100644 > --- a/include/linux/list.h > +++ b/include/linux/list.h > @@ -29,6 +29,19 @@ static inline void INIT_LIST_HEAD(struct list_head *list) > list->prev = list; > } > > +/** > + * list_is_null - check if a list_head has been initialized > + * @list: the list > + * > + * Check if the list_head prev and next pointers are NULL. This is useful to > + * see if a list_head that has been zeroed when allocated has been initialized > + * with INIT_LIST_HEAD() or added to a list. How this should work with an entry that has been removed from a list with list_del()? The values will be LIST_POISON[12] and so this function will return true. Should it return false instead? > + */ > +static inline bool list_is_null(struct list_head *list) > +{ > + return list->prev == NULL && list->next == NULL; What would you think of issuing a warning if one is NULL but the other one isn't? That could happen if the memory is uninitialised by the caller. It should return true in that case, too. > +} > + > #ifdef CONFIG_DEBUG_LIST > extern bool __list_add_valid(struct list_head *new, > struct list_head *prev, -- Kind regards, Sakari Ailus