Re: [PATCH 05/12] drm/i915: Add DEFINE_SNPRINTF_ARRAY()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Oct 11, 2018 at 03:14:41PM +0300, Jani Nikula wrote:
> On Wed, 10 Oct 2018, Ville Syrjala <ville.syrjala@xxxxxxxxxxxxxxx> wrote:
> > From: Ville Syrjälä <ville.syrjala@xxxxxxxxxxxxxxx>
> >
> > Templatize snprintf_int_array() to allow us to print
> > different kinds of arrays without having to type all
> > the boilerplate for the snprintf() loop.
> 
> I might just feel happier about duplicating the boilerplate...

How about when the third user appears? :)

Not sure I have a third user for this actually.
snprintf_output_types() is pretty close, and there are other
bitmask I'd probably like to decode. But I couldn't immediately
think of a nice way to handle bitmasks and arrays in the same
function.

> 
> BR,
> Jani.
> 
> 
> 
> >
> > Signed-off-by: Ville Syrjälä <ville.syrjala@xxxxxxxxxxxxxxx>
> > ---
> >  drivers/gpu/drm/i915/i915_utils.h | 16 ++++++++++++++++
> >  drivers/gpu/drm/i915/intel_dp.c   | 17 ++---------------
> >  2 files changed, 18 insertions(+), 15 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
> > index 5858a43e19da..079aefa20bee 100644
> > --- a/drivers/gpu/drm/i915/i915_utils.h
> > +++ b/drivers/gpu/drm/i915/i915_utils.h
> > @@ -161,4 +161,20 @@ static inline const char *enableddisabled(bool v)
> >  	return v ? "enabled" : "disabled";
> >  }
> >  
> > +#define DEFINE_SNPRINTF_ARRAY(name, type, values, index, fmt, ...) \
> > +void name(char *_str, size_t _len, const type *values, int _nelems) \
> > +{ \
> > +	int index; \
> > +	if (_len) \
> > +		_str[0] = '\0'; \
> > +	for (index = 0; index < _nelems; index++) { \
> > +		int _r = snprintf(_str, _len, "%s" fmt, \
> > +				  index ? ", " : "", __VA_ARGS__); \
> > +		if (_r >= _len) \
> > +			return; \
> > +		_str += _r; \
> > +		_len -= _r; \
> > +	} \
> > +}
> > +
> >  #endif /* !__I915_UTILS_H */
> > diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> > index 13ff89be6ad6..dd8634b40179 100644
> > --- a/drivers/gpu/drm/i915/intel_dp.c
> > +++ b/drivers/gpu/drm/i915/intel_dp.c
> > @@ -1774,21 +1774,8 @@ intel_dp_set_clock(struct intel_encoder *encoder,
> >  	}
> >  }
> >  
> > -static void snprintf_int_array(char *str, size_t len,
> > -			       const int *array, int nelem)
> > -{
> > -	int i;
> > -
> > -	str[0] = '\0';
> > -
> > -	for (i = 0; i < nelem; i++) {
> > -		int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
> > -		if (r >= len)
> > -			return;
> > -		str += r;
> > -		len -= r;
> > -	}
> > -}
> > +static DEFINE_SNPRINTF_ARRAY(snprintf_int_array,
> > +			     int, array, i, "%d", array[i]);
> >  
> >  static void intel_dp_print_rates(struct intel_dp *intel_dp)
> >  {
> 
> -- 
> Jani Nikula, Intel Open Source Graphics Center

-- 
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux