Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2281530pxp; Mon, 21 Mar 2022 15:47:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgtpSaxjdFqLzwP9tu94EMFvJzWp4eUwr/CAbyNzKHnq40ZrUiBQCNon5mtPsMtteyVpNU X-Received: by 2002:a17:902:b7c1:b0:153:e971:663e with SMTP id v1-20020a170902b7c100b00153e971663emr15045299plz.78.1647902865730; Mon, 21 Mar 2022 15:47:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647902865; cv=none; d=google.com; s=arc-20160816; b=wClFF06+Sa7HHXhfm8H05nxId26Wjt4vBAFjpMQtHE98CqOjb5Ez9Rt5BV9mi/SvF1 9BJiPJz7gRqNZTbzSkt6URVACa895N5lMvyouBvfrvLkHfEvNX04BKRnEsnH0iqPB/kb 7B1A7bCfiHzEwP/vpz1IPaMvYIYBZLiCXvGNGkAekTBYG4S5CV0kKFjD47ru35lwGb2g QG0/ch/U7Cz8yVCevNdWiv6NaINiqtiY/nJ6s1FEPsL6ak5pai5YDAzxCCfmio0ZFn2Z 31BAvVMKXG68oJvqIJPUiqlBxEfvjCzDvaold1zCcsd9/PznOnlCAg+3jKdPnOCSDWvz TD3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=RZgeWJxhAC3t+1bfWE/8UUCJ/HfPGpjY4wW8i19DvR8=; b=AFV/agQQZyImQ3f9yh1sToctjqk3u88sxz1Ot1exM4uAaTh3lZ2w/o/+S1OmugEfo2 /Y0Ib60Aur7dy2GSv9FVQezwvlxhiIoqfnsqEqTzUTkejSVw/huq5f4nnXO752yab0Xu t5ccUZs+CzBhXS4FpgPL6GqzMadElfwDvBCr7iILfhEGnmbUkaN+syC9SNZ7X5N+Tg3i kWwvxZf3P7Mcia1OUwO+KNkpnwMSDydbiupzpGILj6UAwRSJkHe1eCSlwgsEFooqhlLm 9HngS5H2ZdCDGU9R8QuvZQQUO4ut+s0N04cwYkhCIdVFcl0p9JY7VoCjA1zlw2lQusqx PBGg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h7-20020a170902ac8700b00153b2d16511si11806010plr.281.2022.03.21.15.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:47:45 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CB6912EA0D6; Mon, 21 Mar 2022 14:55:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349079AbiCUQBn convert rfc822-to-8bit (ORCPT + 99 others); Mon, 21 Mar 2022 12:01:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241372AbiCUQBl (ORCPT ); Mon, 21 Mar 2022 12:01:41 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 28AFD496BD for ; Mon, 21 Mar 2022 09:00:14 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-239-DZcqY6ZCNM-Zxa3ztE6Iiw-1; Mon, 21 Mar 2022 16:00:10 +0000 X-MC-Unique: DZcqY6ZCNM-Zxa3ztE6Iiw-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Mon, 21 Mar 2022 16:00:11 +0000 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.033; Mon, 21 Mar 2022 16:00:10 +0000 From: David Laight To: 'Dan Carpenter' , Jakob Koschel CC: Joseph Qi , Mark Fasheh , Linux Kernel Mailing List , "ocfs2-devel@oss.oracle.com" , Joel Becker , Andrew Morton , "Geert Uytterhoeven" , Masahiro Yamada , Miguel Ojeda , Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: RE: [PATCH] ocfs2: fix check if list iterator did find an element Thread-Topic: [PATCH] ocfs2: fix check if list iterator did find an element Thread-Index: AQHYPSvRVnhy0IZf6EGgy069JPLEqKzJ/HWg Date: Mon, 21 Mar 2022 16:00:10 +0000 Message-ID: <75180dd18a3f460891cd93f7fcb3aa1c@AcuMS.aculab.com> References: <20220319203106.2541700-1-jakobkoschel@gmail.com> <20220321135435.GL336@kadam> In-Reply-To: <20220321135435.GL336@kadam> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Dan Carpenter > Sent: 21 March 2022 13:55 > On Mon, Mar 21, 2022 at 02:34:34PM +0100, Jakob Koschel wrote: > > >> @@ -556,11 +556,11 @@ static void *lockres_seq_start(struct seq_file *m, loff_t *pos) > > >> } > > >> } > > >> > > >> - list_for_each_entry(res, track_list, tracking) { > > >> - if (&res->tracking == &dlm->tracking_list) > > >> - res = NULL; > > >> - else > > >> - dlm_lockres_get(res); > > >> + list_for_each_entry(iter, track_list, tracking) { > > >> + if (&iter->tracking != &dlm->tracking_list) { > > This is an open coded version of: > > if (!list_entry_is_head(iter, &dlm->tracking_list, tracking)) { Doesn't list_for_each_entry() terminate before that happens? So this code is probably still horribly broken. My worry about bugs with these lists isn't really the code that uses list_for_each_entry() - they are fairly easy to locate, read and fix. The problem is all the other code that is scanning these list in other more obscure ways. It really isn't a list structure that is easy to use at all. It's only slight advantage is that you can unlink an item without knowing the list head. (Which can stop buggy code generating cross-linked lists.) Unless you actually need to traverse backwards the 'back pointer points to forwards pointer' list is much better. Even if you have to maintain a 'pointer to last' to get FIFO operation. The other option is to double-link the items into a loop and have a 'head' that points to the first item. Both these loops have 'pointer to items' to don't need container_of() and get better type checking from the compiler. David > > Ideally someone would come through with enough confidence to just delete > it but the second best option is to just make it readable... > > regards, > dan carpenter > > > >> + dlm_lockres_get(iter); > > >> + res = iter; > > >> + } > > >> break; > > >> } - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)