Device driver .shutdown() VS .remove()

Luca Ceresoli luca at
Thu Apr 22 03:36:43 EDT 2021


despite having been searching for documentation I couldn't find out the
exact and detailed difference between the .shutdown() and .remove()
calls in struct device_driver.

My best understanding follows. Any amendment or clarification would be
appreciated, and why not it might end up in improving the docs.

The different intent is kind of clear: remove() is called when the
device is disconnected or otherwise removed from the system, and also
when the driver is removed (which can only happen by unloading a kernel
module, I think). shutdown() is called during reboot and shutdown.

remove() is _not_ called during shutdown and reboot.
shutdown() is not called on device or driver removal.

Things get more blurred when trying to understand what each of the two
should do.

Definitely both must stop the device from producing any events to the
rest of the system: stop DMAs, stop anything that would trigger
interrupts etc.

remove() should also "turn off" the device, but it's probably a good
idea to do in shutdown() as well in order to not leave peripherals
unnecessarily powered while rebooting.

remove() must definitely free any allocated resources, which would be
useless in shutdown().

>From the above it looks like the shutdown() actions must be a subset of
remove() actions.

How much of my understanding is correct?


More information about the Kernelnewbies mailing list