Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2257372pxp; Mon, 21 Mar 2022 15:08:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIGorDIyNIpdjoP3QDQVba9Fs78AeCoHiyBUoKCMRlTXejn+4Q/jCHHkDIavE6ANDpVsCF X-Received: by 2002:a63:7:0:b0:37f:fa5b:95f9 with SMTP id 7-20020a630007000000b0037ffa5b95f9mr19927382pga.57.1647900533703; Mon, 21 Mar 2022 15:08:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647900533; cv=none; d=google.com; s=arc-20160816; b=UrIgecW80peUaEPl43H1ovU7SuJAvHeM7NH/gi3TBFrIWqUhXQcI/be1Wfg4rk9Ylz B+jT2kvoDBDPbsSKuoqliP8+hOBGY590bK2Bbj9tQ/+/rM03q42CGQB7qUcTPL4sVod0 SYIRNruEmo7piZ62z2VBgejndBRhuPizTOanSF+cNP6WzRcloAZeFSRdwMlUiP9fMY5R vKhefkOTM6T5nnAajQ7KafUEk9aMgvue8CG32aCk8FlZM7E91KH5vAhzaAUucHoKOFD9 uqwJTM56w074rhDT7rMrtSTqb/G6yjcIlyHxDiojf4+C8wvMcZ6gvdFRVRrz9qCOhZC5 TAiA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=N2nH/6HpwTaCP8txEBQYJMA9Qv7Ene1XvLcUIwNblbw=; b=0GjCXtOwDbE2jMqVzyR6nxQS7XbgCPxacL4YPwHEXqUZwam/AfaQPxjhPc86SElyIv p5zXtOnAqel3pxhgsI6iwa5uwP4/nVIUW478z9suILUZjNrUZQcvTBdKErjcvEnWLh/n ao19o/kilszBi0DyFamIKc0EVxp41KQoaYfQg7dkDawukKJ7vNf8fIBuq/X36A4R21mf OrScbmLJKICoISbB/wXbpFVoL78X3PEE58jblw8zhIc03B6nD26fvCyjgu6J6tX0CuCe b6gMMPoqLf0vqRidxLuOYXeGYqA2Brn41frZ5yrvbZI0HfBUPf55c93vTpPnGfw7XTiX 7YKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kfuhmI16; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id bd12-20020a656e0c000000b003816043f170si15557889pgb.869.2022.03.21.15.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:08:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kfuhmI16; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A107935CE77; Mon, 21 Mar 2022 14:29:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244142AbiCSUdO (ORCPT + 99 others); Sat, 19 Mar 2022 16:33:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235693AbiCSUdN (ORCPT ); Sat, 19 Mar 2022 16:33:13 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06828A0BC4 for ; Sat, 19 Mar 2022 13:31:52 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id o10so4244080ejd.1 for ; Sat, 19 Mar 2022 13:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=N2nH/6HpwTaCP8txEBQYJMA9Qv7Ene1XvLcUIwNblbw=; b=kfuhmI16RfQ5XyFFwfPWGNgI9FebAcYFdOTi3tz2cN4I4aoMO4xPY9VHdrL9nZF/7K vdSTLgdaQsJoDVjANXS9JhkKNerMkb6jawwr1kJrdLQ0tyDzK2KbJVwypyLIP7nCgFgY DNfLVVptJow8+Bl77Zjd9BdzXpmDiiX3CNCwfXhKQAUZtaP9m0kxE/MS8XH0vlClPDUE 5WNFQ2R+RXx8SnbnTROzpSXuH5ih2Pmpfi0vBOnRtsOcIE8FVjwoesE4B+YG0VHogs/J T4GDiQJm50R5E62bx3g24//zKomA9pTdJPU7nIfEfrmMsRvGIU1yBL1Vllrj2ngYr8ph 5dnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=N2nH/6HpwTaCP8txEBQYJMA9Qv7Ene1XvLcUIwNblbw=; b=t4Rrk4M9qn/gZnMXTyx9/kjudUmz3rdiq2ZD00CTPuXe9jLQ4e1tIB6Bvk4Rt8NOhB USk5hlIh6MRAMZ+3QCEzvA9bLK/p0AIYbyYb+hoT0RTa6Ct14Hi9AxfGJDULD/pB3suq jg5WRmnr6wkdOlE9SEYTVmgw6vbdcoSmzP1nOa4qjzyBYNsrFLTTPoG/jRrM+ylkzMPC xmALl9U/TDjjGU7Yt/2T+tQgmuB2PHIXa6G0RiJruSn7vtisQE9TksTZHks8nkPVsgA3 PvoQ0rTMGEW42TfV/OGJnHON/RTiukUiQUt4bRzCOjMJoS7OwcmjkUGtBVy0VJyOhVip McEw== X-Gm-Message-State: AOAM533PjRkGrIf6tuKdh1dhtnYbOh9PuY/dVbS2A3Uqubq98Hnuh2C0 qmL2IOm5WIlzguUJZXtzyUs= X-Received: by 2002:a17:906:5cb:b0:6cf:954:d84d with SMTP id t11-20020a17090605cb00b006cf0954d84dmr14694950ejt.560.1647721910365; Sat, 19 Mar 2022 13:31:50 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id g15-20020a170906520f00b006cd07ba40absm5131441ejm.160.2022.03.19.13.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Mar 2022 13:31:49 -0700 (PDT) From: Jakob Koschel To: Mark Fasheh Cc: Jakob Koschel , linux-kernel@vger.kernel.org, ocfs2-devel@oss.oracle.com, Joel Becker , Joseph Qi , Andrew Morton , Geert Uytterhoeven , Masahiro Yamada , Miguel Ojeda , Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH] ocfs2: fix check if list iterator did find an element Date: Sat, 19 Mar 2022 21:31:06 +0100 Message-Id: <20220319203106.2541700-1-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 Instead of setting 'res' to NULL, it should only be set if the suitable element was found. In the original code 'res' would have been set to an incorrect pointer if the list is empty. In preparation to limit the scope of the list iterator to the list traversal loop, use a dedicated pointer pointing to the found element [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- fs/ocfs2/dlm/dlmdebug.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/ocfs2/dlm/dlmdebug.c b/fs/ocfs2/dlm/dlmdebug.c index d442cf5dda8a..be5e9ed7da8d 100644 --- a/fs/ocfs2/dlm/dlmdebug.c +++ b/fs/ocfs2/dlm/dlmdebug.c @@ -541,7 +541,7 @@ static void *lockres_seq_start(struct seq_file *m, loff_t *pos) struct debug_lockres *dl = m->private; struct dlm_ctxt *dlm = dl->dl_ctxt; struct dlm_lock_resource *oldres = dl->dl_res; - struct dlm_lock_resource *res = NULL; + struct dlm_lock_resource *res = NULL, *iter; struct list_head *track_list; spin_lock(&dlm->track_lock); @@ -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) { + dlm_lockres_get(iter); + res = iter; + } break; } spin_unlock(&dlm->track_lock); base-commit: 34e047aa16c0123bbae8e2f6df33e5ecc1f56601 -- 2.25.1