[Intel-gfx] [PATCH i-g-t] lib/igt_debugfs: Update documentation and clenup

Liviu Dudau liviu.dudau at arm.com
Mon Jul 17 15:05:27 UTC 2017


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.peres at intel.com>
> Cc: Liviu Dudau <liviu.dudau at arm.com>

Reviewed-by: Liviu Dudau <liviu.dudau at arm.com>

> Signed-off-by: Arkadiusz Hiler <arkadiusz.hiler at 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!  /
  ---------------
    ¯\_(ツ)_/¯


More information about the Intel-gfx mailing list