From: Jani Nikula <jani.nikula@intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: jani.nikula@intel.com
Subject: [Intel-gfx] [PATCH 1/5] drm/i915/gmbus: combine gmbus pin lookups to one function
Date: Thu, 3 Mar 2022 20:19:27 +0200 [thread overview]
Message-ID: <20220303181931.1661767-1-jani.nikula@intel.com> (raw)
Combine the platform specific if ladders for array lookup and size
checks into one. This is cleaner and avoids duplication, but hopefully
also helps any static analyzers that seem to have trouble with the
bounds checks.
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
drivers/gpu/drm/i915/display/intel_gmbus.c | 62 ++++++++++------------
1 file changed, 29 insertions(+), 33 deletions(-)
diff --git a/drivers/gpu/drm/i915/display/intel_gmbus.c b/drivers/gpu/drm/i915/display/intel_gmbus.c
index 2fad03250661..9cbf7f9a1e2e 100644
--- a/drivers/gpu/drm/i915/display/intel_gmbus.c
+++ b/drivers/gpu/drm/i915/display/intel_gmbus.c
@@ -106,51 +106,47 @@ static const struct gmbus_pin gmbus_pins_dg2[] = {
[GMBUS_PIN_9_TC1_ICP] = { "tc1", GPIOJ },
};
-/* pin is expected to be valid */
-static const struct gmbus_pin *get_gmbus_pin(struct drm_i915_private *dev_priv,
+static const struct gmbus_pin *get_gmbus_pin(struct drm_i915_private *i915,
unsigned int pin)
{
- if (INTEL_PCH_TYPE(dev_priv) >= PCH_DG2)
- return &gmbus_pins_dg2[pin];
- else if (INTEL_PCH_TYPE(dev_priv) >= PCH_DG1)
- return &gmbus_pins_dg1[pin];
- else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
- return &gmbus_pins_icp[pin];
- else if (HAS_PCH_CNP(dev_priv))
- return &gmbus_pins_cnp[pin];
- else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
- return &gmbus_pins_bxt[pin];
- else if (DISPLAY_VER(dev_priv) == 9)
- return &gmbus_pins_skl[pin];
- else if (IS_BROADWELL(dev_priv))
- return &gmbus_pins_bdw[pin];
- else
- return &gmbus_pins[pin];
-}
-
-bool intel_gmbus_is_valid_pin(struct drm_i915_private *dev_priv,
- unsigned int pin)
-{
- unsigned int size;
+ const struct gmbus_pin *pins;
+ size_t size;
- if (INTEL_PCH_TYPE(dev_priv) >= PCH_DG2)
+ if (INTEL_PCH_TYPE(i915) >= PCH_DG2) {
+ pins = gmbus_pins_dg2;
size = ARRAY_SIZE(gmbus_pins_dg2);
- else if (INTEL_PCH_TYPE(dev_priv) >= PCH_DG1)
+ } else if (INTEL_PCH_TYPE(i915) >= PCH_DG1) {
+ pins = gmbus_pins_dg1;
size = ARRAY_SIZE(gmbus_pins_dg1);
- else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
+ } else if (INTEL_PCH_TYPE(i915) >= PCH_ICP) {
+ pins = gmbus_pins_icp;
size = ARRAY_SIZE(gmbus_pins_icp);
- else if (HAS_PCH_CNP(dev_priv))
+ } else if (HAS_PCH_CNP(i915)) {
+ pins = gmbus_pins_cnp;
size = ARRAY_SIZE(gmbus_pins_cnp);
- else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
+ } else if (IS_GEMINILAKE(i915) || IS_BROXTON(i915)) {
+ pins = gmbus_pins_bxt;
size = ARRAY_SIZE(gmbus_pins_bxt);
- else if (DISPLAY_VER(dev_priv) == 9)
+ } else if (DISPLAY_VER(i915) == 9) {
+ pins = gmbus_pins_skl;
size = ARRAY_SIZE(gmbus_pins_skl);
- else if (IS_BROADWELL(dev_priv))
+ } else if (IS_BROADWELL(i915)) {
+ pins = gmbus_pins_bdw;
size = ARRAY_SIZE(gmbus_pins_bdw);
- else
+ } else {
+ pins = gmbus_pins;
size = ARRAY_SIZE(gmbus_pins);
+ }
+
+ if (pin >= size || !pins[pin].name)
+ return NULL;
- return pin < size && get_gmbus_pin(dev_priv, pin)->name;
+ return &pins[pin];
+}
+
+bool intel_gmbus_is_valid_pin(struct drm_i915_private *i915, unsigned int pin)
+{
+ return get_gmbus_pin(i915, pin);
}
/* Intel GPIO access functions */
--
2.30.2
next reply other threads:[~2022-03-03 18:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-03 18:19 Jani Nikula [this message]
2022-03-03 18:19 ` [Intel-gfx] [PATCH 2/5] drm/i915/gmbus: reduce gmbus pin lookups in gmbus setup Jani Nikula
2022-03-03 18:19 ` [Intel-gfx] [PATCH 3/5] drm/i915/gmbus: pass gpio reg to intel_gpio_setup() Jani Nikula
2022-03-03 18:19 ` [Intel-gfx] [PATCH 4/5] drm/i915/gmbus: alloc intel_gmbus dynamically Jani Nikula
2022-03-03 20:17 ` Ville Syrjälä
2022-03-04 9:55 ` Jani Nikula
2022-03-03 18:19 ` [Intel-gfx] [PATCH 5/5] drm/i915: include linux/highmem.h and linux/swap.h where needed Jani Nikula
2022-03-03 19:26 ` [Intel-gfx] ✗ Fi.CI.SPARSE: warning for series starting with [1/5] drm/i915/gmbus: combine gmbus pin lookups to one function Patchwork
2022-03-03 19:54 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2022-03-04 8:01 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork
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=20220303181931.1661767-1-jani.nikula@intel.com \
--to=jani.nikula@intel.com \
--cc=intel-gfx@lists.freedesktop.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox