Re: arch/arm/kernel/hibernate.c:29:40: warning: array subscript -1 is outside array bounds of 'const void[2147483647]'

From: Yujie Liu
Date: Mon Nov 20 2023 - 02:19:35 EST


On Mon, Nov 06, 2023 at 02:19:33PM +0100, Linus Walleij wrote:
> Hi Robot,
>
> On Wed, Oct 18, 2023 at 2:17 PM kernel test robot <lkp@xxxxxxxxx> wrote:
>
> > arch/arm/kernel/hibernate.c: In function 'pfn_is_nosave':
> > >> arch/arm/kernel/hibernate.c:29:40: warning: array subscript -1 is outside array bounds of 'const void[2147483647]' [-Warray-bounds=]
> > 29 | unsigned long nosave_end_pfn = virt_to_pfn(&__nosave_end - 1);
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> So the concern is that &__nosave_end could be 0 and the -1 would make
> it wrap around?
>
> It still has nothing to do with arrays, I don't get it.

Hi Linus Walleij, sorry that we couldn't explain this warning very
clearly. Let's consult Kees for more input.

Hi Kees, our robot has sent out several reports of "-Warray-bounds"
warnings. Thanks a lot for helping to analyze them. [1][2]

[1] https://lore.kernel.org/all/202309200904.CEED70DA33@keescook/
[2] https://lore.kernel.org/all/202311071521.099CAEA58@keescook/

As for some other reports, developers have some doubt about them that we
are not sure how to explain, such as the one in this report and
[3][4][5][6]. If it's not too much trouble, could you please help take a
look to see if these are valid warnings or false positives? Thanks a lot.

[3] https://lore.kernel.org/oe-kbuild-all/CACRpkdZ-1OcZ-cz0V218-VxAc07DMPvKWee3MHngs6Hrwv4zPA@xxxxxxxxxxxxxx/
[4] https://lore.kernel.org/oe-kbuild-all/20231019092258.c2cbwmmgffa33bro@vireshk-i7/
[5] https://lore.kernel.org/oe-kbuild-all/CANn89iKdMVNrV_0QienhpCJ98D7hj2sqOOYFhhSHBVHzvtkgWQ@xxxxxxxxxxxxxx/
[6] https://lore.kernel.org/oe-kbuild-all/CAOQ4uxjTv+5cB4z8TZQ02c5F3rags1HARoEQG9834A0+_+_twA@xxxxxxxxxxxxxx/

Best Regards,
Yujie