summaryrefslogtreecommitdiff
path: root/lib/igt_debugfs.c
diff options
context:
space:
mode:
authorDhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>2018-09-05 14:15:55 -0700
committerDhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>2018-09-05 18:12:38 -0700
commit219b578bca04c93004e3f3942ce3079813f72724 (patch)
tree7249eeee59f10bb325449bc71de468c43e80fd9a /lib/igt_debugfs.c
parent86686c6e2f7c6f0944bced11550e06d20bc6957f (diff)
lib/debugfs: Function to read debugfs with the directory already open
tests/kms_frontbuffer_tracking and tests/kms_psr read debugfs nodes several times after opening the directory once. There is already an implementation of this in the kms_frontbuffer_tracking, moving that functionality to the library will allow us to share the code with kms_psr and kms_fbcon_fbt Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com> Reviewed-by: José Roberto de Souza <jose.souza@intel.com>
Diffstat (limited to 'lib/igt_debugfs.c')
-rw-r--r--lib/igt_debugfs.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 14753a9e..baedc225 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -263,25 +263,46 @@ int igt_debugfs_open(int device, const char *filename, int mode)
}
/**
+ * igt_debugfs_simple_read:
+ * @filename: file name
+ * @buf: buffer where the contents will be stored, allocated by the caller
+ * @size: size of the buffer
+ *
+ * This function is similar to __igt_debugfs_read, the difference is that it
+ * expects the debugfs directory to be open and it's descriptor passed as the
+ * first argument.
+ *
+ * Returns:
+ * -errorno on failure or bytes read on success
+ */
+int igt_debugfs_simple_read(int dir, const char *filename, char *buf, int size)
+{
+ int len;
+
+ len = igt_sysfs_read(dir, filename, buf, size - 1);
+ if (len < 0)
+ buf[0] = '\0';
+ else
+ buf[len] = '\0';
+
+ return len;
+}
+
+/**
* __igt_debugfs_read:
* @filename: file name
* @buf: buffer where the contents will be stored, allocated by the caller
- * @buf_size: size of the buffer
+ * @size: size of the buffer
*
* This function opens the debugfs file, reads it, stores the content in the
* provided buffer, then closes the file. Users should make sure that the buffer
* provided is big enough to fit the whole file, plus one byte.
*/
-void __igt_debugfs_read(int fd, const char *filename, char *buf, int buf_size)
+void __igt_debugfs_read(int fd, const char *filename, char *buf, int size)
{
- int dir;
- int len;
+ int dir = igt_debugfs_dir(fd);
- dir = igt_debugfs_dir(fd);
- len = igt_sysfs_read(dir, filename, buf, buf_size - 1);
- if (len < 0)
- len = 0;
- buf[len] = '\0';
+ igt_debugfs_simple_read(dir, filename, buf, size);
close(dir);
}