From nobody Fri Jun 19 14:43:11 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6033C433F5 for ; Sat, 2 Apr 2022 10:34:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354416AbiDBKf5 (ORCPT ); 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-Google-Smtp-Source: ABdhPJyepaDh+72OJQAb//NtMAZ1iAKNbliOLrLT9DCb8OUjvFb4zCCtWijVSnGfPMi4FdhK3FfLWA== 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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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-=3DwgRr_D8CB-D9Kg-c=3DEHreAsk5SqXPwr= 9Y7k9sA6cWXJ6w@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); =20 static int trace_search_list(struct list_head **list) { - struct trace_event *e; + struct trace_event *e =3D NULL, *iter; int next =3D __TRACE_LAST_TYPE; =20 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 !=3D next) + list_for_each_entry(iter, &ftrace_event_list, list) { + if (iter->type !=3D next) { + e =3D iter; break; + } next++; } =20 @@ -714,7 +716,10 @@ static int trace_search_list(struct list_head **list) if (next > TRACE_EVENT_TYPE_MAX) return 0; =20 - *list =3D &e->list; + if (e) + *list =3D &e->list; + else + *list =3D &ftrace_event_list; return next; } =20 --=20 2.25.1 From nobody Fri Jun 19 14:43:11 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08E46C433EF for ; Sat, 2 Apr 2022 10:34:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354427AbiDBKgB (ORCPT ); Sat, 2 Apr 2022 06:36:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353429AbiDBKfu (ORCPT ); Sat, 2 Apr 2022 06:35:50 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F3BAFFB58 for ; Sat, 2 Apr 2022 03:33:59 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id g22so5685315edz.2 for ; Sat, 02 Apr 2022 03:33:59 -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=GSFi2Vbaam24zbQ2UHEtgn0YLJt9Gjcf9TUTQdEKRhk=; b=ANo/ZBjzbJxD1fwLzVN2KY63i4HMkcnGpsETHRyILMum/mnT6bI7w7rQSLm+j/jV5h mUUI85lGIAF+muhNt0EFB1H1SvFpwPqgWN6MxROdPqctbENACn7gql4ZGuYxSGUJ7Ke0 HoVWf6dS6pughzdsThZDx4RH9+xEXNeObqYHuzeyo0M1yrW8i7FZMV9/5klIgYH2KlN8 DV841lG3axZZHoVHBMyxatjYTz9Dy/i8QobsUwqm/CRqLLrl2sJ3ntWiDmPDImRsSOd3 js3BrqsZJ1YJ9m3E32qBe4FbNHFkgEynskq1mDln3T7ia8OadbVW45OWOPewB5DhAEq2 VvfQ== 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=GSFi2Vbaam24zbQ2UHEtgn0YLJt9Gjcf9TUTQdEKRhk=; b=l79rA53gURhF0q1eBr359WFx4ZM/CoVEdnAq84t7U0hPnGIQ2jA3Munusegy1qbkeD PabMZfOXco7DEzJpEuLwGt0QBsCI0M+6ZIjsLBNw7RDuroG7dOfnZZ6ZXRz+VWkTf6gV /9e0F3K9S8XSVNSbYiQKB9vUw/8JpM1KTShsjDmgRTKjmdbrhHsuXWTTvSCRIPNbQA7t IVfpREmuxcuScKiios9SEXjv0GyYKdWIaEJ3T4PgZdpIPO1y6u/ObOZod+HBaDgil0jZ 2HaFBDq1t2+sv5jpZU9SK+ZpidYxvy4CGgSlNVDfBp/GC7Zucj2hhpIa2xFmEPdJCIO6 EUhQ== X-Gm-Message-State: AOAM532JX7eyg06f4+dZpZWqdEoQjvHehJsq9kH5KGkbHdbYuTHjS3Uj PDyk0Wb9HG8f7MsoULsUt/8pepYsZktFZA== X-Google-Smtp-Source: ABdhPJzz5skU9XAsb8nwsYzCfNOufYhY+mQd7sbgLahPCs9cXcMI5utFQeUaXbA/iTRfW4PrxRH1oQ== X-Received: by 2002:a05:6402:40c9:b0:419:4b81:162e with SMTP id z9-20020a05640240c900b004194b81162emr25135170edb.380.1648895637722; 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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Apr 2022 03:33:57 -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 2/4] tracing: Remove usage of list iterator variable after the loop Date: Sat, 2 Apr 2022 12:33:39 +0200 Message-Id: <20220402103341.1763932-3-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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In preparation to limit the scope of a list iterator to the list traversal loop, use a dedicated pointer to point to the found element [1]. Link: https://lore.kernel.org/all/CAHk-=3DwgRr_D8CB-D9Kg-c=3DEHreAsk5SqXPwr= 9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- kernel/trace/trace_events.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index e11e167b7809..97c7eb2f55e5 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -1723,9 +1723,9 @@ static LIST_HEAD(event_subsystems); =20 static int subsystem_open(struct inode *inode, struct file *filp) { + struct trace_subsystem_dir *dir =3D NULL, *iter_dir; + struct trace_array *tr =3D NULL, *iter_tr; struct event_subsystem *system =3D NULL; - struct trace_subsystem_dir *dir =3D NULL; /* Initialize for gcc */ - struct trace_array *tr; int ret; =20 if (tracing_is_disabled()) @@ -1734,14 +1734,16 @@ static int subsystem_open(struct inode *inode, stru= ct file *filp) /* Make sure the system still exists */ mutex_lock(&event_mutex); mutex_lock(&trace_types_lock); - list_for_each_entry(tr, &ftrace_trace_arrays, list) { - list_for_each_entry(dir, &tr->systems, list) { - if (dir =3D=3D inode->i_private) { + list_for_each_entry(iter_tr, &ftrace_trace_arrays, list) { + list_for_each_entry(iter_dir, &iter_tr->systems, list) { + if (iter_dir =3D=3D inode->i_private) { /* Don't open systems with no events */ - if (dir->nr_events) { + if (iter_dir->nr_events) { __get_system_dir(dir); system =3D dir->subsystem; } + tr =3D iter_tr; + dir =3D iter_dir; goto exit_loop; } } @@ -1753,9 +1755,6 @@ static int subsystem_open(struct inode *inode, struct= file *filp) if (!system) return -ENODEV; =20 - /* Some versions of gcc think dir can be uninitialized here */ - WARN_ON(!dir); - /* Still need to increment the ref count of the system */ if (trace_array_get(tr) < 0) { put_system(dir); --=20 2.25.1 From nobody Fri Jun 19 14:43:11 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F6DDC433EF for ; Sat, 2 Apr 2022 10:34:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354437AbiDBKgC (ORCPT ); Sat, 2 Apr 2022 06:36:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354399AbiDBKfv (ORCPT ); Sat, 2 Apr 2022 06:35:51 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A3B4F55C7 for ; Sat, 2 Apr 2022 03:34:00 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id d10so866782edj.0 for ; Sat, 02 Apr 2022 03:33:59 -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=YxLyiVAe1fZmParic2Rf8qrKN3jJ4OFw0+uxZzajL5E=; b=nqQGArzkAlBLj5t1PKnCWmvItxL90TmoVvVLBsK/RQfOz6HeoALDrcHdCOj5I3sdOu OZ0xdR1182QGoFpRAsTrOppkrQa/kJ//544WWcOZWpqpaN9k9E2quTPuj9THPAMarIrr ak+M2vSpPkXcNv/8z5Rj/FsQ80ug17wolv4tAzwYmzhg84goFf48A7LOeZnryhcnPCrO aJ6zjK0mw4E8C/gZW6bD2bupGRbtGPfvy/VJApkmuNMRFkIjP09UwIv2htXat7L50bKI 9RFH3m2PJaHKbzfJIm5L5hyfMPsJ2BwTgIJIYOlfFG29KHyORW9zriw9AC76mUkEv3bw vbAA== 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=YxLyiVAe1fZmParic2Rf8qrKN3jJ4OFw0+uxZzajL5E=; b=insSxrkakobDBIfj/1c1PgGAoQdj7+rODphXLFgbSxJ1KlySD72TCtGPDkRrFOi4lW 46Ld2TlMebpFD3FmdSO23cP9OI00f3rvdx81t/oUWeHD5EjIcFB5EqefZNKFAzCM7xtH dBuSMr/Ca5zIlpgP+u+2I2VbTE49yYSnlAkZPG6Dh40dP0rL8AsJiewjGtjT07IbBtrS +16ft/+o9xdDB6K2xG7/CgThONgfKE8KgZp0bL7w6oAz+rvyqF6GyOBb2eh8PC8ixb/N OjO/TE57jsh5lUTSRrHZiiePo471pTI8p8Cy/QwzcbZlYbRFkuZj8D0DHk7JxcJ5pWsP 5GNw== X-Gm-Message-State: AOAM532A+9c8ExFgPwrXUPbI27PcdjqFHgOf6hOGHQH3tmZEOE1xUsQw dWl9ryNGQiuvEjvrCF5v5zKcLBzd3Q7DaA== X-Google-Smtp-Source: ABdhPJy8bCxxNAMxlikFqLvo0tREKpqZ+r87LOf/cVQumDaHaOArO+YZeZo19fKQmO+LNy54wDMHdQ== X-Received: by 2002:aa7:dbd6:0:b0:408:4a31:97a5 with SMTP id v22-20020aa7dbd6000000b004084a3197a5mr24868574edt.186.1648895638550; Sat, 02 Apr 2022 03:33:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Apr 2022 03:33:58 -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 3/4] tracing: Replace usage of found with dedicated list iterator variable Date: Sat, 2 Apr 2022 12:33:40 +0200 Message-Id: <20220402103341.1763932-4-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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable instead of a found boolean [1]. This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit. Link: https://lore.kernel.org/all/CAHk-=3DwgRr_D8CB-D9Kg-c=3DEHreAsk5SqXPwr= 9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- kernel/trace/trace_events_hist.c | 17 ++++++++--------- kernel/trace/trace_events_trigger.c | 28 +++++++++++++--------------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_h= ist.c index 44db5ba9cabb..7f60d04d5b6e 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -6089,32 +6089,31 @@ static void hist_unregister_trigger(char *glob, struct event_trigger_data *data, struct trace_event_file *file) { + struct event_trigger_data *test =3D NULL, *iter, *named_data =3D NULL; struct hist_trigger_data *hist_data =3D data->private_data; - struct event_trigger_data *test, *named_data =3D NULL; - bool unregistered =3D false; =20 lockdep_assert_held(&event_mutex); =20 if (hist_data->attrs->name) named_data =3D find_named_trigger(hist_data->attrs->name); =20 - list_for_each_entry(test, &file->triggers, list) { - if (test->cmd_ops->trigger_type =3D=3D ETT_EVENT_HIST) { - if (!hist_trigger_match(data, test, named_data, false)) + list_for_each_entry(iter, &file->triggers, list) { + if (iter->cmd_ops->trigger_type =3D=3D ETT_EVENT_HIST) { + if (!hist_trigger_match(data, iter, named_data, false)) continue; - unregistered =3D true; - list_del_rcu(&test->list); + test =3D iter; + list_del_rcu(&iter->list); trace_event_trigger_enable_disable(file, 0); update_cond_flag(file); break; } } =20 - if (unregistered && test->ops->free) + if (test && test->ops->free) test->ops->free(test->ops, test); =20 if (hist_data->enable_timestamps) { - if (!hist_data->remove || unregistered) + if (!hist_data->remove || test) tracing_set_filter_buffering(file->tr, false); } } diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_event= s_trigger.c index 7eb9d04f1c2e..1ba54a489416 100644 --- a/kernel/trace/trace_events_trigger.c +++ b/kernel/trace/trace_events_trigger.c @@ -614,22 +614,21 @@ static void unregister_trigger(char *glob, struct event_trigger_data *test, struct trace_event_file *file) { - struct event_trigger_data *data; - bool unregistered =3D false; + struct event_trigger_data *data =3D NULL, *iter; =20 lockdep_assert_held(&event_mutex); =20 - list_for_each_entry(data, &file->triggers, list) { - if (data->cmd_ops->trigger_type =3D=3D test->cmd_ops->trigger_type) { - unregistered =3D true; - list_del_rcu(&data->list); + list_for_each_entry(iter, &file->triggers, list) { + if (iter->cmd_ops->trigger_type =3D=3D test->cmd_ops->trigger_type) { + data =3D iter; + list_del_rcu(&iter->list); trace_event_trigger_enable_disable(file, 0); update_cond_flag(file); break; } } =20 - if (unregistered && data->ops->free) + if (data && data->ops->free) data->ops->free(data->ops, data); } =20 @@ -1976,27 +1975,26 @@ void event_enable_unregister_trigger(char *glob, struct trace_event_file *file) { struct enable_trigger_data *test_enable_data =3D test->private_data; + struct event_trigger_data *data =3D NULL, *iter; struct enable_trigger_data *enable_data; - struct event_trigger_data *data; - bool unregistered =3D false; =20 lockdep_assert_held(&event_mutex); =20 - list_for_each_entry(data, &file->triggers, list) { - enable_data =3D data->private_data; + list_for_each_entry(iter, &file->triggers, list) { + enable_data =3D iter->private_data; if (enable_data && - (data->cmd_ops->trigger_type =3D=3D + (iter->cmd_ops->trigger_type =3D=3D test->cmd_ops->trigger_type) && (enable_data->file =3D=3D test_enable_data->file)) { - unregistered =3D true; - list_del_rcu(&data->list); + data =3D iter; + list_del_rcu(&iter->list); trace_event_trigger_enable_disable(file, 0); update_cond_flag(file); break; } } =20 - if (unregistered && data->ops->free) + if (data && data->ops->free) data->ops->free(data->ops, data); } =20 --=20 2.25.1 From nobody Fri Jun 19 14:43:11 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D188C433EF for ; Sat, 2 Apr 2022 10:34:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354444AbiDBKgF (ORCPT ); Sat, 2 Apr 2022 06:36:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229630AbiDBKfw (ORCPT ); Sat, 2 Apr 2022 06:35:52 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C448E1017C3 for ; Sat, 2 Apr 2022 03:34:00 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id a17so5632975edm.9 for ; Sat, 02 Apr 2022 03:34:00 -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=ILXjMgTh/e2skGwgvL/8l3IUSWbsB2Y7GDxe3Qujksk=; b=bJzrJJYwBaxoJ6Z7kwl2l32TO+J+Dvj+ZodRdKkfMFh9/uY7FEOfDA4Pl/FLqKBht8 PxOqcW3GvXK97GEcXsd8N3atIiDLD73is06JhZEmKVWWOFdIjLOBjA8i+a0EhuyXrEUM p9L81El3/aYEQarD8sz1zqCSB5TBUGISih2qF2SUjjL3vCUzrbT3wIU4As2uphMWh9mH wN/bJ5QYYGTTGPiHZKeQrEuoPfmaNXSsNrm4XLYz0OcWaZMQWjOEF54l+E6WstEq9XQn KIyZeMVFEq7DB5ntYRHH902U5roEH46yx2pupzowYOlT1tWwquettZtaqDj3XRmdeooN XC6Q== 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=ILXjMgTh/e2skGwgvL/8l3IUSWbsB2Y7GDxe3Qujksk=; b=SeIG122LRExGi9pc0MhTb3KU67OWxBw9naGwHMVvS+HUmfnwFKzEQHHIMkNfo9ikoo Y3QTdQviEBE76vQi1QRiUC8xc991KqaWnWu+GzCckXpUmX2nYqQw0DhXme9U1VKXIy8c hzKpSIBGPb+oB5NFT4rkhL3z5/AmtaBR/CDEjZQAVrlJ8nDiKH/OMHZySv+/EoNd1Vc+ Fy7kGKSa6T2TLYkf3a95Bs41XDzzst8uqvsMg2ugGPnZSnB7+5MD4GadI9MxhtVePyeD v+E+oNKUpq9AixUkGJdgUffHOKt8AVhh/rQE2eqZPMd/c/jVF3GY6GzJgKWsKO6ASYXY SkIw== X-Gm-Message-State: AOAM532JZ1cG3yFyNw4ljnP/KBn7i9vSLIuaOG4anR6mfVb17WJ4UxE8 ZFhA8c3zNYxIYv+sAUlsRlc= X-Google-Smtp-Source: ABdhPJzSPVtI1CY0cHtzSgWJxAfwaL1GA7j/GTUxM6cNMuSgU9qugJlt4ZlU7+RCvHvr42JVaT+asg== X-Received: by 2002:a05:6402:3591:b0:419:26ea:1e22 with SMTP id y17-20020a056402359100b0041926ea1e22mr24940655edc.27.1648895639358; Sat, 02 Apr 2022 03:33:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Apr 2022 03:33:59 -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 4/4] tracing: Remove check of list iterator against head past the loop body Date: Sat, 2 Apr 2022 12:33:41 +0200 Message-Id: <20220402103341.1763932-5-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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When list_for_each_entry() completes the iteration over the whole list without breaking the loop, the iterator value will be a bogus pointer computed based on the head element. While it is safe to use the pointer to determine if it was computed based on the head element, either with list_entry_is_head() or &pos->member =3D=3D head, using the iterator variable after the loop should be avoided. In preparation to limit the scope of a list iterator to the list traversal loop, use a dedicated pointer to point to the found element [1]. Link: https://lore.kernel.org/all/CAHk-=3DwgRr_D8CB-D9Kg-c=3DEHreAsk5SqXPwr= 9Y7k9sA6cWXJ6w@mail.gmail.com/ Signed-off-by: Jakob Koschel --- kernel/trace/ftrace.c | 20 ++++++++++++-------- kernel/trace/trace_eprobe.c | 14 ++++++++------ kernel/trace/trace_events.c | 12 ++++++------ 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 4f1d2f5e7263..5c465e70d146 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -4560,8 +4560,8 @@ register_ftrace_function_probe(char *glob, struct tra= ce_array *tr, struct ftrace_probe_ops *probe_ops, void *data) { + struct ftrace_func_probe *probe =3D NULL, *iter; struct ftrace_func_entry *entry; - struct ftrace_func_probe *probe; struct ftrace_hash **orig_hash; struct ftrace_hash *old_hash; struct ftrace_hash *hash; @@ -4580,11 +4580,13 @@ register_ftrace_function_probe(char *glob, struct t= race_array *tr, =20 mutex_lock(&ftrace_lock); /* Check if the probe_ops is already registered */ - list_for_each_entry(probe, &tr->func_probes, list) { - if (probe->probe_ops =3D=3D probe_ops) + list_for_each_entry(iter, &tr->func_probes, list) { + if (iter->probe_ops =3D=3D probe_ops) { + probe =3D iter; break; + } } - if (&probe->list =3D=3D &tr->func_probes) { + if (!probe) { probe =3D kzalloc(sizeof(*probe), GFP_KERNEL); if (!probe) { mutex_unlock(&ftrace_lock); @@ -4702,9 +4704,9 @@ int unregister_ftrace_function_probe_func(char *glob, struct trace_array *tr, struct ftrace_probe_ops *probe_ops) { + struct ftrace_func_probe *probe =3D NULL, *iter; struct ftrace_ops_hash old_hash_ops; struct ftrace_func_entry *entry; - struct ftrace_func_probe *probe; struct ftrace_glob func_g; struct ftrace_hash **orig_hash; struct ftrace_hash *old_hash; @@ -4732,11 +4734,13 @@ unregister_ftrace_function_probe_func(char *glob, s= truct trace_array *tr, =20 mutex_lock(&ftrace_lock); /* Check if the probe_ops is already registered */ - list_for_each_entry(probe, &tr->func_probes, list) { - if (probe->probe_ops =3D=3D probe_ops) + list_for_each_entry(iter, &tr->func_probes, list) { + if (iter->probe_ops =3D=3D probe_ops) { + probe =3D iter; break; + } } - if (&probe->list =3D=3D &tr->func_probes) + if (!probe) goto err_unlock_ftrace; =20 ret =3D -EINVAL; diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c index 541aa13581b9..63e901a28425 100644 --- a/kernel/trace/trace_eprobe.c +++ b/kernel/trace/trace_eprobe.c @@ -650,7 +650,7 @@ static struct trace_event_functions eprobe_funcs =3D { static int disable_eprobe(struct trace_eprobe *ep, struct trace_array *tr) { - struct event_trigger_data *trigger; + struct event_trigger_data *trigger =3D NULL, *iter; struct trace_event_file *file; struct eprobe_data *edata; =20 @@ -658,14 +658,16 @@ static int disable_eprobe(struct trace_eprobe *ep, if (!file) return -ENOENT; =20 - list_for_each_entry(trigger, &file->triggers, list) { - if (!(trigger->flags & EVENT_TRIGGER_FL_PROBE)) + list_for_each_entry(iter, &file->triggers, list) { + if (!(iter->flags & EVENT_TRIGGER_FL_PROBE)) continue; - edata =3D trigger->private_data; - if (edata->ep =3D=3D ep) + edata =3D iter->private_data; + if (edata->ep =3D=3D ep) { + trigger =3D iter; break; + } } - if (list_entry_is_head(trigger, &file->triggers, list)) + if (!trigger) return -ENODEV; =20 list_del_rcu(&trigger->list); diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 97c7eb2f55e5..c86cbb25879d 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -2279,8 +2279,8 @@ static struct dentry * event_subsystem_dir(struct trace_array *tr, const char *name, struct trace_event_file *file, struct dentry *parent) { + struct event_subsystem *system, *iter; struct trace_subsystem_dir *dir; - struct event_subsystem *system; struct dentry *entry; =20 /* First see if we did not already create this dir */ @@ -2294,13 +2294,13 @@ event_subsystem_dir(struct trace_array *tr, const c= har *name, } =20 /* Now see if the system itself exists. */ - list_for_each_entry(system, &event_subsystems, list) { - if (strcmp(system->name, name) =3D=3D 0) + system =3D NULL; + list_for_each_entry(iter, &event_subsystems, list) { + if (strcmp(iter->name, name) =3D=3D 0) { + system =3D iter; break; + } } - /* Reset system variable when not found */ - if (&system->list =3D=3D &event_subsystems) - system =3D NULL; =20 dir =3D kmalloc(sizeof(*dir), GFP_KERNEL); if (!dir) --=20 2.25.1