diff mbox

[U-Boot] pinctrl: uniphier: fix unused-const-variable warnings for GCC 6.x

Message ID 1476024777-5113-1-git-send-email-yamada.masahiro@socionext.com
State Accepted
Commit 935e09cdcb6d6dfa41f4cd8c8a69da52ef6850ed
Delegated to: Masahiro Yamada
Headers show

Commit Message

Masahiro Yamada Oct. 9, 2016, 2:52 p.m. UTC
Marek reports warnings in UniPhier pinctrl drivers when compiled by
GCC 6.x, like:

  drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c:58:18: warning:
  'usb3_muxvals' defined but not used [-Wunused-const-variable=]
   static const int usb3_muxvals[] = {0, 0};
                    ^~~~~~~~~~~~

My intention here is to compile minimum set of pin data for SPL to
save memory footprint, but GCC these days is clever enough to notice
unused data arrays.

We can fix it by sprinkling around __maybe_unused on those arrays,
but I did not do that because they are counterparts of the pinctrl
drivers in Linux.  All the pin data were just copy-pasted from Linux
and are kept in sync for maintainability.

I chose a bit tricky way to fix the issue; calculate ARRAY_SIZE of
*_pins and *_muxvals and set their sum to an unused struct member.
This trick will satisfy GCC because the data arrays are used anyway,
but such data arrays will be dropped from the final binary because
the pointers to them are not used.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reported-by: Marek Vasut <marex@denx.de>
---

 drivers/pinctrl/uniphier/pinctrl-uniphier.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Masahiro Yamada Oct. 18, 2016, 3:38 p.m. UTC | #1
2016-10-09 23:52 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
> Marek reports warnings in UniPhier pinctrl drivers when compiled by
> GCC 6.x, like:
>
>   drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c:58:18: warning:
>   'usb3_muxvals' defined but not used [-Wunused-const-variable=]
>    static const int usb3_muxvals[] = {0, 0};
>                     ^~~~~~~~~~~~
>
> My intention here is to compile minimum set of pin data for SPL to
> save memory footprint, but GCC these days is clever enough to notice
> unused data arrays.
>
> We can fix it by sprinkling around __maybe_unused on those arrays,
> but I did not do that because they are counterparts of the pinctrl
> drivers in Linux.  All the pin data were just copy-pasted from Linux
> and are kept in sync for maintainability.
>
> I chose a bit tricky way to fix the issue; calculate ARRAY_SIZE of
> *_pins and *_muxvals and set their sum to an unused struct member.
> This trick will satisfy GCC because the data arrays are used anyway,
> but such data arrays will be dropped from the final binary because
> the pointers to them are not used.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Reported-by: Marek Vasut <marex@denx.de>


Applied to u-boot-uniphier/master.
Marek Vasut Oct. 18, 2016, 3:41 p.m. UTC | #2
On 10/18/2016 05:38 PM, Masahiro Yamada wrote:
> 2016-10-09 23:52 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
>> Marek reports warnings in UniPhier pinctrl drivers when compiled by
>> GCC 6.x, like:
>>
>>   drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c:58:18: warning:
>>   'usb3_muxvals' defined but not used [-Wunused-const-variable=]
>>    static const int usb3_muxvals[] = {0, 0};
>>                     ^~~~~~~~~~~~
>>
>> My intention here is to compile minimum set of pin data for SPL to
>> save memory footprint, but GCC these days is clever enough to notice
>> unused data arrays.
>>
>> We can fix it by sprinkling around __maybe_unused on those arrays,
>> but I did not do that because they are counterparts of the pinctrl
>> drivers in Linux.  All the pin data were just copy-pasted from Linux
>> and are kept in sync for maintainability.
>>
>> I chose a bit tricky way to fix the issue; calculate ARRAY_SIZE of
>> *_pins and *_muxvals and set their sum to an unused struct member.
>> This trick will satisfy GCC because the data arrays are used anyway,
>> but such data arrays will be dropped from the final binary because
>> the pointers to them are not used.
>>
>> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
>> Reported-by: Marek Vasut <marex@denx.de>
> 
> 
> Applied to u-boot-uniphier/master.
> 
Thanks!
diff mbox

Patch

diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier.h b/drivers/pinctrl/uniphier/pinctrl-uniphier.h
index 5c3db2a..21e2d37 100644
--- a/drivers/pinctrl/uniphier/pinctrl-uniphier.h
+++ b/drivers/pinctrl/uniphier/pinctrl-uniphier.h
@@ -91,7 +91,12 @@  struct uniphier_pinctrl_socdata {
 #define __UNIPHIER_PINMUX_FUNCTION(func)	#func
 
 #ifdef CONFIG_SPL_BUILD
-#define UNIPHIER_PINCTRL_GROUP(grp)		{ .name = NULL }
+	/*
+	 * a tricky way to drop unneeded *_pins and *_muxvals arrays from SPL,
+	 * suppressing "defined but not used" warnings.
+	 */
+#define UNIPHIER_PINCTRL_GROUP(grp)					\
+	{ .num_pins = ARRAY_SIZE(grp##_pins) + ARRAY_SIZE(grp##_muxvals) }
 #define UNIPHIER_PINMUX_FUNCTION(func)		NULL
 #else
 #define UNIPHIER_PINCTRL_GROUP(grp)		__UNIPHIER_PINCTRL_GROUP(grp)