2022-10-12 06:42:42

by kernel test robot

[permalink] [raw]
Subject: drivers/ata/ahci_st.c:229:34: warning: unused variable 'st_ahci_match'

Hi Damien,

First bad commit (maybe != root cause):

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 49da070062390094112b423ba443ea193527b2e4
commit: ecf8322f464d62759d838ea62cdeff6966a60134 ata: ahci_st: Enable compile test
date: 3 weeks ago
config: mips-randconfig-r023-20221012
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install mips cross compiling tool for clang build
# apt-get install binutils-mipsel-linux-gnu
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ecf8322f464d62759d838ea62cdeff6966a60134
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout ecf8322f464d62759d838ea62cdeff6966a60134
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=mips SHELL=/bin/bash drivers/ata/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> drivers/ata/ahci_st.c:229:34: warning: unused variable 'st_ahci_match' [-Wunused-const-variable]
static const struct of_device_id st_ahci_match[] = {
^
1 warning generated.


vim +/st_ahci_match +229 drivers/ata/ahci_st.c

76884cb2f7da52 Lee Jones 2014-02-26 228
09de99db23df55 Kiran Padwal 2014-07-22 @229 static const struct of_device_id st_ahci_match[] = {
76884cb2f7da52 Lee Jones 2014-02-26 230 { .compatible = "st,ahci", },
5e776d7b20f040 Geert Uytterhoeven 2022-03-03 231 { /* sentinel */ }
76884cb2f7da52 Lee Jones 2014-02-26 232 };
76884cb2f7da52 Lee Jones 2014-02-26 233 MODULE_DEVICE_TABLE(of, st_ahci_match);
76884cb2f7da52 Lee Jones 2014-02-26 234

:::::: The code at line 229 was first introduced by commit
:::::: 09de99db23df55c7415d110f6c62281dedd77384 ahci: st: Make of_device_id array const

:::::: TO: Kiran Padwal <[email protected]>
:::::: CC: Tejun Heo <[email protected]>

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (2.47 kB)
config (158.72 kB)
Download all attachments

2022-10-13 06:26:41

by Damien Le Moal

[permalink] [raw]
Subject: Re: drivers/ata/ahci_st.c:229:34: warning: unused variable 'st_ahci_match'

On 10/12/22 15:37, kernel test robot wrote:
> Hi Damien,
>
> First bad commit (maybe != root cause):
>
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: 49da070062390094112b423ba443ea193527b2e4
> commit: ecf8322f464d62759d838ea62cdeff6966a60134 ata: ahci_st: Enable compile test
> date: 3 weeks ago
> config: mips-randconfig-r023-20221012
> compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920)
> reproduce (this is a W=1 build):
> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> # install mips cross compiling tool for clang build
> # apt-get install binutils-mipsel-linux-gnu
> # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ecf8322f464d62759d838ea62cdeff6966a60134
> git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> git fetch --no-tags linus master
> git checkout ecf8322f464d62759d838ea62cdeff6966a60134
> # save the config file
> mkdir build_dir && cp config build_dir/.config
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=mips SHELL=/bin/bash drivers/ata/
>
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <[email protected]>
>
> All warnings (new ones prefixed by >>):
>
>>> drivers/ata/ahci_st.c:229:34: warning: unused variable 'st_ahci_match' [-Wunused-const-variable]
> static const struct of_device_id st_ahci_match[] = {
> ^
> 1 warning generated.
>
>
> vim +/st_ahci_match +229 drivers/ata/ahci_st.c
>
> 76884cb2f7da52 Lee Jones 2014-02-26 228
> 09de99db23df55 Kiran Padwal 2014-07-22 @229 static const struct of_device_id st_ahci_match[] = {
> 76884cb2f7da52 Lee Jones 2014-02-26 230 { .compatible = "st,ahci", },
> 5e776d7b20f040 Geert Uytterhoeven 2022-03-03 231 { /* sentinel */ }
> 76884cb2f7da52 Lee Jones 2014-02-26 232 };
> 76884cb2f7da52 Lee Jones 2014-02-26 233 MODULE_DEVICE_TABLE(of, st_ahci_match);
> 76884cb2f7da52 Lee Jones 2014-02-26 234
>
> :::::: The code at line 229 was first introduced by commit
> :::::: 09de99db23df55c7415d110f6c62281dedd77384 ahci: st: Make of_device_id array const
>
> :::::: TO: Kiran Padwal <[email protected]>
> :::::: CC: Tejun Heo <[email protected]>

I am at a loss with this one... There are plenty of patterns similar to
drivers/ata/ahci_st.c doing something like:

static const struct of_device_id st_ahci_match[] = {

{ .compatible = "st,ahci", },

{ /* sentinel */ }

};

MODULE_DEVICE_TABLE(of, st_ahci_match);

For instance, in drivers/pwm/pwm-sti.c, we have:

static const struct of_device_id sti_pwm_of_match[] = {

{ .compatible = "st,sti-pwm", },

{ /* sentinel */ }

};

MODULE_DEVICE_TABLE(of, sti_pwm_of_match);

And countless others like this for STI and other arch too.

So if CONFIG_MODULE is not enabled, how come we are not submerged with
warnings about unused variables ? Is mips arch special in this regard ?
Or am I missing something ?

--
Damien Le Moal
Western Digital Research

2022-10-13 07:43:55

by Arnd Bergmann

[permalink] [raw]
Subject: Re: drivers/ata/ahci_st.c:229:34: warning: unused variable 'st_ahci_match'

On Thu, Oct 13, 2022, at 8:13 AM, Damien Le Moal wrote:
> On 10/12/22 15:37, kernel test robot wrote:

> I am at a loss with this one... There are plenty of patterns similar to
> drivers/ata/ahci_st.c doing something like:
>
> static const struct of_device_id st_ahci_match[] = {
>
> { .compatible = "st,ahci", },
>
> { /* sentinel */ }
>
> };
>
> MODULE_DEVICE_TABLE(of, st_ahci_match);
>
> For instance, in drivers/pwm/pwm-sti.c, we have:
>
>
> And countless others like this for STI and other arch too.
>
> So if CONFIG_MODULE is not enabled, how come we are not submerged with
> warnings about unused variables ? Is mips arch special in this regard ?
> Or am I missing something ?

It has nothing to do with MIPS, the problem is

.of_match_table = of_match_ptr(st_ahci_match),

The 'of_match_ptr()' sets the pointer to NULL when CONFIG_OF is
disabled, which avoids a build failure when st_ahci_match[]
itself is in an #ifdef.

In this driver, there is no #ifdef around st_ahci_match[], so we
simply want

.of_match_table = st_ahci_match,

The thing with the MODULE_DEVICE_TABLE() is that it would
create another reference if CONFIG_MODULE is enabled, but not
for a built-in driver, so you only get this type of warning
for randconfig builds that have the driver built-in and OF
disabled.

It's a common mistake, and we should probably remove most
of the of_match_ptr() references as you rarely have drivers
that optionally use OF support but benefit from compiling
that support out on kernels without OF.

Arnd

2022-10-13 08:28:46

by Damien Le Moal

[permalink] [raw]
Subject: Re: drivers/ata/ahci_st.c:229:34: warning: unused variable 'st_ahci_match'

On 2022/10/13 16:33, Arnd Bergmann wrote:
> On Thu, Oct 13, 2022, at 8:13 AM, Damien Le Moal wrote:
>> On 10/12/22 15:37, kernel test robot wrote:
>
>> I am at a loss with this one... There are plenty of patterns similar to
>> drivers/ata/ahci_st.c doing something like:
>>
>> static const struct of_device_id st_ahci_match[] = {
>>
>> { .compatible = "st,ahci", },
>>
>> { /* sentinel */ }
>>
>> };
>>
>> MODULE_DEVICE_TABLE(of, st_ahci_match);
>>
>> For instance, in drivers/pwm/pwm-sti.c, we have:
>>
>>
>> And countless others like this for STI and other arch too.
>>
>> So if CONFIG_MODULE is not enabled, how come we are not submerged with
>> warnings about unused variables ? Is mips arch special in this regard ?
>> Or am I missing something ?
>
> It has nothing to do with MIPS, the problem is
>
> .of_match_table = of_match_ptr(st_ahci_match),
>
> The 'of_match_ptr()' sets the pointer to NULL when CONFIG_OF is
> disabled, which avoids a build failure when st_ahci_match[]
> itself is in an #ifdef.
>
> In this driver, there is no #ifdef around st_ahci_match[], so we
> simply want
>
> .of_match_table = st_ahci_match,
>
> The thing with the MODULE_DEVICE_TABLE() is that it would
> create another reference if CONFIG_MODULE is enabled, but not
> for a built-in driver, so you only get this type of warning
> for randconfig builds that have the driver built-in and OF
> disabled.
>
> It's a common mistake, and we should probably remove most
> of the of_match_ptr() references as you rarely have drivers
> that optionally use OF support but benefit from compiling
> that support out on kernels without OF.

Got it. Thanks for the info !

Will patch this and check other ata drivers for the same issue.


--
Damien Le Moal
Western Digital Research