[PATCH 21/25] libxfs: remove dangerous casting between cache_node and xfs_buf

Darrick J. Wong
2020-02-25T00:13:48Z

Get rid of all the dangerous casting between cache_node and xfs_buf
since we can use container_of now.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
libxfs/rdwr.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 09a2a716..29c9dd68 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -294,8 +294,9 @@ libxfs_bhash(cache_key_t key, unsigned int hashsize, unsigned int hashshift)
static int
libxfs_bcompare(struct cache_node *node, cache_key_t key)
{
- struct xfs_buf *bp = (struct xfs_buf *)node;
- struct xfs_bufkey *bkey = (struct xfs_bufkey *)key;
+ struct xfs_buf *bp = container_of(node, struct xfs_buf,
+ b_node);
+ struct xfs_bufkey *bkey = (struct xfs_bufkey *)key;

if (bp->b_target->dev == bkey->buftarg->dev &&
bp->b_bn == bkey->blkno) {
@@ -1045,7 +1046,8 @@ static void
libxfs_brelse(
struct cache_node *node)
{
- struct xfs_buf *bp = (struct xfs_buf *)node;
+ struct xfs_buf *bp = container_of(node, struct xfs_buf,
+ b_node);

if (!bp)
return;
@@ -1110,7 +1112,8 @@ static int
libxfs_bflush(
struct cache_node *node)
{
- struct xfs_buf *bp = (struct xfs_buf *)node;
+ struct xfs_buf *bp = container_of(node, struct xfs_buf,
+ b_node);

if (!bp->b_error && bp->b_flags & LIBXFS_B_DIRTY)
return libxfs_bwrite(bp);