Re: [PATCH] Use of getblk differs between locations

From: Mikulas Patocka
Date: Mon Oct 10 2005 - 16:59:15 EST

On Mon, 10 Oct 2005, Glauber de Oliveira Costa wrote:

On Mon, Oct 10, 2005 at 10:20:07PM +0100, Anton Altaparmakov wrote:

On Mon, 10 Oct 2005, Glauber de Oliveira Costa wrote:
I've just noticed that the use of sb_getblk differs between locations
inside the kernel. To be precise, in some locations there are tests
against its return value, and in some places there are not.

According to the comments in __getblk definition, the tests are not
necessary, as the function always return a buffer_head (maybe a wrong

If you had read the source code rather than just the comments you would
have seen that this is not true. It can return NULL (see
fs/buffer.c::__getblk_slow()). Certainly I would prefer to keep the
checks in NTFS, please. They may only be good for catching bugs but I
like catching bugs rather than segfaulting due to a NULL dereference.

The check should be rather a BUG() than dump_stack() and return NULL --- I think it's not right to write code to recover from programming errors. Filesystem drivers are supposed to pass correct blocksize to getblk(). --- even for users it's better to crash, because user whose machine has locked up on BUG() will report bug more likely than user whose machine has written stack dump into log and corrupted filesystem --- by the time he discovers the corruption and mesage he might not even remember what triggered it.

As comment in buffer.c says, getblk will deadlock if the machine is out of memory. It is questionable whether to deadlock or return NULL and corrupt filesystem in this case --- deadlock is probably better.


I did. But I did not see this specifically, for sure. What takes us to
the opposite problem: A lot of places do not check for the return value
of getblk (Almost half of them, I'd say), and may thus lead to a
dereferencing of a NULL pointer.

Does anyone else have any comments on that?

Best regards,

Anton Altaparmakov <aia21 at> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on
WWW: &

Glauber de Oliveira Costa
IBM Linux Technology Center - Brazil

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at