summaryrefslogtreecommitdiff
path: root/lib/igt_debugfs.c
diff options
context:
space:
mode:
authorArkadiusz Hiler <arkadiusz.hiler@intel.com>2017-07-17 16:53:41 +0300
committerArkadiusz Hiler <arkadiusz.hiler@intel.com>2017-07-18 11:01:04 +0300
commitcbc539a3285c7aca7f69399dfb6b4968cb1457fa (patch)
treea37a7e5babc3add99386fc258e6fc986dade0c7d /lib/igt_debugfs.c
parentfd096fcc3362b1178d687f08e63e198ad9d3dd67 (diff)
lib/igt_debugfs: Update documentation and cleanup
The documentation was lying. The igt_crc_to_string() is threadsafe and does not return a pointer to an internal buffer. Actually the caller is responsible for the memory that is allocated (and they are for all the current cases), so let's put that in the doc too. While I was at it I got rid of strdup() in favor of an early allocation. Cc: Martin Peres <martin.peres@intel.com> Cc: Liviu Dudau <liviu.dudau@arm.com> Signed-off-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com> Reviewed-by: Martin Peres <martin.peres@intel.com>
Diffstat (limited to 'lib/igt_debugfs.c')
-rw-r--r--lib/igt_debugfs.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 80f25c61..2702686a 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -304,21 +304,23 @@ void igt_assert_crc_equal(const igt_crc_t *a, const igt_crc_t *b)
* igt_crc_to_string:
* @crc: pipe CRC value to print
*
- * This formats @crc into a string buffer which is owned by igt_crc_to_string().
- * The next call will override the buffer again, which makes this multithreading
- * unsafe.
+ * This function allocates a string and formats @crc into it.
+ * The caller is responsible for freeing the string.
*
* This should only ever be used for diagnostic debug output.
*/
char *igt_crc_to_string(igt_crc_t *crc)
{
int i;
- char buf[128] = { 0 };
+ char *buf = calloc(128, sizeof(char));
+
+ if (!buf)
+ return NULL;
for (i = 0; i < crc->n_words; i++)
sprintf(buf + strlen(buf), "%08x ", crc->crc[i]);
- return strdup(buf);
+ return buf;
}
#define MAX_CRC_ENTRIES 10