linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [v2] ceph: fix clang warning for CEPH_DEFINE_OID_ONSTACK
@ 2019-03-25 12:51 Arnd Bergmann
  2019-03-27 16:33 ` Ilya Dryomov
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2019-03-25 12:51 UTC (permalink / raw)
  To: Ilya Dryomov, Yan, Zheng, Sage Weil
  Cc: clang-built-linux, Nick Desaulniers, Nathan Chancellor,
	Arnd Bergmann, Alex Elder, ceph-devel, linux-kernel

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v2: rearrange to only have one instance of the initializer
---
 include/linux/ceph/osdmap.h | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/include/linux/ceph/osdmap.h b/include/linux/ceph/osdmap.h
index 5675b1f09bc5..8794cf0f0b39 100644
--- a/include/linux/ceph/osdmap.h
+++ b/include/linux/ceph/osdmap.h
@@ -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;
-- 
2.20.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] [v2] ceph: fix clang warning for CEPH_DEFINE_OID_ONSTACK
  2019-03-25 12:51 [PATCH] [v2] ceph: fix clang warning for CEPH_DEFINE_OID_ONSTACK Arnd Bergmann
@ 2019-03-27 16:33 ` Ilya Dryomov
  0 siblings, 0 replies; 2+ messages in thread
From: Ilya Dryomov @ 2019-03-27 16:33 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Yan, Zheng, Sage Weil, clang-built-linux, Nick Desaulniers,
	Nathan Chancellor, Alex Elder, Ceph Development, LKML

On Mon, Mar 25, 2019 at 1:51 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> 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.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> v2: rearrange to only have one instance of the initializer
> ---
>  include/linux/ceph/osdmap.h | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/include/linux/ceph/osdmap.h b/include/linux/ceph/osdmap.h
> index 5675b1f09bc5..8794cf0f0b39 100644
> --- a/include/linux/ceph/osdmap.h
> +++ b/include/linux/ceph/osdmap.h
> @@ -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;

Applied.

Thanks,

                Ilya

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-03-27 16:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-25 12:51 [PATCH] [v2] ceph: fix clang warning for CEPH_DEFINE_OID_ONSTACK Arnd Bergmann
2019-03-27 16:33 ` Ilya Dryomov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).