From 92ac6131a1b35b9a9d397f77b412ce8b8747eb5f Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Thu, 5 Jan 2017 01:34:24 +0000
Subject: [PATCH] tests: replace init_magic with fill_memory

Use the same fill_memory/fill_memory_ex interface in all affected tests.

* tests/ioctl_block.c (init_magic): Remove.
(main): Replace init_magic with fill_memory.
* tests/ioctl_evdev.c: Likewise.
* tests/ioctl_v4l2.c: Likewise.
* tests/ioctl_mtd.c (magic, init_magic): Remove.
(main): Replace init_magic with fill_memory.
* tests/ioctl_rtc.c: Likewise.
---
 tests/ioctl_block.c | 14 +-------------
 tests/ioctl_evdev.c | 16 +++-------------
 tests/ioctl_mtd.c   | 27 ++++++++-------------------
 tests/ioctl_rtc.c   | 19 ++++---------------
 tests/ioctl_v4l2.c  | 16 +++-------------
 5 files changed, 19 insertions(+), 73 deletions(-)

diff --git a/tests/ioctl_block.c b/tests/ioctl_block.c
index 82b89da9..f62b0b36 100644
--- a/tests/ioctl_block.c
+++ b/tests/ioctl_block.c
@@ -43,18 +43,6 @@
 static const unsigned int magic = 0xdeadbeef;
 static const unsigned long lmagic = (unsigned long) 0xdeadbeefbadc0dedULL;
 
-#if defined BLKTRACESETUP && defined HAVE_STRUCT_BLK_USER_TRACE_SETUP
-static void
-init_magic(void *addr, const unsigned int size)
-{
-	unsigned int *p = addr;
-	const unsigned int *end = addr + size - sizeof(int);
-
-	for (; p <= end; ++p)
-		*(unsigned int *) p = magic + (p - (unsigned int *) addr);
-}
-#endif
-
 static struct xlat block_argless[] = {
 	XLAT(BLKRRPART),
 	XLAT(BLKFLSBUF),
@@ -190,7 +178,7 @@ main(void)
 
 #if defined BLKTRACESETUP && defined HAVE_STRUCT_BLK_USER_TRACE_SETUP
 	struct blk_user_trace_setup *const buts = tail_alloc(sizeof(*buts));
-	init_magic(buts, sizeof(*buts));
+	fill_memory(buts, sizeof(*buts));
 
 	ioctl(-1, BLKTRACESETUP, buts);
 	printf("ioctl(-1, BLKTRACESETUP, {act_mask=%hu, buf_size=%u, buf_nr=%u"
diff --git a/tests/ioctl_evdev.c b/tests/ioctl_evdev.c
index 74aac0d3..d12323ee 100644
--- a/tests/ioctl_evdev.c
+++ b/tests/ioctl_evdev.c
@@ -41,16 +41,6 @@
 static const unsigned int magic = 0xdeadbeef;
 static const unsigned long lmagic = (unsigned long) 0xdeadbeefbadc0dedULL;
 
-static void
-init_magic(void *addr, const unsigned int size)
-{
-	unsigned int *p = addr;
-	const unsigned int *end = addr + size - sizeof(int);
-
-	for (; p <= end; ++p)
-		*(unsigned int *) p = magic;
-}
-
 # if VERBOSE
 static void
 print_envelope(const struct ff_envelope *const e)
@@ -156,7 +146,7 @@ main(void)
 
 	const unsigned int size = get_page_size();
 	void *const page = tail_alloc(size);
-	init_magic(page, size);
+	fill_memory(page, size);
 
 	int *const val_int = tail_alloc(sizeof(*val_int));
 	*val_int = magic;
@@ -183,7 +173,7 @@ main(void)
 
 # ifdef EVIOCSKEYCODE_V2
 	struct input_keymap_entry *const ike = tail_alloc(sizeof(*ike));
-	init_magic(ike, sizeof(*ike));
+	fill_memory(ike, sizeof(*ike));
 	ike->keycode = 2;
 
 	ioctl(-1, EVIOCSKEYCODE_V2, ike);
@@ -207,7 +197,7 @@ main(void)
 # endif
 
 	struct ff_effect *const ffe = tail_alloc(sizeof(*ffe));
-	init_magic(ffe, sizeof(*ffe));
+	fill_memory(ffe, sizeof(*ffe));
 
 	ffe->type = FF_CONSTANT;
 	ioctl(-1, EVIOCSFF, ffe);
diff --git a/tests/ioctl_mtd.c b/tests/ioctl_mtd.c
index e28bcc9d..a37d5d0f 100644
--- a/tests/ioctl_mtd.c
+++ b/tests/ioctl_mtd.c
@@ -42,19 +42,8 @@
 # include <mtd/mtd-abi.h>
 #endif
 
-static const unsigned int magic = 0xdeadbeef;
 static const unsigned long lmagic = (unsigned long) 0xdeadbeefbadc0dedULL;
 
-static void
-init_magic(void *addr, const unsigned int size)
-{
-	unsigned int *p = addr;
-	const unsigned int *end = addr + size - sizeof(int);
-
-	for (; p <= end; ++p)
-		*(unsigned int *) p = magic;
-}
-
 #define TEST_NULL_ARG(cmd) \
 	do { \
 		ioctl(-1, cmd, 0); \
@@ -113,7 +102,7 @@ main(void)
 	       " = -1 EBADF (%m)\n", (unsigned int) _IOC_NR(OTPSELECT));
 
 	uint64_t *const v64 = tail_alloc(sizeof(*v64));
-	init_magic(v64, sizeof(*v64));
+	fill_memory(v64, sizeof(*v64));
 
 	ioctl(-1, MEMGETBADBLOCK, v64);
 	printf("ioctl(-1, MIXER_WRITE(%u) or MEMGETBADBLOCK, [%" PRIu64 "])"
@@ -126,7 +115,7 @@ main(void)
 	       (unsigned int) _IOC_NR(MEMSETBADBLOCK), *v64);
 
 	struct region_info_user *const riu = tail_alloc(sizeof(*riu));
-	init_magic(riu, sizeof(*riu));
+	fill_memory(riu, sizeof(*riu));
 	ioctl(-1, MEMGETREGIONINFO, riu);
 	printf("ioctl(-1, %s, {regionindex=%#x}) = -1 EBADF (%m)\n",
 	       "MEMGETREGIONINFO"
@@ -136,7 +125,7 @@ main(void)
 	       , riu->regionindex);
 
 	struct erase_info_user *const eiu = tail_alloc(sizeof(*eiu));
-	init_magic(eiu, sizeof(*eiu));
+	fill_memory(eiu, sizeof(*eiu));
 
 	TEST_erase_info_user(MEMERASE, eiu);
 	TEST_erase_info_user(MEMLOCK, eiu);
@@ -144,7 +133,7 @@ main(void)
 	TEST_erase_info_user(MEMISLOCKED, eiu);
 
 	struct erase_info_user64 *const eiu64 = tail_alloc(sizeof(*eiu64));
-	init_magic(eiu64, sizeof(*eiu64));
+	fill_memory(eiu64, sizeof(*eiu64));
 	ioctl(-1, MEMERASE64, eiu64);
 	printf("ioctl(-1, MIXER_WRITE(%u) or %s, {start=%#llx, length=%#llx})"
 	       " = -1 EBADF (%m)\n",
@@ -153,7 +142,7 @@ main(void)
 	       (unsigned long long) eiu64->length);
 
 	struct mtd_oob_buf *const oob = tail_alloc(sizeof(*oob));
-	init_magic(oob, sizeof(*oob));
+	fill_memory(oob, sizeof(*oob));
 
 	ioctl(-1, MEMWRITEOOB, oob);
 	printf("ioctl(-1, MEMWRITEOOB, {start=%#x, length=%#x, ptr=%p})"
@@ -164,7 +153,7 @@ main(void)
 	       " = -1 EBADF (%m)\n", oob->start, oob->length, oob->ptr);
 
 	struct mtd_oob_buf64 *const oob64 = tail_alloc(sizeof(*oob64));
-	init_magic(oob64, sizeof(*oob64));
+	fill_memory(oob64, sizeof(*oob64));
 
 	ioctl(-1, MEMWRITEOOB64, oob64);
 	printf("ioctl(-1, MEMWRITEOOB64"
@@ -180,14 +169,14 @@ main(void)
 
 
 	struct otp_info *const oi = tail_alloc(sizeof(*oi));
-	init_magic(oi, sizeof(*oi));
+	fill_memory(oi, sizeof(*oi));
 	ioctl(-1, OTPLOCK, oi);
 	printf("ioctl(-1, MIXER_READ(%u) or OTPLOCK"
 	       ", {start=%#x, length=%#x, locked=%u}) = -1 EBADF (%m)\n",
 	       (unsigned int) _IOC_NR(OTPLOCK),  oi->start, oi->length, oi->locked);
 
 	struct mtd_write_req *const wr = tail_alloc(sizeof(*wr));
-	init_magic(wr, sizeof(*wr));
+	fill_memory(wr, sizeof(*wr));
 	wr->mode = MTD_OPS_PLACE_OOB;
 	ioctl(-1, MEMWRITE, wr);
 	printf("ioctl(-1, MEMWRITE, {start=%#llx, len=%#llx, ooblen=%#llx"
diff --git a/tests/ioctl_rtc.c b/tests/ioctl_rtc.c
index 34264ce5..49d7ec7b 100644
--- a/tests/ioctl_rtc.c
+++ b/tests/ioctl_rtc.c
@@ -36,19 +36,8 @@
 #include <linux/rtc.h>
 #include "xlat.h"
 
-static const unsigned int magic = 0xdeadbeef;
 static const unsigned long lmagic = (unsigned long) 0xdeadbeefbadc0dedULL;
 
-static void
-init_magic(void *addr, const unsigned int size)
-{
-	unsigned int *p = addr;
-	const unsigned int *end = addr + size - sizeof(int);
-
-	for (; p <= end; ++p)
-		*(unsigned int *) p = magic;
-}
-
 static void
 print_rtc_time(const struct rtc_time *rt)
 {
@@ -82,16 +71,16 @@ main(void)
 	const unsigned int size = get_page_size();
 
 	void *const page = tail_alloc(size);
-	init_magic(page, size);
+	fill_memory(page, size);
 
 	struct rtc_time *rt = tail_alloc(sizeof(*rt));
-	init_magic(rt, sizeof(*rt));
+	fill_memory(rt, sizeof(*rt));
 
 	struct rtc_wkalrm *wk = tail_alloc(sizeof(*wk));
-	init_magic(wk, sizeof(*wk));
+	fill_memory(wk, sizeof(*wk));
 
 	struct rtc_pll_info *pll = tail_alloc(sizeof(*pll));
-	init_magic(pll, sizeof(*pll));
+	fill_memory(pll, sizeof(*pll));
 
 	/* RTC_ALM_READ */
 	ioctl(-1, RTC_ALM_READ, 0);
diff --git a/tests/ioctl_v4l2.c b/tests/ioctl_v4l2.c
index a3b430b3..af8c3419 100644
--- a/tests/ioctl_v4l2.c
+++ b/tests/ioctl_v4l2.c
@@ -32,18 +32,6 @@
 #include <linux/types.h>
 #include <linux/videodev2.h>
 
-static const unsigned int magic = 0xdeadbeef;
-
-static void
-init_magic(void *addr, const unsigned int size)
-{
-	unsigned int *p = addr;
-	const unsigned int *end = addr + size;
-
-	for (; p < end; ++p)
-		*(unsigned int *) p = magic;
-}
-
 #if WORDS_BIGENDIAN
 # define cc0(arg) ((unsigned int) (unsigned char) ((unsigned int) (arg) >> 24))
 # define cc1(arg) ((unsigned int) (unsigned char) ((unsigned int) (arg) >> 16))
@@ -66,12 +54,14 @@ init_magic(void *addr, const unsigned int size)
 	 ((unsigned int)(a3) << 24))
 #endif
 
+static const unsigned int magic = 0xdeadbeef;
+
 int
 main(void )
 {
 	const unsigned int size = get_page_size();
 	void *const page = tail_alloc(size);
-	init_magic(page, size);
+	fill_memory(page, size);
 
 	unsigned char cc[sizeof(int)] = { 'A', '\'', '\\', '\xfa' };
 
-- 
2.40.0