From patchwork Wed Oct 10 13:04:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= X-Patchwork-Id: 10634525 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DDBD017E1 for ; Wed, 10 Oct 2018 13:05:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5958E29E20 for ; Wed, 10 Oct 2018 13:05:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D66229E3B; Wed, 10 Oct 2018 13:05:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0289E29E20 for ; Wed, 10 Oct 2018 13:05:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 33F9489DB4; Wed, 10 Oct 2018 13:05:28 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5385189DB4 for ; Wed, 10 Oct 2018 13:05:27 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Oct 2018 06:05:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,364,1534834800"; d="scan'208";a="76934818" Received: from stinkbox.fi.intel.com (HELO stinkbox) ([10.237.72.174]) by fmsmga007.fm.intel.com with SMTP; 10 Oct 2018 06:05:23 -0700 Received: by stinkbox (sSMTP sendmail emulation); Wed, 10 Oct 2018 16:05:23 +0300 From: Ville Syrjala To: intel-gfx@lists.freedesktop.org Date: Wed, 10 Oct 2018 16:04:47 +0300 Message-Id: <20181010130454.28557-6-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20181010130454.28557-1-ville.syrjala@linux.intel.com> References: <20181010130454.28557-1-ville.syrjala@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 05/12] drm/i915: Add DEFINE_SNPRINTF_ARRAY() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Ville Syrjälä 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ä --- 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) {