drm/i915: add plural() helper for logging plurals

Submitted by Jani Nikula on Sept. 2, 2019, 6:29 p.m.

Details

Message ID 20190902182916.17487-1-jani.nikula@intel.com
State New
Headers show
Series "drm/i915: add plural() helper for logging plurals" ( rev: 1 ) in Intel GFX

Not browsing as part of any series.

Commit Message

Jani Nikula Sept. 2, 2019, 6:29 p.m.
Add a helper instead of open coding the plurals in debug logs. Also
fixes the case for "0 display pipes available."

Signed-off-by: Jani Nikula <jani.nikula@intel.com>

---

I stumbled upon the pipes one while working on ->num_pipes. I honestly
thought we'd have more users than this, but to my surprise couldn't find
any. Perhaps this is not worth it after all.
---
 drivers/gpu/drm/i915/display/intel_display.c | 2 +-
 drivers/gpu/drm/i915/i915_utils.h            | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
index e661e2099118..c4bfd80a1cfa 100644
--- a/drivers/gpu/drm/i915/display/intel_display.c
+++ b/drivers/gpu/drm/i915/display/intel_display.c
@@ -16215,7 +16215,7 @@  int intel_modeset_init(struct drm_device *dev)
 
 	DRM_DEBUG_KMS("%d display pipe%s available.\n",
 		      INTEL_INFO(dev_priv)->num_pipes,
-		      INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
+		      plural(INTEL_INFO(dev_priv)->num_pipes));
 
 	for_each_pipe(dev_priv, pipe) {
 		ret = intel_crtc_init(dev_priv, pipe);
diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
index 562f756da421..dc34dfe18a1e 100644
--- a/drivers/gpu/drm/i915/i915_utils.h
+++ b/drivers/gpu/drm/i915/i915_utils.h
@@ -410,6 +410,11 @@  static inline const char *enableddisabled(bool v)
 	return v ? "enabled" : "disabled";
 }
 
+static inline const char *plural(long v)
+{
+	return v == 1 ? "" : "s";
+}
+
 static inline void add_taint_for_CI(unsigned int taint)
 {
 	/*

Comments

Quoting Jani Nikula (2019-09-02 21:29:16)
> Add a helper instead of open coding the plurals in debug logs. Also
> fixes the case for "0 display pipes available."
> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> 
> ---
> 
> I stumbled upon the pipes one while working on ->num_pipes. I honestly
> thought we'd have more users than this, but to my surprise couldn't find
> any. Perhaps this is not worth it after all.

Just a debug string, less hassle with "display pipes available: %d"?

Regards, Joonas