diff mbox series

futex_waitv01: Correct assign and add cleanup

Message ID 20220413112405.48471-1-zhaogongyi@huawei.com
State Accepted
Headers show
Series futex_waitv01: Correct assign and add cleanup | expand

Commit Message

Zhao Gongyi April 13, 2022, 11:24 a.m. UTC
1.Correct assign of waitv->uaddr
2.Rename function name of test_invalid_nr_futex
3.Add cleanup

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 testcases/kernel/syscalls/futex/futex_waitv01.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

--
2.17.1

Comments

Cyril Hrubis April 14, 2022, 1:42 p.m. UTC | #1
Hi!
> +static void cleanup(void)
> +{
> +	if (futex != NULL)
> +		free(futex);

free(NULL) is no-op, there is no reason to check for NULL before passing
a pointer to free().

The rest of the changes looks good to me.
Petr Vorel April 14, 2022, 3:25 p.m. UTC | #2
Hi Zhao, Cyril,

> Hi!
> > +static void cleanup(void)
> > +{
> > +	if (futex != NULL)
> > +		free(futex);

> free(NULL) is no-op, there is no reason to check for NULL before passing
> a pointer to free().

> The rest of the changes looks good to me.

Removed if check before free(futex) and merged with Cyril's Reviewed-by: tag.

Thanks!

Kind regards,
Petr
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/futex/futex_waitv01.c b/testcases/kernel/syscalls/futex/futex_waitv01.c
index 8b7bd50d3..ddc4be01c 100644
--- a/testcases/kernel/syscalls/futex/futex_waitv01.c
+++ b/testcases/kernel/syscalls/futex/futex_waitv01.c
@@ -10,6 +10,7 @@ 
  */

 #include <time.h>
+#include <stdlib.h>
 #include "tst_test.h"
 #include "lapi/futex.h"
 #include "futex2test.h"
@@ -32,7 +33,7 @@  static void init_timeout(struct timespec *to)

 static void init_waitv(void)
 {
-	waitv->uaddr = (uintptr_t)&futex;
+	waitv->uaddr = (uintptr_t)futex;
 	waitv->flags = FUTEX_32 | FUTEX_PRIVATE_FLAG;
 	waitv->val = 0;
 }
@@ -98,7 +99,7 @@  static void test_invalid_clockid(void)
 		     "futex_waitv invalid clockid");
 }

-static void test_invalid_nr_futex(void)
+static void test_invalid_nr_futexes(void)
 {
 	struct timespec to;

@@ -112,6 +113,12 @@  static void test_invalid_nr_futex(void)
 		     "futex_waitv invalid nr_futexes");
 }

+static void cleanup(void)
+{
+	if (futex != NULL)
+		free(futex);
+}
+
 static void run(void)
 {
 	test_invalid_flags();
@@ -119,12 +126,13 @@  static void run(void)
 	test_null_address();
 	test_null_waiters();
 	test_invalid_clockid();
-	test_invalid_nr_futex();
+	test_invalid_nr_futexes();
 }

 static struct tst_test test = {
 	.test_all = run,
 	.setup = setup,
+	.cleanup = cleanup,
 	.min_kver = "5.16",
 	.bufs =
 		(struct tst_buffers[]){