diff mbox series

[v4,01/21] nvmem: Mark nvmem_type_str array with __maybe_unused

Message ID 20181128190537.14074-2-andriy.shevchenko@linux.intel.com
State Superseded
Headers show
Series lib, rtc: Print rtc_time via %ptR[dt][r] | expand

Commit Message

Andy Shevchenko Nov. 28, 2018, 7:05 p.m. UTC
Since we put static variable to a header file it's copied to each module
that includes the header. But not all of them are actually using it.

Mark nvmem_type_str array with __maybe_unused to make a compiler happy:

In file included from include/linux/rtc.h:18,
                 from drivers/rtc/rtc-proc.c:15:
include/linux/nvmem-provider.h:29:27: warning: ‘nvmem_type_str’ defined but not used [-Wunused-const-variable=]
 static const char * const nvmem_type_str[] = {
                           ^~~~~~~~~~~~~~

Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/nvmem-provider.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alexandre Belloni Nov. 28, 2018, 9:05 p.m. UTC | #1
On 28/11/2018 21:05:17+0200, Andy Shevchenko wrote:
> Since we put static variable to a header file it's copied to each module
> that includes the header. But not all of them are actually using it.
> 
> Mark nvmem_type_str array with __maybe_unused to make a compiler happy:
> 
> In file included from include/linux/rtc.h:18,
>                  from drivers/rtc/rtc-proc.c:15:
> include/linux/nvmem-provider.h:29:27: warning: ‘nvmem_type_str’ defined but not used [-Wunused-const-variable=]
>  static const char * const nvmem_type_str[] = {
>                            ^~~~~~~~~~~~~~
> 
> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  include/linux/nvmem-provider.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
> index 00ff92571683..e33919ddb026 100644
> --- a/include/linux/nvmem-provider.h
> +++ b/include/linux/nvmem-provider.h
> @@ -26,7 +26,7 @@ enum nvmem_type {
>  	NVMEM_TYPE_BATTERY_BACKED,
>  };
>  
> -static const char * const nvmem_type_str[] = {
> +static const __maybe_unused char * const nvmem_type_str[] = {

Hum, it is probably better to move the array to nvmem/core.c. I should
have done that from the beginning.

>  	[NVMEM_TYPE_UNKNOWN] = "Unknown",
>  	[NVMEM_TYPE_EEPROM] = "EEPROM",
>  	[NVMEM_TYPE_OTP] = "OTP",
> -- 
> 2.19.2
>
Joe Perches Nov. 29, 2018, 12:10 a.m. UTC | #2
On Wed, 2018-11-28 at 21:05 +0200, Andy Shevchenko wrote:
> Since we put static variable to a header file it's copied to each module
> that includes the header. But not all of them are actually using it.
> 
> Mark nvmem_type_str array with __maybe_unused to make a compiler happy:
> 
> In file included from include/linux/rtc.h:18,
>                  from drivers/rtc/rtc-proc.c:15:
> include/linux/nvmem-provider.h:29:27: warning: ‘nvmem_type_str’ defined but not used [-Wunused-const-variable=]
>  static const char * const nvmem_type_str[] = {

It would be better to move this definition into
the one file that seems to use it.

$ git grep -w nvmem_type_str
drivers/nvmem/core.c:   return sprintf(buf, "%s\n", nvmem_type_str[nvmem->type])
include/linux/nvmem-provider.h:static const char * const nvmem_type_str[] = {
diff mbox series

Patch

diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index 00ff92571683..e33919ddb026 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -26,7 +26,7 @@  enum nvmem_type {
 	NVMEM_TYPE_BATTERY_BACKED,
 };
 
-static const char * const nvmem_type_str[] = {
+static const __maybe_unused char * const nvmem_type_str[] = {
 	[NVMEM_TYPE_UNKNOWN] = "Unknown",
 	[NVMEM_TYPE_EEPROM] = "EEPROM",
 	[NVMEM_TYPE_OTP] = "OTP",