Re: [PATCH v3 2/2] selftests/mm: add missing mmap() return checks in pkey tests

From: Mike Rapoport

Date: Thu May 28 2026 - 07:15:44 EST


On Thu, May 28, 2026 at 04:57:46PM +0800, Hongfu Li wrote:
> > > @@ -1693,7 +1694,10 @@ int main(void)
> > > printf("running PKEY tests for unsupported CPU/OS\n");
> > >
> > > ptr = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
> > > - assert(ptr != (void *)-1);
> > > + if (ptr == MAP_FAILED) {
> > > + perror("mmap");
> > > + return EXIT_FAILURE;
> > > + }
> >
> > Just stick to pkey_assert() everywhere, it already prints errno and exits.
>
> This is a pre-test initialization path that runs before the test loop,
> so test_nr and iteration_nr are not yet set up for pkey_assert().
>
> Should we just use their initial values here directly?

I think it's fine if pkey_assert() would print the initial values.
Or you can use ksft_exit_fail_perror() here.

> > > test_mprotect_pkey_on_unsupported_cpu(ptr, 1);
> > > exit(0);
> > > }
> > > @@ -1706,5 +1710,5 @@ int main(void)
> > > run_tests_once();
> > >
> > > printf("done (all tests OK)\n");
> > > - return 0;
> > > + return EXIT_SUCCESS;
> >
> > Completely unrelated and not needed.
> >
> > And you may want to base your work on mm-unstable to get up to date version
> > of protection_keys tests.
>
> Sure, I will base my changes on top of the latest mm-unstable branch.
>
> Best regards,
> Hongfu

--
Sincerely yours,
Mike.