diff mbox series

[01/18] block/rnbd: fix mixed module-builtin object

Message ID 20221119225650.1044591-2-alobakin@pm.me (mailing list archive)
State Not Applicable
Headers show
Series treewide: fix object files shared between several modules | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Alexander Lobakin Nov. 19, 2022, 11:04 p.m. UTC
From: Masahiro Yamada <masahiroy@kernel.org>

With CONFIG_BLK_DEV_RNBD_CLIENT=m and CONFIG_BLK_DEV_RNBD_SERVER=y
(or vice versa), rnbd-common.o is linked to a module and also to
vmlinux even though CFLAGS are different between builtins and modules.

This is the same situation as fixed by commit 637a642f5ca5 ("zstd:
Fixing mixed module-builtin objects").

Turn rnbd_access_mode_str() into an inline function.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-and-tested-by: Alexander Lobakin <alobakin@pm.me>
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
---
 drivers/block/rnbd/Makefile      |  6 ++----
 drivers/block/rnbd/rnbd-common.c | 23 -----------------------
 drivers/block/rnbd/rnbd-proto.h  | 14 +++++++++++++-
 3 files changed, 15 insertions(+), 28 deletions(-)
 delete mode 100644 drivers/block/rnbd/rnbd-common.c

--
2.38.1

Comments

Andrew Davis Nov. 21, 2022, 9:17 p.m. UTC | #1
On 11/19/22 5:04 PM, Alexander Lobakin wrote:
> From: Masahiro Yamada <masahiroy@kernel.org>
> 
> With CONFIG_BLK_DEV_RNBD_CLIENT=m and CONFIG_BLK_DEV_RNBD_SERVER=y
> (or vice versa), rnbd-common.o is linked to a module and also to
> vmlinux even though CFLAGS are different between builtins and modules.
> 
> This is the same situation as fixed by commit 637a642f5ca5 ("zstd:
> Fixing mixed module-builtin objects").
> 
> Turn rnbd_access_mode_str() into an inline function.
> 

Why inline? All you should need is "static" to keep these internal to
each compilation unit. Inline also bloats the object files when the
function is called from multiple places. Let the compiler decide when
to inline.

Andrew

> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> Reviewed-and-tested-by: Alexander Lobakin <alobakin@pm.me>
> Signed-off-by: Alexander Lobakin <alobakin@pm.me>
> ---
>   drivers/block/rnbd/Makefile      |  6 ++----
>   drivers/block/rnbd/rnbd-common.c | 23 -----------------------
>   drivers/block/rnbd/rnbd-proto.h  | 14 +++++++++++++-
>   3 files changed, 15 insertions(+), 28 deletions(-)
>   delete mode 100644 drivers/block/rnbd/rnbd-common.c
> 
> diff --git a/drivers/block/rnbd/Makefile b/drivers/block/rnbd/Makefile
> index 40b31630822c..208e5f865497 100644
> --- a/drivers/block/rnbd/Makefile
> +++ b/drivers/block/rnbd/Makefile
> @@ -3,13 +3,11 @@
>   ccflags-y := -I$(srctree)/drivers/infiniband/ulp/rtrs
> 
>   rnbd-client-y := rnbd-clt.o \
> -		  rnbd-clt-sysfs.o \
> -		  rnbd-common.o
> +		  rnbd-clt-sysfs.o
> 
>   CFLAGS_rnbd-srv-trace.o = -I$(src)
> 
> -rnbd-server-y := rnbd-common.o \
> -		  rnbd-srv.o \
> +rnbd-server-y := rnbd-srv.o \
>   		  rnbd-srv-sysfs.o \
>   		  rnbd-srv-trace.o
> 
> diff --git a/drivers/block/rnbd/rnbd-common.c b/drivers/block/rnbd/rnbd-common.c
> deleted file mode 100644
> index 596c3f732403..000000000000
> --- a/drivers/block/rnbd/rnbd-common.c
> +++ /dev/null
> @@ -1,23 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0-or-later
> -/*
> - * RDMA Network Block Driver
> - *
> - * Copyright (c) 2014 - 2018 ProfitBricks GmbH. All rights reserved.
> - * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
> - * Copyright (c) 2019 - 2020 1&1 IONOS SE. All rights reserved.
> - */
> -#include "rnbd-proto.h"
> -
> -const char *rnbd_access_mode_str(enum rnbd_access_mode mode)
> -{
> -	switch (mode) {
> -	case RNBD_ACCESS_RO:
> -		return "ro";
> -	case RNBD_ACCESS_RW:
> -		return "rw";
> -	case RNBD_ACCESS_MIGRATION:
> -		return "migration";
> -	default:
> -		return "unknown";
> -	}
> -}
> diff --git a/drivers/block/rnbd/rnbd-proto.h b/drivers/block/rnbd/rnbd-proto.h
> index ea7ac8bca63c..1849e7039fa1 100644
> --- a/drivers/block/rnbd/rnbd-proto.h
> +++ b/drivers/block/rnbd/rnbd-proto.h
> @@ -300,6 +300,18 @@ static inline u32 rq_to_rnbd_flags(struct request *rq)
>   	return rnbd_opf;
>   }
> 
> -const char *rnbd_access_mode_str(enum rnbd_access_mode mode);
> +static inline const char *rnbd_access_mode_str(enum rnbd_access_mode mode)
> +{
> +	switch (mode) {
> +	case RNBD_ACCESS_RO:
> +		return "ro";
> +	case RNBD_ACCESS_RW:
> +		return "rw";
> +	case RNBD_ACCESS_MIGRATION:
> +		return "migration";
> +	default:
> +		return "unknown";
> +	}
> +}
> 
>   #endif /* RNBD_PROTO_H */
> --
> 2.38.1
> 
>
Masahiro Yamada Nov. 22, 2022, 5:59 a.m. UTC | #2
On Tue, Nov 22, 2022 at 6:18 AM Andrew Davis <afd@ti.com> wrote:
>
> On 11/19/22 5:04 PM, Alexander Lobakin wrote:
> > From: Masahiro Yamada <masahiroy@kernel.org>
> >
> > With CONFIG_BLK_DEV_RNBD_CLIENT=m and CONFIG_BLK_DEV_RNBD_SERVER=y
> > (or vice versa), rnbd-common.o is linked to a module and also to
> > vmlinux even though CFLAGS are different between builtins and modules.
> >
> > This is the same situation as fixed by commit 637a642f5ca5 ("zstd:
> > Fixing mixed module-builtin objects").
> >
> > Turn rnbd_access_mode_str() into an inline function.
> >
>
> Why inline? All you should need is "static" to keep these internal to
> each compilation unit. Inline also bloats the object files when the
> function is called from multiple places. Let the compiler decide when
> to inline.
>
> Andrew


Since it is a header file.


In header files, "static inline" should be always used.
Never "static".


If a header is included from a C file and there is a function
that is not used from that C file,
"static" would emit -Wunused-function warning
(-Wunused-function is enabled by -Wall, which is the case
for the kernel build).
Andrew Davis Nov. 29, 2022, 6:24 p.m. UTC | #3
On 11/21/22 11:59 PM, Masahiro Yamada wrote:
> On Tue, Nov 22, 2022 at 6:18 AM Andrew Davis <afd@ti.com> wrote:
>>
>> On 11/19/22 5:04 PM, Alexander Lobakin wrote:
>>> From: Masahiro Yamada <masahiroy@kernel.org>
>>>
>>> With CONFIG_BLK_DEV_RNBD_CLIENT=m and CONFIG_BLK_DEV_RNBD_SERVER=y
>>> (or vice versa), rnbd-common.o is linked to a module and also to
>>> vmlinux even though CFLAGS are different between builtins and modules.
>>>
>>> This is the same situation as fixed by commit 637a642f5ca5 ("zstd:
>>> Fixing mixed module-builtin objects").
>>>
>>> Turn rnbd_access_mode_str() into an inline function.
>>>
>>
>> Why inline? All you should need is "static" to keep these internal to
>> each compilation unit. Inline also bloats the object files when the
>> function is called from multiple places. Let the compiler decide when
>> to inline.
>>
>> Andrew
> 
> 
> Since it is a header file.
> 
> 
> In header files, "static inline" should be always used.
> Never "static".
> 

My comment was more "why"?

> 
> If a header is included from a C file and there is a function
> that is not used from that C file,
> "static" would emit -Wunused-function warning
> (-Wunused-function is enabled by -Wall, which is the case
> for the kernel build).
> 
> 

Inline still hints to the compiler to inline, causing unneeded
object size bloat. Using "inline" to signal something else (that
the function may be unused) when we already have a flag for that
(__maybe_unused) feels wrong.

Seems this was already debated way back in 2006.. So maybe not
worth revisiting today, but still a cleanup that could be good
to think more about later.

Andrew
diff mbox series

Patch

diff --git a/drivers/block/rnbd/Makefile b/drivers/block/rnbd/Makefile
index 40b31630822c..208e5f865497 100644
--- a/drivers/block/rnbd/Makefile
+++ b/drivers/block/rnbd/Makefile
@@ -3,13 +3,11 @@ 
 ccflags-y := -I$(srctree)/drivers/infiniband/ulp/rtrs

 rnbd-client-y := rnbd-clt.o \
-		  rnbd-clt-sysfs.o \
-		  rnbd-common.o
+		  rnbd-clt-sysfs.o

 CFLAGS_rnbd-srv-trace.o = -I$(src)

-rnbd-server-y := rnbd-common.o \
-		  rnbd-srv.o \
+rnbd-server-y := rnbd-srv.o \
 		  rnbd-srv-sysfs.o \
 		  rnbd-srv-trace.o

diff --git a/drivers/block/rnbd/rnbd-common.c b/drivers/block/rnbd/rnbd-common.c
deleted file mode 100644
index 596c3f732403..000000000000
--- a/drivers/block/rnbd/rnbd-common.c
+++ /dev/null
@@ -1,23 +0,0 @@ 
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * RDMA Network Block Driver
- *
- * Copyright (c) 2014 - 2018 ProfitBricks GmbH. All rights reserved.
- * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
- * Copyright (c) 2019 - 2020 1&1 IONOS SE. All rights reserved.
- */
-#include "rnbd-proto.h"
-
-const char *rnbd_access_mode_str(enum rnbd_access_mode mode)
-{
-	switch (mode) {
-	case RNBD_ACCESS_RO:
-		return "ro";
-	case RNBD_ACCESS_RW:
-		return "rw";
-	case RNBD_ACCESS_MIGRATION:
-		return "migration";
-	default:
-		return "unknown";
-	}
-}
diff --git a/drivers/block/rnbd/rnbd-proto.h b/drivers/block/rnbd/rnbd-proto.h
index ea7ac8bca63c..1849e7039fa1 100644
--- a/drivers/block/rnbd/rnbd-proto.h
+++ b/drivers/block/rnbd/rnbd-proto.h
@@ -300,6 +300,18 @@  static inline u32 rq_to_rnbd_flags(struct request *rq)
 	return rnbd_opf;
 }

-const char *rnbd_access_mode_str(enum rnbd_access_mode mode);
+static inline const char *rnbd_access_mode_str(enum rnbd_access_mode mode)
+{
+	switch (mode) {
+	case RNBD_ACCESS_RO:
+		return "ro";
+	case RNBD_ACCESS_RW:
+		return "rw";
+	case RNBD_ACCESS_MIGRATION:
+		return "migration";
+	default:
+		return "unknown";
+	}
+}

 #endif /* RNBD_PROTO_H */