From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CFE6C433DB for ; Mon, 1 Feb 2021 16:10:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC1A464E9E for ; Mon, 1 Feb 2021 16:10:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229692AbhBAQKB (ORCPT ); Mon, 1 Feb 2021 11:10:01 -0500 Received: from mga03.intel.com ([134.134.136.65]:9911 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229897AbhBAQJ7 (ORCPT ); Mon, 1 Feb 2021 11:09:59 -0500 IronPort-SDR: tmMsnUdcqtrwROFF980siFlweEbpqsLey1zI/KDfDZehQTDjB44ogL+Z7glgTojfaTv4YdETGt 1luX1Wl1sLog== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="180784943" X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="180784943" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 08:08:08 -0800 IronPort-SDR: FSfa88hx+XVDjLrPi1beO/mBqYjz9PlI9D5VFJTwyb1moJVB5HnTYH83Gaptko9FK++MAicn1e 4YEtBYUYaBFg== X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="479139580" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 08:08:06 -0800 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1l6bkB-001Aab-Dc; Mon, 01 Feb 2021 18:08:03 +0200 Date: Mon, 1 Feb 2021 18:08:03 +0200 From: Andy Shevchenko To: Christian =?iso-8859-1?Q?K=F6nig?= Cc: mojha@codeaurora.org, jkosina@suse.cz, cezary.rojewski@intel.com, neilb@suse.com, b00073877@aus.edu, linux-kernel@vger.kernel.org Subject: Re: [PATCH] list: add more extensive double add check Message-ID: References: <20210201135251.1884-1-christian.koenig@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210201135251.1884-1-christian.koenig@amd.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 01, 2021 at 02:52:51PM +0100, Christian König wrote: > Adding the same element to a linked list multiple times > seems to be a rather common programming mistake. To debug > those I've more than once written some code to check a > linked list for duplicates. > > Since re-inventing the wheel over and over again is a bad > idea this patch tries to add some common code which allows > to check linked lists for duplicates while adding new > elements. > > When list debugging is enabled we currently already check > the previous and next element if they are identical to the > new one. This patch now adds a configuration option to > check N elements before and after the desired position. > > By default we still only test one item since testing more > means quite a large CPU overhead. This can be overwritten > on a per C file bases by defining DEBUG_LIST_DOUBLE_ADD > before including list.h. I'm not sure it is a good idea. Currently the implementation is *generic*. You are customizing it w/o letting caller know. Create a derivative implementation and name it exlist (exclusive list) and use whenever it makes sense. And I think if you are still pushing to modify generic one the default must be 0 in order not altering current behaviour. > A new kunit test is also added to the existing list tests > which intentionally triggers the debug functionality. -- With Best Regards, Andy Shevchenko