From: Damien Le Moal <dlemoal@kernel.org>
To: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Cc: "linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Kishon Vijay Abraham I" <kishon@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Frank Li" <Frank.Li@nxp.com>,
"Niklas Cassel" <cassel@kernel.org>
Subject: Re: [PATCH] PCI: endpoint: pci-epf-test: NULL check dma channels before release
Date: Fri, 12 Sep 2025 19:38:03 +0900 [thread overview]
Message-ID: <c7411e4b-83ba-45cb-8d76-37e1d0ad6ddc@kernel.org> (raw)
In-Reply-To: <juziivdtvq4lcpugrw6whe7leq324cqspncd2ivojzp3bvm5l7@lhmdfj3lkjob>
On 9/12/25 18:59, Shinichiro Kawasaki wrote:
> On Sep 12, 2025 / 16:31, Damien Le Moal wrote:
>> On 9/12/25 16:11, Shin'ichiro Kawasaki wrote:
>>> When endpoint controller driver is immature, the fields dma_chan_tx and
>>> dma_chan_rx of the struct pci_epf_test could be NULL even after epf
>>> initialization. However, pci_epf_test_clean_dma_chan() assumes that they
>>> are always non-NULL valid values, and causes kernel panic when the
>>> fields are NULL. To avoid the kernel panic, NULL check the fields before
>>> release.
>>>
>>> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
>>> ---
>>> drivers/pci/endpoint/functions/pci-epf-test.c | 17 +++++++++++------
>>> 1 file changed, 11 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
>>> index e091193bd8a8..1c29d5dd4382 100644
>>> --- a/drivers/pci/endpoint/functions/pci-epf-test.c
>>> +++ b/drivers/pci/endpoint/functions/pci-epf-test.c
>>> @@ -301,15 +301,20 @@ static void pci_epf_test_clean_dma_chan(struct pci_epf_test *epf_test)
>>> if (!epf_test->dma_supported)
>>> return;
>>>
>>> - dma_release_channel(epf_test->dma_chan_tx);
>>> - if (epf_test->dma_chan_tx == epf_test->dma_chan_rx) {
>>> + if (epf_test->dma_chan_tx) {
>>> + dma_release_channel(epf_test->dma_chan_tx);
>>> + if (epf_test->dma_chan_tx == epf_test->dma_chan_rx) {
>>> + epf_test->dma_chan_tx = NULL;
>>> + epf_test->dma_chan_rx = NULL;
>>> + return;
>>> + }
>>> epf_test->dma_chan_tx = NULL;
>>> - epf_test->dma_chan_rx = NULL;
>>> - return;
>>> }
>>
>> Can we simplify here ?
>
> I'm afraid, no,
>
>>
>> if (epf_test->dma_chan_tx) {
>> dma_release_channel(epf_test->dma_chan_tx);
>> epf_test->dma_chan_tx = NULL;
>
> because the line above affects the comparison below.
Arg... Of course ! Sorry about the noise.
>
>> if (epf_test->dma_chan_tx == epf_test->dma_chan_rx) {
>> epf_test->dma_chan_rx = NULL;
>> return;
>> }
>> }
>>
>>>
>>> - dma_release_channel(epf_test->dma_chan_rx);
>>> - epf_test->dma_chan_rx = NULL;
>>> + if (epf_test->dma_chan_rx) {
>>> + dma_release_channel(epf_test->dma_chan_rx);
>>> + epf_test->dma_chan_rx = NULL;
>>> + }
>>> }
>>>
>>> static void pci_epf_test_print_rate(struct pci_epf_test *epf_test,
>>
>>
>> --
>> Damien Le Moal
>> Western Digital Research
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2025-09-12 10:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-12 7:11 [PATCH] PCI: endpoint: pci-epf-test: NULL check dma channels before release Shin'ichiro Kawasaki
2025-09-12 7:31 ` Damien Le Moal
2025-09-12 9:59 ` Shinichiro Kawasaki
2025-09-12 10:38 ` Damien Le Moal [this message]
2025-09-12 10:38 ` Damien Le Moal
2025-09-12 16:58 ` Manivannan Sadhasivam
2025-09-13 5:34 ` Shinichiro Kawasaki
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=c7411e4b-83ba-45cb-8d76-37e1d0ad6ddc@kernel.org \
--to=dlemoal@kernel.org \
--cc=Frank.Li@nxp.com \
--cc=bhelgaas@google.com \
--cc=cassel@kernel.org \
--cc=kishon@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mani@kernel.org \
--cc=shinichiro.kawasaki@wdc.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