Re: [PATCH mm v2] kasan: fix array-bounds warnings in tests

From: Andrey Konovalov
Date: Mon Sep 26 2022 - 14:18:01 EST


On Sun, Sep 25, 2022 at 7:03 PM Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> > --- a/mm/kasan/kasan_test.c
> > +++ b/mm/kasan/kasan_test.c
> > @@ -333,6 +333,8 @@ static void krealloc_more_oob_helper(struct kunit *test,
> > ptr2 = krealloc(ptr1, size2, GFP_KERNEL);
> > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2);
> >
> > + OPTIMIZER_HIDE_VAR(ptr2);
> > +
> > /* All offsets up to size2 must be accessible. */
> > ptr2[size1 - 1] = 'x';
> > ptr2[size1] = 'x';
> > @@ -365,6 +367,8 @@ static void krealloc_less_oob_helper(struct kunit *test,
> > ptr2 = krealloc(ptr1, size2, GFP_KERNEL);
> > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2);
> >
> > + OPTIMIZER_HIDE_VAR(ptr2);
>
> What chance does a reader have of working out why this is here? If
> "little" then a code comment would be a nice way of saving that poor
> person for having to dive into the git history.

Will add in v3. Thank you, Andrew!