All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: "Noralf Trønnes" <noralf@tronnes.org>
Cc: hoegsberg@gmail.com, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3 4/8] drm/print: Add drm_printf_indent()
Date: Thu, 26 Oct 2017 22:13:16 +0300	[thread overview]
Message-ID: <20171026191316.GX10981@intel.com> (raw)
In-Reply-To: <1b80d160-9cf5-e743-997d-408178a469c5@tronnes.org>

On Thu, Oct 26, 2017 at 08:51:57PM +0200, Noralf Trønnes wrote:
> 
> Den 26.10.2017 19.49, skrev Ville Syrjälä:
> > On Thu, Oct 26, 2017 at 06:57:27PM +0200, Noralf Trønnes wrote:
> >> Add drm_printf_indent() that adds tab indentation according to argument.
> >>
> >> Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
> >> ---
> >>   drivers/gpu/drm/drm_print.c | 21 +++++++++++++++++++++
> >>   include/drm/drm_print.h     |  2 ++
> >>   2 files changed, 23 insertions(+)
> >>
> >> diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
> >> index 0b3bf476dc4b..dac3ee98b30f 100644
> >> --- a/drivers/gpu/drm/drm_print.c
> >> +++ b/drivers/gpu/drm/drm_print.c
> >> @@ -64,6 +64,27 @@ void drm_printf(struct drm_printer *p, const char *f, ...)
> >>   }
> >>   EXPORT_SYMBOL(drm_printf);
> >>   
> >> +/**
> >> + * drm_printf_indent - print to a &drm_printer stream with indentation
> >> + * @p: the &drm_printer
> >> + * @i: indentation
> >> + * @f: format string
> >> + */
> >> +void drm_printf_indent(struct drm_printer *p, unsigned int i, const char *f, ...)
> >> +{
> >> +	struct va_format vaf;
> >> +	va_list args;
> >> +
> >> +	drm_printf(p, "%.*s", i, "\t\t\t\t\t\t\t\t\t\t");
> >> +
> >> +	va_start(args, f);
> >> +	vaf.fmt = f;
> >> +	vaf.va = &args;
> >> +	p->printfn(p, &vaf);
> >> +	va_end(args);
> >> +}
> >> +EXPORT_SYMBOL(drm_printf_indent);
> > The double printf() is rather unfortunate. Sadly I don't think there's
> > any proper way to manipulate a va_list to avoid that.
> >
> > Hmm. Would it work if we simply make it a macro? Eg.
> >
> > #define drm_printf_indent(printer, indent, fmt, ...) \
> > 	drm_printf((printer), "%.*s" fmt, (indent), "\t\t\t", ##__VA_ARGS__)
> 
> The macro worked fine and it looks like a better solution to me.

Only downside is that it bloats every format string. But as long
as there aren't a huge number of useless callers we should be fine.

> 
> > The "\t\t\t..." thing is also rather off putting, but I guess it's
> > the best we can do if we want to keep it to one printf(). And maybe we
> > should have a check in there to make sure we have enought tabs in the
> > string to satisfy the indent level, or we just clamp the indent level
> > silently to something reasonable?
> 
> I put 10 tabs in my suggestion, which should be enough and I think it's
> OK to just silently fail to do more. If 10 isn't enough it's easy to add
> more for the developer that hits the limit.

10 is probably even overkill. I'd say if you have to go past four or so
then there's alredy a bigger problem in the code ;)

> 
> Noralf.
> 
> > Oh, seeing the \t now reminds me that tabs won't necesarily get printed
> > out properly. At least I've seen fbcon just printing some weird blobs
> > instead of tabs. Not sure if it's just a matter of having a crappy font
> > or what. That said, the state dump code is using tabs already, so I guess
> > this wouldn't make it worse at least.
> >
> >> +
> >>   #define DRM_PRINTK_FMT "[" DRM_NAME ":%s]%s %pV"
> >>   
> >>   void drm_dev_printk(const struct device *dev, const char *level,
> >> diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h
> >> index 7b9c86a6ca3e..73dcd16eca49 100644
> >> --- a/include/drm/drm_print.h
> >> +++ b/include/drm/drm_print.h
> >> @@ -79,6 +79,8 @@ void __drm_printfn_debug(struct drm_printer *p, struct va_format *vaf);
> >>   
> >>   __printf(2, 3)
> >>   void drm_printf(struct drm_printer *p, const char *f, ...);
> >> +__printf(3, 4)
> >> +void drm_printf_indent(struct drm_printer *p, unsigned int i, const char *f, ...);
> >>   
> >>   
> >>   /**
> >> -- 
> >> 2.14.2

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2017-10-26 19:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-26 16:57 [PATCH v3 0/8] drm/framebuffer: Add framebuffer debugfs file Noralf Trønnes
2017-10-26 16:57 ` [PATCH v3 1/8] drm/vma-manager: drm_vma_node_start() constify argument Noralf Trønnes
2017-10-26 16:57 ` [PATCH v3 2/8] drm/framebuffer: drm_framebuffer_read_refcount() " Noralf Trønnes
2017-10-26 16:57 ` [PATCH v3 3/8] drm/gem: Remove trailing whitespace Noralf Trønnes
2017-10-26 17:51   ` Ville Syrjälä
2017-10-26 16:57 ` [PATCH v3 4/8] drm/print: Add drm_printf_indent() Noralf Trønnes
2017-10-26 17:49   ` Ville Syrjälä
2017-10-26 18:51     ` Noralf Trønnes
2017-10-26 19:13       ` Ville Syrjälä [this message]
2017-10-27  9:44         ` Jani Nikula
2017-10-26 16:57 ` [PATCH v3 5/8] drm/framebuffer: Add framebuffer debugfs file Noralf Trønnes
2017-10-26 16:57 ` [PATCH v3 6/8] drm/atomic: Use drm_framebuffer_print_info() Noralf Trønnes
2017-10-26 16:57 ` [PATCH v3 7/8] drm/cma-helper: Add drm_gem_cma_print_info() Noralf Trønnes
2017-10-26 16:57 ` [PATCH v3 8/8] drm/tinydrm: Use drm_gem_cma_print_info() Noralf Trønnes
2017-10-30 10:31   ` 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=20171026191316.GX10981@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hoegsberg@gmail.com \
    --cc=noralf@tronnes.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.