Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3490402pxb; Mon, 4 Apr 2022 18:39:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDBVN7+IxLIOAt1l5q76vSmPU42OhvBRhI26Y0w/Tuhxx3VwnExbeksayUvciOh0eu6x5H X-Received: by 2002:a63:b20a:0:b0:398:9e3e:d581 with SMTP id x10-20020a63b20a000000b003989e3ed581mr900091pge.236.1649122774827; Mon, 04 Apr 2022 18:39:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649122774; cv=none; d=google.com; s=arc-20160816; b=TUvO9yZwahpCHG1yBvtMeRzXtZ48mPg6o9dBbClkJZMan3ABeBZOCPtZpKPoDQkKGF naplL6k9JSX/G/gXlg5ck+PsRjmnLu/zeOxhtIkyYwV/Mol855LpQh5mDkRD0TkNKTj8 A1ovDgR0EkeSW2vVxNRtqchPim7+wU7jal68Scfq/PrMl3kBZWtx0ztgaITXTVLzfB+M UrlrwUObWtvl+POio3iDQgW+wL/+kzKKoZBZZ0G3qgLOdJw2DxXHLkRLH3HBep85iXq2 ++LuBTxFnnMrPSzX6LKDtTJkTtOHW+QKuk1b2Ii8/7H8yOqN2uipWNT7tVe0TEkGkDH+ BJkA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LastlIlp3ExuBmWFIzRxFtrilFT5BPcN0d/npk5blEA=; b=iV/3HKWrffoHapVRTD3pVChUhzwDk6BueBGdJ6PPw4w0393bM9XAKNNAgh6Zb34YII EfErHzoM2nAqKewxwFU8sJKl7Wqori1U4guBceSjb4AqQhm9uHs2S5bQWYlFG53PLnQP PZZM/D0G8/bcC+t6toO4ZgAE12joQAB3kf/viQQdePmAYwt+/r1lpX9KdZxizwve/4IY L916qLup6MPTSxcLHtfyvT/JvECUApRNj6XMKJ77T5Q/BhXjmALnHHum2868bRelh92i YsiQpE6h9HrNREiRxwFnDM2OGMcDNhfjY9u3Z8dcnjQWtEHtktcGxQ6Ogjab0k94ZPot cGmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qvysjYio; 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 p25-20020a637419000000b003816043f15asi12116840pgc.847.2022.04.04.18.39.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 18:39:34 -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=qvysjYio; 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 86898888CA; Mon, 4 Apr 2022 17:33:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354410AbiDBKf5 (ORCPT + 99 others); Sat, 2 Apr 2022 06:35:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350473AbiDBKft (ORCPT ); Sat, 2 Apr 2022 06:35:49 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77704F9544 for ; Sat, 2 Apr 2022 03:33:58 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id a17so5632929edm.9 for ; Sat, 02 Apr 2022 03:33:58 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=LastlIlp3ExuBmWFIzRxFtrilFT5BPcN0d/npk5blEA=; b=qvysjYio+jn5bNdMLOOFpyAVg/y4GfHySl3OV/+G3ttTph1rUoz8ruHWZPDEYgoqV0 3Eb91ZKTxqCSW0utwO0bo67gzijYl/Z3o6Zfysn0aACn1yCB4lRn6IT3Q+L/c1u3egRX sxlvLumga9zCmaCH12sYSYFcBv51l0Cth48A608/ofNZ3yUigUUi4SIT7hnMxF2LYQ2D RDOE+0zYErNwEcNq7gUyabAvA+s4oFbuM/07YvSOjU49v13x0RawxFSLRTf9k0PfZD/G W0U+NSQmUhF9x2ky0RqueRQcWVt5hrpLHc8/oStTOFonKXXw9VHmHHl4GQQ1gSks/JUR vjLw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=LastlIlp3ExuBmWFIzRxFtrilFT5BPcN0d/npk5blEA=; b=C6ahXU6J0m8WDudWgcqjzS8IRpbSkL4pMQeAOI31FHMTnnIkeWUwL9p+tItmA7Rll7 eQBzjuG2Bz0nd2DvKB/MpP8TQzZzw1/VAL92jqZF3ftdw/DvToBBoDJEyt26nW9x5ZFX IR9Cdco3pl/QkPbN83azS3bp3EtLtARLJ5ePJ/W1kVh86oJx8ItBgGK33wj0voG/K+a1 KpW2boJMe46d+w2ABndlGKWTAtBEQ/1d6P37HswJFoK4hxywcgb+44mA7eU2u2i6Dvfa pDN4wKUJSX22xP27OD5TlvJ7HGZzLgJv7asdiNm8j4YQFzbr5Ck4n+JcmPM5TMLUs1np HacA== X-Gm-Message-State: AOAM531eBhXXFvT3Ag6DVSkMYdK7YJeWv8Ng6SuQqnG/ouBHAY/v6qs5 MfECiYEa1iFZ6Qv/2erQOAM= X-Received: by 2002:a05:6402:362:b0:419:2b6d:a662 with SMTP id s2-20020a056402036200b004192b6da662mr24946416edw.54.1648895637045; Sat, 02 Apr 2022 03:33:57 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id ka22-20020a170907921600b006e4c1ab0bbdsm1886965ejb.207.2022.04.02.03.33.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Apr 2022 03:33:56 -0700 (PDT) From: Jakob Koschel To: Steven Rostedt Cc: Ingo Molnar , linux-kernel@vger.kernel.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel Subject: [PATCH v2 1/4] tracing: Remove usage of list iterator after the loop body Date: Sat, 2 Apr 2022 12:33:38 +0200 Message-Id: <20220402103341.1763932-2-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220402103341.1763932-1-jakobkoschel@gmail.com> References: <20220402103341.1763932-1-jakobkoschel@gmail.com> 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 In preparation to limit the scope of the list iterator variable to the traversal loop, use a dedicated pointer to point to the found element [1]. Before, the code implicitly used the head when no element was found when using &pos->list. Since the new variable is only set if an element was found, the head needs to be used explicitly if the variable is NULL. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- kernel/trace/trace_output.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index 8aa493d25c73..733a4d6c20e2 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -692,7 +692,7 @@ static LIST_HEAD(ftrace_event_list); static int trace_search_list(struct list_head **list) { - struct trace_event *e; + struct trace_event *e = NULL, *iter; int next = __TRACE_LAST_TYPE; if (list_empty(&ftrace_event_list)) { @@ -704,9 +704,11 @@ static int trace_search_list(struct list_head **list) * We used up all possible max events, * lets see if somebody freed one. */ - list_for_each_entry(e, &ftrace_event_list, list) { - if (e->type != next) + list_for_each_entry(iter, &ftrace_event_list, list) { + if (iter->type != next) { + e = iter; break; + } next++; } @@ -714,7 +716,10 @@ static int trace_search_list(struct list_head **list) if (next > TRACE_EVENT_TYPE_MAX) return 0; - *list = &e->list; + if (e) + *list = &e->list; + else + *list = &ftrace_event_list; return next; } -- 2.25.1