This fixes a long standing issue, where the kernel does flushing of file streams, although it should not handle such streams at all.
For CONFIG_BUILD_KERNEL using the sched/task/task_exithook implementation will just not work. It calls user code with kernel privileges which is a bit of a security issue.