I've written a Linux device driver for a PCI device. This device performs DMA operations. An issue arise when the program crashes when a DMA operation is running.
Indeed, when crashing, the device_remove()
function is called by the system (as if close()
were called). This function does the cleanup on the memory regions used by the PCI device, frees the allocated memory correctly. I mean it works correctly under normal circumstances.
But if a DMA is running, when it will actually terminate, it won't be able to perform the DMA cleanup because it does not have access anymore to the device data that have been freed. A simple solution would be to wait in the close() function. (This is my understanding, but maybe the last part of the DMA function is never executed?)
Is it a good idea to wail for the DMA to actually terminate in the device_remove()
(aka close()
) function of a device driver? Are there other means to deal with this issue?