]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
The bread() function was inconsistent about whether it would return
authorKirk McKusick <mckusick@FreeBSD.org>
Wed, 27 Jan 2016 21:23:01 +0000 (21:23 +0000)
committerKirk McKusick <mckusick@FreeBSD.org>
Wed, 27 Jan 2016 21:23:01 +0000 (21:23 +0000)
commitd2a28cb08088a0b837d4ba4eb5896cb96e42c295
treef2447333b6b707e0c4a1f5b56e89972d313c010e
parent2b198fe92f4aebe14640c7c1256bb222d5fdbb2d
The bread() function was inconsistent about whether it would return
a buffer pointer in the event of an error (for some errors it would
return a buffer pointer and for other errors it would not return a
buffer pointer). The cluster_read() function was similarly inconsistent.

Clients of these functions were inconsistent in handling errors.
Some would assume that no buffer was returned after an error and
would thus lose buffers under certain error conditions. Others would
assume that brelse() should always be called after an error and
would thus panic the system under certain error conditions.

To correct both of these problems with minimal code churn, bread()
and cluster_write() now always free the buffer when returning an
error thus ensuring that buffers will never be lost. The brelse()
routine checks for being passed a NULL buffer pointer and silently
returns to avoid panics. Thus both approaches to handling error
returns from bread() and cluster_read() will work correctly.

Future code should be written assuming that bread() and cluster_read()
will never return a buffer with an error, so should not attempt to
brelse() the buffer when an error is returned.

Reviewed by: kib
sys/kern/vfs_bio.c
sys/kern/vfs_cluster.c
sys/ufs/ffs/ffs_inode.c