diff mbox series

[RFC,2/6] testing/pkeys: Don't use uninitialized variable

Message ID 20220610233533.3649584-3-ira.weiny@intel.com (mailing list archive)
State New
Headers show
Series User pkey minor bug fixes | expand

Commit Message

Ira Weiny June 10, 2022, 11:35 p.m. UTC
From: Ira Weiny <ira.weiny@intel.com>

err was being used in test_pkey_alloc_exhaust() prior to being assigned.
errno is useful to know after a failed alloc_pkey() call.

Change err to errno in the debug print.

Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 tools/testing/selftests/vm/protection_keys.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Sohil Mehta June 13, 2022, 10:48 p.m. UTC | #1
On 6/10/2022 4:35 PM, ira.weiny@intel.com wrote:
> diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c
> index d0183c381859..43e47de19c0d 100644
> --- a/tools/testing/selftests/vm/protection_keys.c
> +++ b/tools/testing/selftests/vm/protection_keys.c
> @@ -1225,9 +1225,9 @@ void test_pkey_alloc_exhaust(int *ptr, u16 pkey)
>   		int new_pkey;
>   		dprintf1("%s() alloc loop: %d\n", __func__, i);
>   		new_pkey = alloc_pkey();
> -		dprintf4("%s()::%d, err: %d pkey_reg: 0x%016llx"
> +		dprintf4("%s()::%d, errno: %d pkey_reg: 0x%016llx"

What is errno referring to over here? There are a few things happening 
in alloc_pkey(). I guess it would show the latest error that happened. 
Does errno need to be set to 0 before the call?

Also, would it be useful to print the return value (new_pkey) from 
alloc_pkey() here?

>   				" shadow: 0x%016llx\n",
> -				__func__, __LINE__, err, __read_pkey_reg(),
> +				__func__, __LINE__, errno, __read_pkey_reg(),
>   				shadow_pkey_reg);
>   		read_pkey_reg(); /* for shadow checking */
>   		dprintf2("%s() errno: %d ENOSPC: %d\n", __func__, errno, ENOSPC);

Sohil
Ira Weiny June 13, 2022, 11:59 p.m. UTC | #2
On Mon, Jun 13, 2022 at 03:48:56PM -0700, Mehta, Sohil wrote:
> On 6/10/2022 4:35 PM, ira.weiny@intel.com wrote:
> > diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c
> > index d0183c381859..43e47de19c0d 100644
> > --- a/tools/testing/selftests/vm/protection_keys.c
> > +++ b/tools/testing/selftests/vm/protection_keys.c
> > @@ -1225,9 +1225,9 @@ void test_pkey_alloc_exhaust(int *ptr, u16 pkey)
> >   		int new_pkey;
> >   		dprintf1("%s() alloc loop: %d\n", __func__, i);
> >   		new_pkey = alloc_pkey();
> > -		dprintf4("%s()::%d, err: %d pkey_reg: 0x%016llx"
> > +		dprintf4("%s()::%d, errno: %d pkey_reg: 0x%016llx"
> 
> What is errno referring to over here?  There are a few things happening in
> alloc_pkey().

Good point, but the only system call in alloc_pkey() is pkey_alloc() so it will
be the errno from there.

In test_pkey_alloc_exhaust() we are expecting the errno to be from pkey_alloc()

...
                if ((new_pkey == -1) && (errno == ENOSPC)) {
...


> I guess it would show the latest error that happened. Does
> errno need to be set to 0 before the call?

Maybe.  Now that I look again errno is printed just below at level 2.

                dprintf2("%s() errno: %d ENOSPC: %d\n", __func__, errno, ENOSPC);

I missed that.

> 
> Also, would it be useful to print the return value (new_pkey) from
> alloc_pkey() here?

Yea that might be useful.  Perhaps change err to new_pkey instead since errno
is already printed.

Ira

> 
> >   				" shadow: 0x%016llx\n",
> > -				__func__, __LINE__, err, __read_pkey_reg(),
> > +				__func__, __LINE__, errno, __read_pkey_reg(),
> >   				shadow_pkey_reg);
> >   		read_pkey_reg(); /* for shadow checking */
> >   		dprintf2("%s() errno: %d ENOSPC: %d\n", __func__, errno, ENOSPC);
> 
> Sohil
diff mbox series

Patch

diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c
index d0183c381859..43e47de19c0d 100644
--- a/tools/testing/selftests/vm/protection_keys.c
+++ b/tools/testing/selftests/vm/protection_keys.c
@@ -1225,9 +1225,9 @@  void test_pkey_alloc_exhaust(int *ptr, u16 pkey)
 		int new_pkey;
 		dprintf1("%s() alloc loop: %d\n", __func__, i);
 		new_pkey = alloc_pkey();
-		dprintf4("%s()::%d, err: %d pkey_reg: 0x%016llx"
+		dprintf4("%s()::%d, errno: %d pkey_reg: 0x%016llx"
 				" shadow: 0x%016llx\n",
-				__func__, __LINE__, err, __read_pkey_reg(),
+				__func__, __LINE__, errno, __read_pkey_reg(),
 				shadow_pkey_reg);
 		read_pkey_reg(); /* for shadow checking */
 		dprintf2("%s() errno: %d ENOSPC: %d\n", __func__, errno, ENOSPC);