All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ceph: fix clang warning for CEPH_DEFINE_OID_ONSTACK
@ 2019-03-22 14:08 Arnd Bergmann
  2019-03-22 14:41 ` Ilya Dryomov
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2019-03-22 14:08 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>
---
 include/linux/ceph/osdmap.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/linux/ceph/osdmap.h b/include/linux/ceph/osdmap.h
index 5675b1f09bc5..82f957a7a0d6 100644
--- a/include/linux/ceph/osdmap.h
+++ b/include/linux/ceph/osdmap.h
@@ -116,10 +116,8 @@ static inline void ceph_oid_init(struct ceph_object_id *oid)
 	oid->name_len = 0;
 }
 
-#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)
+	struct ceph_object_id oid = { .name = oid.inline_name }
 
 static inline bool ceph_oid_empty(const struct ceph_object_id *oid)
 {
-- 
2.20.0


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

* Re: [PATCH] ceph: fix clang warning for CEPH_DEFINE_OID_ONSTACK
  2019-03-22 14:08 [PATCH] ceph: fix clang warning for CEPH_DEFINE_OID_ONSTACK Arnd Bergmann
@ 2019-03-22 14:41 ` Ilya Dryomov
  2019-03-22 15:07   ` Arnd Bergmann
  0 siblings, 1 reply; 3+ messages in thread
From: Ilya Dryomov @ 2019-03-22 14:41 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Yan, Zheng, Sage Weil, clang-built-linux, Nick Desaulniers,
	Nathan Chancellor, Alex Elder, Ceph Development, LKML

On Fri, Mar 22, 2019 at 3:08 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>
> ---
>  include/linux/ceph/osdmap.h | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/include/linux/ceph/osdmap.h b/include/linux/ceph/osdmap.h
> index 5675b1f09bc5..82f957a7a0d6 100644
> --- a/include/linux/ceph/osdmap.h
> +++ b/include/linux/ceph/osdmap.h
> @@ -116,10 +116,8 @@ static inline void ceph_oid_init(struct ceph_object_id *oid)
>         oid->name_len = 0;
>  }
>
> -#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)
> +       struct ceph_object_id oid = { .name = oid.inline_name }
>
>  static inline bool ceph_oid_empty(const struct ceph_object_id *oid)
>  {

Hi Arnd,

I don't like this because the initialization is no longer contained to
ceph_oid_init().  Now there are two things to patch instead of one.

How is this going to be fixed in other places?

Thanks,

                Ilya

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

* Re: [PATCH] ceph: fix clang warning for CEPH_DEFINE_OID_ONSTACK
  2019-03-22 14:41 ` Ilya Dryomov
@ 2019-03-22 15:07   ` Arnd Bergmann
  0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-03-22 15:07 UTC (permalink / raw)
  To: Ilya Dryomov
  Cc: Yan, Zheng, Sage Weil, clang-built-linux, Nick Desaulniers,
	Nathan Chancellor, Alex Elder, Ceph Development, LKML

On Fri, Mar 22, 2019 at 3:40 PM Ilya Dryomov <idryomov@gmail.com> wrote:
>
> On Fri, Mar 22, 2019 at 3:08 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> Hi Arnd,
>
> I don't like this because the initialization is no longer contained to
> ceph_oid_init().  Now there are two things to patch instead of one.
>
> How is this going to be fixed in other places?

The only other warning like this that I encountered was in
DECLARE_WAIT_QUEUE_HEAD_ONSTACK().

So far, I have no idea for how to solve it, other than disabling
CONFIG_LOCKDEP when clang is used.

Would you prefer this version?

#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 = (struct ceph_object_id)CEPH_OID_INITIALIZER(*oid);
}




       Arnd

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

end of thread, other threads:[~2019-03-22 15:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-22 14:08 [PATCH] ceph: fix clang warning for CEPH_DEFINE_OID_ONSTACK Arnd Bergmann
2019-03-22 14:41 ` Ilya Dryomov
2019-03-22 15:07   ` Arnd Bergmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.