ceph: fix clang warning for CEPH_DEFINE_OID_ONSTACK
PATCH v2 1/1 ceph: fix clang warning for CEPH_DEFINE_OID_ONSTACK
clang complains about assigning a variable to itself during the declaration:
fs/ceph/ioctl.c:187:26: error: variable 'oid' is uninitialized when used within its own initialization [-Werror,-Wuninitialized]
CEPH_DEFINE_OID_ONSTACK(oid);
^~~include/linux/ceph/osdmap.h:122:52: note: expanded from macro 'CEPH_DEFINE_OID_ONSTACK'
struct ceph_object_id oid = CEPH_OID_INIT_ONSTACK(oid)
~~~ ^~~include/linux/ceph/osdmap.h:120:29: note: expanded from macro 'CEPH_OID_INIT_ONSTACK'
({ ceph_oid_init(&oid); oid; })
^~~We use this trick in other places, but it is completely unnecessary here, as we can just use a regular struct initializer.
---
v2: rearrange to only have one instance of the initializer
--- include/linux/ceph/osdmap.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
include/linux/ceph/osdmap.h +6 -7
@@ -110,17 +110,16 @@ struct ceph_object_id {int name_len; }; +#define CEPH_OID_INITIALIZER (oid) { .name = (oid).inline_name } + +#define CEPH_DEFINE_OID_ONSTACK (oid) \ + struct ceph_object_id oid = CEPH_OID_INITIALIZER(oid) +static inline void ceph_oid_init (struct ceph_object_id *oid) { - oid->name = oid->inline_name; - oid->name_len =0 ; + *oid = (struct ceph_object_id )CEPH_OID_INITIALIZER (*oid); } -#define CEPH_OID_INIT_ONSTACK (oid) \ - ({ ceph_oid_init(&oid); oid; }) -#define CEPH_DEFINE_OID_ONSTACK (oid) \ - struct ceph_object_id oid = CEPH_OID_INIT_ONSTACK(oid) -static inline bool ceph_oid_empty (const struct ceph_object_id *oid) {return oid->name == oid->inline_name && !oid->name_len;
Signature · 1 line
2.20.0
Quoted 42 lines · Arnd Bergmann
clang complains about assigning a variable to itself during the declaration:
fs/ceph/ioctl.c:187:26: error: variable 'oid' is uninitialized when used within its own initialization [-Werror,-Wuninitialized]CEPH_DEFINE_OID_ONSTACK(oid); ^~~
include/linux/ceph/osdmap.h:122:52: note: expanded from macro 'CEPH_DEFINE_OID_ONSTACK'
structceph_object_idoid =CEPH_OID_INIT_ONSTACK(oid)
~~~ ^~~include/linux/ceph/osdmap.h:120:29: note: expanded from macro 'CEPH_OID_INIT_ONSTACK'({ ceph_oid_init(&oid); oid; }) ^~~We use this trick in other places, but it is completely unnecessary here, as we can just use a regular struct initializer.
Signed-off-by Arnd Bergmann <[email protected]>---
v2: rearrange to only have one instance of the initializer--- include/linux/ceph/osdmap.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)include/linux/ceph/osdmap.h +6
-2@@ -110,17 +110,16 @@ struct ceph_object_id {int name_len; }; +#define CEPH_OID_INITIALIZER (oid) { .name = (oid).inline_name } + +#define CEPH_DEFINE_OID_ONSTACK (oid) \ + struct ceph_object_id oid = CEPH_OID_INITIALIZER(oid) +static inline void ceph_oid_init (struct ceph_object_id *oid) { - oid->name = oid->inline_name; - oid->name_len =0 ; + *oid = (struct ceph_object_id )CEPH_OID_INITIALIZER (*oid);
include/linux/ceph/osdmap.h struct ceph_object_id { · line 125
Quoted 10 lines
include/linux/ceph/osdmap.h +0
-5} -#define CEPH_OID_INIT_ONSTACK (oid) \ - ({ ceph_oid_init(&oid); oid; }) -#define CEPH_DEFINE_OID_ONSTACK (oid) \ - struct ceph_object_id oid = CEPH_OID_INIT_ONSTACK(oid) -static inline bool ceph_oid_empty (const struct ceph_object_id *oid) {return oid->name == oid->inline_name && !oid->name_len;
Applied.
Thanks,
Ilya