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. 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) { -- 2.18.1 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx