On Mon, Jul 17, 2017 at 04:59:48PM +0300, Arkadiusz Hiler wrote:
> 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.pe...@intel.com>
> Cc: Liviu Dudau <liviu.du...@arm.com>

Reviewed-by: Liviu Dudau <liviu.du...@arm.com>

> Signed-off-by: Arkadiusz Hiler <arkadiusz.hi...@intel.com>
> ---
>  lib/igt_debugfs.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
> index 80f25c6..5e4d72c 100644
> --- a/lib/igt_debugfs.c
> +++ b/lib/igt_debugfs.c
> @@ -304,21 +304,20 @@ 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 formats @crc into a string. Function allocates memory - the caller is
> + * in charge of freeing it.
>   *
>   * 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));
>  
>       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
> -- 
> 2.9.4
> 

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to