From: Michael Jeanson Date: Thu, 24 Sep 2020 19:38:35 +0000 (-0400) Subject: fix: Use 'kernel_read' to read from procfs X-Git-Tag: v2.13.0-rc1~166 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=cc87d2b4fa9348da830b0da09db1ee6653e0d758;p=lttng-modules.git fix: Use 'kernel_read' to read from procfs Use the 'kernel_read' helper to read files in procfs, it's present in the kernel since the 2.6 series and does the right thing on kernels that require the set_fs dance and newer one which don't. Change-Id: I1a53fda379e0bb9acc79331626925bbdba63d727 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/src/wrapper/random.c b/src/wrapper/random.c index 7b91fc7f..63a30988 100644 --- a/src/wrapper/random.c +++ b/src/wrapper/random.c @@ -26,21 +26,12 @@ int wrapper_get_bootid(char *bootid) struct file *file; int ret; ssize_t len; - mm_segment_t old_fs; file = filp_open("/proc/sys/kernel/random/boot_id", O_RDONLY, 0); if (IS_ERR(file)) return PTR_ERR(file); - old_fs = get_fs(); - set_fs(KERNEL_DS); - - if (!file->f_op || !file->f_op->read) { - ret = -EINVAL; - goto end; - } - - len = file->f_op->read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos); + len = kernel_read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos); if (len != BOOT_ID_LEN - 1) { ret = -EINVAL; goto end; @@ -49,7 +40,6 @@ int wrapper_get_bootid(char *bootid) bootid[BOOT_ID_LEN - 1] = '\0'; ret = 0; end: - set_fs(old_fs); filp_close(file, current->files); return ret; }