1 // SPDX-License-Identifier: GPL-2.0
5 #include <linux/kernel.h>
6 #include <internal/lib.h>
8 unsigned int page_size
;
10 static ssize_t
ion(bool is_read
, int fd
, void *buf
, size_t n
)
12 void *buf_start
= buf
;
16 /* buf must be treated as const if !is_read. */
17 ssize_t ret
= is_read
? read(fd
, buf
, left
) :
20 if (ret
< 0 && errno
== EINTR
)
29 BUG_ON((size_t)(buf
- buf_start
) != n
);
34 * Read exactly 'n' bytes or return an error.
36 ssize_t
readn(int fd
, void *buf
, size_t n
)
38 return ion(true, fd
, buf
, n
);
42 * Write exactly 'n' bytes or return an error.
44 ssize_t
writen(int fd
, const void *buf
, size_t n
)
46 /* ion does not modify buf. */
47 return ion(false, fd
, (void *)buf
, n
);