public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Mika Kuoppala <mika.kuoppala@linux.intel.com>
To: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: Re: [PATCH] drm/i915/sdvo: Fix up debug output to not split lines
Date: Wed, 27 Nov 2013 17:15:56 +0200	[thread overview]
Message-ID: <878uw9ooyb.fsf@gaia.fi.intel.com> (raw)
In-Reply-To: <1385564581-13015-1-git-send-email-daniel.vetter@ffwll.ch>

Daniel Vetter <daniel.vetter@ffwll.ch> writes:

> It leads to a big mess when stuff interleaves. Especially with the new
> patch I've submitted for the drm core to no longer artificially split
> up debug messages.
>
> v2: The size parameter to snprintf includes the terminating 0, but the
> return value does not. Adjust the logic accordingly. Spotted by Mika.
>
> Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

Reviewed-by: Mika Kuoppala <mika.kuoppala@intel.com>

> ---
>  drivers/gpu/drm/i915/intel_sdvo.c | 55 ++++++++++++++++++++++++++-------------
>  1 file changed, 37 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
> index a583e8f718a7..e4f9918ab859 100644
> --- a/drivers/gpu/drm/i915/intel_sdvo.c
> +++ b/drivers/gpu/drm/i915/intel_sdvo.c
> @@ -413,23 +413,34 @@ static const struct _sdvo_cmd_name {
>  static void intel_sdvo_debug_write(struct intel_sdvo *intel_sdvo, u8 cmd,
>  				   const void *args, int args_len)
>  {
> -	int i;
> +	int i, pos = 0;
> +#define BUF_LEN 256
> +	char buffer[BUF_LEN];
> +
> +#define BUF_PRINT(args...) \
> +	pos += snprintf(buffer + pos, max_t(int, BUF_LEN - pos, 0), args)
> +
>  
> -	DRM_DEBUG_KMS("%s: W: %02X ",
> -				SDVO_NAME(intel_sdvo), cmd);
> -	for (i = 0; i < args_len; i++)
> -		DRM_LOG_KMS("%02X ", ((u8 *)args)[i]);
> -	for (; i < 8; i++)
> -		DRM_LOG_KMS("   ");
> +	for (i = 0; i < args_len; i++) {
> +		BUF_PRINT("%02X ", ((u8 *)args)[i]);
> +	}
> +	for (; i < 8; i++) {
> +		BUF_PRINT("   ");
> +	}
>  	for (i = 0; i < ARRAY_SIZE(sdvo_cmd_names); i++) {
>  		if (cmd == sdvo_cmd_names[i].cmd) {
> -			DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name);
> +			BUF_PRINT("(%s)", sdvo_cmd_names[i].name);
>  			break;
>  		}
>  	}
> -	if (i == ARRAY_SIZE(sdvo_cmd_names))
> -		DRM_LOG_KMS("(%02X)", cmd);
> -	DRM_LOG_KMS("\n");
> +	if (i == ARRAY_SIZE(sdvo_cmd_names)) {
> +		BUF_PRINT("(%02X)", cmd);
> +	}
> +	BUG_ON(pos >= BUF_LEN - 1);
> +#undef BUF_PRINT
> +#undef BUF_LEN
> +
> +	DRM_DEBUG_KMS("%s: W: %02X %s\n", SDVO_NAME(intel_sdvo), cmd, buffer);
>  }
>  
>  static const char *cmd_status_names[] = {
> @@ -512,9 +523,10 @@ static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo,
>  {
>  	u8 retry = 15; /* 5 quick checks, followed by 10 long checks */
>  	u8 status;
> -	int i;
> +	int i, pos = 0;
> +#define BUF_LEN 256
> +	char buffer[BUF_LEN];
>  
> -	DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(intel_sdvo));
>  
>  	/*
>  	 * The documentation states that all commands will be
> @@ -551,10 +563,13 @@ static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo,
>  			goto log_fail;
>  	}
>  
> +#define BUF_PRINT(args...) \
> +	pos += snprintf(buffer + pos, max_t(int, BUF_LEN - pos, 0), args)
> +
>  	if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP)
> -		DRM_LOG_KMS("(%s)", cmd_status_names[status]);
> +		BUF_PRINT("(%s)", cmd_status_names[status]);
>  	else
> -		DRM_LOG_KMS("(??? %d)", status);
> +		BUF_PRINT("(??? %d)", status);
>  
>  	if (status != SDVO_CMD_STATUS_SUCCESS)
>  		goto log_fail;
> @@ -565,13 +580,17 @@ static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo,
>  					  SDVO_I2C_RETURN_0 + i,
>  					  &((u8 *)response)[i]))
>  			goto log_fail;
> -		DRM_LOG_KMS(" %02X", ((u8 *)response)[i]);
> +		BUF_PRINT(" %02X", ((u8 *)response)[i]);
>  	}
> -	DRM_LOG_KMS("\n");
> +	BUG_ON(pos >= BUF_LEN - 1);
> +#undef BUF_PRINT
> +#undef BUF_LEN
> +
> +	DRM_DEBUG_KMS("%s: R: %s\n", SDVO_NAME(intel_sdvo), buffer);
>  	return true;
>  
>  log_fail:
> -	DRM_LOG_KMS("... failed\n");
> +	DRM_DEBUG_KMS("%s: R: ... failed\n", SDVO_NAME(intel_sdvo));
>  	return false;
>  }
>  
> -- 
> 1.8.3.1

  reply	other threads:[~2013-11-27 15:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-27 11:10 [PATCH] drm/i915/sdvo: Fix up debug output to not split lines Daniel Vetter
2013-11-27 14:09 ` Mika Kuoppala
2013-11-27 14:26   ` Daniel Vetter
2013-11-27 15:03 ` Daniel Vetter
2013-11-27 15:15   ` Mika Kuoppala [this message]
2013-11-27 21:53     ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878uw9ooyb.fsf@gaia.fi.intel.com \
    --to=mika.kuoppala@linux.intel.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox