iomap: fix a use after free in iomap_dio_rw

Introduce a local wait_for_completion variable to avoid an access to the
potentially freed dio struture after dropping the last reference count.

Also use the chance to document the completion behavior to make the
refcounting clear to the reader of the code.

Fixes: ff6a9292e6 ("iomap: implement direct I/O")
Reported-by: Chandan Rajendra <>
Reported-by: Darrick J. Wong <>
Signed-off-by: Christoph Hellwig <>
Tested-by: Chandan Rajendra <>
Tested-by: Darrick J. Wong <>
Reviewed-by: Dave Chinner <>
Reviewed-by: Darrick J. Wong <>
Signed-off-by: Darrick J. Wong <>
1 file changed