diff --git a/base/memory/container_of.h b/base/memory/container_of.h index 4e4c662bf..ddb795935 100644 --- a/base/memory/container_of.h +++ b/base/memory/container_of.h @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Red Hat, Inc. All rights reserved. +// Copyright (C) 2018 - 2020 Red Hat, Inc. All rights reserved. // // This file is part of LVM2. // @@ -13,10 +13,12 @@ #ifndef BASE_MEMORY_CONTAINER_OF_H #define BASE_MEMORY_CONTAINER_OF_H +#include // offsetof + //---------------------------------------------------------------- #define container_of(v, t, head) \ - ((t *)((const char *)(v) - (const char *)&((t *) 0)->head)) + ((t *)((const char *)(v) - offsetof(t, head))) //---------------------------------------------------------------- diff --git a/lib/device/bcache.h b/lib/device/bcache.h index 4ef044c74..2950afa69 100644 --- a/lib/device/bcache.h +++ b/lib/device/bcache.h @@ -16,19 +16,12 @@ #define BCACHE_H #include "device_mapper/all.h" +#include "base/memory/container_of.h" #include #include #include -/*----------------------------------------------------------------*/ - -// FIXME: move somewhere more sensible -#define container_of(v, t, head) \ - ((t *)((const char *)(v) - (const char *)&((t *) 0)->head)) - -/*----------------------------------------------------------------*/ - enum dir { DIR_READ, DIR_WRITE