From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E8892E1EE0 for ; Fri, 26 Jun 2026 14:02:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782482530; cv=none; b=C0XolvuLHjs6KlpDtj7/8Ka9o8O4Dcmgg/2skXIRAzCRHJAvPaX3YYjYKBeYhiUa07jBGM6RRyOQwSR2Xb6lejhnlCeWHds7ea8Qh8LfBlJv9EpOKKvNTQR2kCe7sqLVGQADA8vO1PFgP+Wp3weJyvVRz1axDd95ZAOBzVPmjHo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782482530; c=relaxed/simple; bh=t+344il5kS+1UwLrPedrEucQtxevDKH1A2BfGnBb1lw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OmrmNtqQSMu4DaXaQHg/CiboN8zuoORXUnYFgR9DyRFHE+DHpmbvbFEFzZkzIz6wRKF2i6O2+iUjH5IluF3iLUMxHhegyATOfrg/o+uQ2cgGeI8WGxG2bNOjdZW42QAe3dmUkZ+EGVyf2YVYx6dOIrzJF1fXtonfT0t+ba5GQW8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=AjFzeoGA; arc=none smtp.client-ip=192.198.163.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AjFzeoGA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1782482529; x=1814018529; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t+344il5kS+1UwLrPedrEucQtxevDKH1A2BfGnBb1lw=; b=AjFzeoGAM2ALF7fKvvZK1o498PwICmmgTS2bUWfUQuefwb64C/aYh2xr +xbRELCQTwPThcVqb8CEddkFPx7KHmr+8hxbUzJyE8Dm/9pwAYFJUo3KR LuKk5OhW6pAEHAdcFIu/Fuk5fvn8w5oHvBxM1KgmRKBf8sSe8vXOkdOym qBYb40NVQEgzH/AOrkngxdAAIMq/oI2vfGgA48V0Fk50mRfzBobhTk/z6 8oo8iRi8BnLIDaxYQPTC6tnDpCvjIPN45+H+hHJkPfFRUuyZZxxJngYg2 27mQBFOEU+kz1V2iHLWkA7h7FMKSyUiuVKh4wGyoRJI0JXz4IILRIwQ7H w==; X-CSE-ConnectionGUID: 9PkAeMI5RGiXQKsLIxjpew== X-CSE-MsgGUID: G642qIMWRfmTf7erCN1ypg== X-IronPort-AV: E=McAfee;i="6800,10657,11829"; a="100823943" X-IronPort-AV: E=Sophos;i="6.24,226,1774335600"; d="scan'208";a="100823943" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2026 07:02:08 -0700 X-CSE-ConnectionGUID: LfcSOjl3Rm+NdrhZBErWOQ== X-CSE-MsgGUID: 6cZ9xckeTgiQ7DWuFsBjRQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,226,1774335600"; d="scan'208";a="249666229" Received: from pgcooper-mobl3.ger.corp.intel.com (HELO localhost) ([10.245.244.22]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2026 07:02:06 -0700 From: Jani Nikula To: Jani Nikula , intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: Martin Hodo , stable@vger.kernel.org, Animesh Manna , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , =?UTF-8?q?Micha=C5=82=20Grzelak?= Subject: [PATCH v2] drm/i915/bios: range check LFP Data Block panel_type2 Date: Fri, 26 Jun 2026 17:01:55 +0300 Message-ID: <20260626140155.1389655-1-jani.nikula@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260625135130.1067872-1-jani.nikula@intel.com> References: <20260625135130.1067872-1-jani.nikula@intel.com> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs Bertel Jungin Aukio 5, 02600 Espoo, Finland Content-Transfer-Encoding: 8bit While the panel_type from LFP Data Block is range checked, panel_type2 is not. Add a few helpers for range checking, and use them to not only check panel_type2, but also improve clarity and correctness in the panel type selection. Discovered using AI-assisted static analysis confirmed by Intel Product Security. v2: - Fix commit message typo (Michał) - Add is_panel_type_pnp() (Ville) Reported-by: Martin Hodo Fixes: 6434cf630086 ("drm/i915/bios: calculate panel type as per child device index in VBT") Cc: # v6.0+ Cc: Animesh Manna Cc: Ville Syrjälä Reviewed-by: Michał Grzelak # v1 Signed-off-by: Jani Nikula --- drivers/gpu/drm/i915/display/intel_bios.c | 36 ++++++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c index 15ebadc72b88..97cbae2e547e 100644 --- a/drivers/gpu/drm/i915/display/intel_bios.c +++ b/drivers/gpu/drm/i915/display/intel_bios.c @@ -623,6 +623,21 @@ get_lfp_data_tail(const struct bdb_lfp_data *data, return NULL; } +static bool is_panel_type_valid(int panel_type) +{ + return panel_type >= 0 && panel_type < 16; +} + +static bool is_panel_type_pnp(int panel_type) +{ + return panel_type == 0xff; +} + +static bool is_panel_type_valid_or_pnp(int panel_type) +{ + return is_panel_type_valid(panel_type) || is_panel_type_pnp(panel_type); +} + static int opregion_get_panel_type(struct intel_display *display, const struct intel_bios_encoder_data *devdata, const struct drm_edid *drm_edid, bool use_fallback) @@ -640,15 +655,21 @@ static int vbt_get_panel_type(struct intel_display *display, if (!lfp_options) return -1; - if (lfp_options->panel_type > 0xf && - lfp_options->panel_type != 0xff) { + if (!is_panel_type_valid_or_pnp(lfp_options->panel_type)) { drm_dbg_kms(display->drm, "Invalid VBT panel type 0x%x\n", lfp_options->panel_type); return -1; } - if (devdata && devdata->child.handle == DEVICE_HANDLE_LFP2) + if (devdata && devdata->child.handle == DEVICE_HANDLE_LFP2) { + if (!is_panel_type_valid_or_pnp(lfp_options->panel_type2)) { + drm_dbg_kms(display->drm, "Invalid VBT panel type 2 0x%x\n", + lfp_options->panel_type2); + return -1; + } + return lfp_options->panel_type2; + } drm_WARN_ON(display->drm, devdata && devdata->child.handle != DEVICE_HANDLE_LFP1); @@ -762,13 +783,12 @@ static int get_panel_type(struct intel_display *display, panel_types[i].name, panel_types[i].panel_type); } - if (panel_types[PANEL_TYPE_OPREGION].panel_type >= 0) + if (is_panel_type_valid(panel_types[PANEL_TYPE_OPREGION].panel_type)) i = PANEL_TYPE_OPREGION; - else if (panel_types[PANEL_TYPE_VBT].panel_type == 0xff && - panel_types[PANEL_TYPE_PNPID].panel_type >= 0) + else if (is_panel_type_pnp(panel_types[PANEL_TYPE_VBT].panel_type) && + is_panel_type_valid(panel_types[PANEL_TYPE_PNPID].panel_type)) i = PANEL_TYPE_PNPID; - else if (panel_types[PANEL_TYPE_VBT].panel_type != 0xff && - panel_types[PANEL_TYPE_VBT].panel_type >= 0) + else if (is_panel_type_valid(panel_types[PANEL_TYPE_VBT].panel_type)) i = PANEL_TYPE_VBT; else i = PANEL_TYPE_FALLBACK; -- 2.47.3