From bce099b208cb540917015b0f1c806ff29b1a687e Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Fri, 2 Oct 2020 13:03:34 -0400 Subject: [PATCH] Add 'kernel_read' wrapper for kernels < v4.14 See upstream commit: commit bdd1d2d3d251c65b74ac4493e08db18971c09240 Author: Christoph Hellwig Date: Fri Sep 1 17:39:13 2017 +0200 fs: fix kernel_read prototype Use proper ssize_t and size_t types for the return value and count argument, move the offset last and make it an in/out argument like all other read/write helpers, and make the buf argument a void pointer to get rid of lots of casts in the callers. Change-Id: I825c3fcbcc17e9b46e2a661fadc66b52a94eb2da Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- include/wrapper/fs.h | 43 +++++++++++++++++++++++++++++++++++++++++++ wrapper/random.c | 4 ++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 include/wrapper/fs.h diff --git a/include/wrapper/fs.h b/include/wrapper/fs.h new file mode 100644 index 00000000..f11c19fc --- /dev/null +++ b/include/wrapper/fs.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) + * + * wrapper/fs.h + * + * Copyright (C) 2020 Michael Jeanson + */ + +#ifndef _LTTNG_WRAPPER_FS_H +#define _LTTNG_WRAPPER_FS_H + +#include +#include + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)) + +static inline +ssize_t lttng_kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) +{ + return kernel_read(file, buf, count, pos); +} + +#else /* LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0) */ + +static inline +ssize_t lttng_kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) +{ + ssize_t len; + + len = kernel_read(file, *pos, buf, count); + + /* + * Move 'pos' forward since it's passed by value in this + * implementation of 'kernel_read'. + */ + if (len > 0) + (*pos) += len; + + return len; +} + +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0) */ + +#endif /* _LTTNG_WRAPPER_FS_H */ diff --git a/wrapper/random.c b/wrapper/random.c index d7e53cd1..f67d0f0c 100644 --- a/wrapper/random.c +++ b/wrapper/random.c @@ -14,7 +14,7 @@ /* boot_id depends on sysctl */ #if defined(CONFIG_SYSCTL) -#include +#include #include #include #include @@ -33,7 +33,7 @@ int wrapper_get_bootid(char *bootid) if (IS_ERR(file)) return PTR_ERR(file); - len = kernel_read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos); + len = lttng_kernel_read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos); if (len != BOOT_ID_LEN - 1) { ret = -EINVAL; goto end; -- 2.34.1