From: James Clark <james.clark@linaro.org>
To: Leo Yan <leo.yan@arm.com>
Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Tamas Zsoldos <tamas.zsoldos@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Mike Leach <mike.leach@linaro.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>
Subject: Re: [PATCH] coresight: perf: Fix pointer check with IS_ERR_OR_NULL()
Date: Thu, 4 Sep 2025 13:11:37 +0100 [thread overview]
Message-ID: <20cec516-1589-4fc5-ac07-06029f2dc143@linaro.org> (raw)
In-Reply-To: <5f24d286-629c-404f-8e0f-aa01e27bcb80@linaro.org>
On 04/09/2025 1:00 pm, James Clark wrote:
>
>
> On 04/09/2025 11:53 am, Leo Yan wrote:
>> The returned pointer from .alloc_buffer() callback can be an error, if
>> only checking NULL pointer the driver cannot capture errors. The driver
>> will proceed even after failure and cause kernel panic.
>>
>> Change to use IS_ERR_OR_NULL() check for capture error cases.
>>
>> Fixes: 0bcbf2e30ff2 ("coresight: etm-perf: new PMU driver for ETM
>> tracers")
>> Reported-by: Tamas Zsoldos <tamas.zsoldos@arm.com>
>> Signed-off-by: Leo Yan <leo.yan@arm.com>
>> ---
>> drivers/hwtracing/coresight/coresight-etm-perf.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/
>> drivers/hwtracing/coresight/coresight-etm-perf.c
>> index
>> f677c08233ba1a28b277674662c6e6db904873dd..440d967f5d0962df187a81b0dd69a7d82a8b62ba 100644
>> --- a/drivers/hwtracing/coresight/coresight-etm-perf.c
>> +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
>> @@ -198,7 +198,7 @@ static void free_sink_buffer(struct etm_event_data
>> *event_data)
>> cpumask_t *mask = &event_data->mask;
>> struct coresight_device *sink;
>> - if (!event_data->snk_config)
>> + if (IS_ERR_OR_NULL(event_data->snk_config))
>> return;
>> if (WARN_ON(cpumask_empty(mask)))
>> @@ -450,7 +450,7 @@ static void *etm_setup_aux(struct perf_event
>> *event, void **pages,
>> event_data->snk_config =
>> sink_ops(sink)->alloc_buffer(sink, event, pages,
>> nr_pages, overwrite);
>> - if (!event_data->snk_config)
>> + if (IS_ERR_OR_NULL(event_data->snk_config))
>> goto err;
>
> I think the bug is in TRBE. It's the only one that returns an error
> pointer, but only for -ENOMEM which would normally be NULL for alloc
> type functions anyway.
>
> Also it's assigned to event_data->snk_config which is later NULL checked
> rather than IS_ERR_OR_NULL in free_sink_buffer(). Maybe that path
> doesn't happen, but all instances should be updated anyway.
Oh sorry I was only looking at the update to etm_setup_aux() so both
functions are covered. But the other points still apply.
>
> It's much easier to keep it as NULL and make the fix in TRBE. It also
> wouldn't need to be backported as far.
>
>> out:
>>
>> ---
>> base-commit: fa71e9cb4cfa59abb196229667ec84929bdc18fe
>> change-id: 20250904-cs_etm_auxsetup_fix_error_handling-cb7e07ed9adf
>>
>> Best regards,
>
next prev parent reply other threads:[~2025-09-04 12:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-04 10:53 Leo Yan
2025-09-04 12:00 ` James Clark
2025-09-04 12:11 ` James Clark [this message]
2025-09-04 13:02 ` Leo Yan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20cec516-1589-4fc5-ac07-06029f2dc143@linaro.org \
--to=james.clark@linaro.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=coresight@lists.linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=leo.yan@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=mike.leach@linaro.org \
--cc=suzuki.poulose@arm.com \
--cc=tamas.zsoldos@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®