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@xxxxxxx> >>> --- >>> 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