Commit 4378daf5 authored by Lukasz Majczak's avatar Lukasz Majczak Committed by José Roberto de Souza
Browse files

drm/i915/bdb: Fix version check



With patch "drm/i915/vbt: Fix backlight parsing for VBT 234+"
the size of bdb_lfp_backlight_data structure has been increased,
causing if-statement in the parse_lfp_backlight function
that comapres this structure size to the one retrieved from BDB,
always to fail for older revisions.
This patch calculates expected size of the structure for a given
BDB version and compares it with the value gathered from BDB.
Tested on Chromebook Pixelbook (Nocturne) (reports bdb->version = 221)

Fixes: d381baad ("drm/i915/vbt: Fix backlight parsing for VBT 234+")

Tested-by: default avatarLukasz Majczak <lma@semihalf.com>
Signed-off-by: default avatarLukasz Majczak <lma@semihalf.com>
Reviewed-by: default avatarJosé Roberto de Souza <jose.souza@intel.com>
Signed-off-by: default avatarJosé Roberto de Souza <jose.souza@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210930134606.227234-1-lma@semihalf.com
parent f0b6b01b
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -451,14 +451,24 @@ parse_lfp_backlight(struct drm_i915_private *i915,
	}

	i915->vbt.backlight.type = INTEL_BACKLIGHT_DISPLAY_DDI;
	if (bdb->version >= 191 &&
	    get_blocksize(backlight_data) >= sizeof(*backlight_data)) {
	if (bdb->version >= 191) {
		size_t exp_size;

		if (bdb->version >= 236)
			exp_size = sizeof(struct bdb_lfp_backlight_data);
		else if (bdb->version >= 234)
			exp_size = EXP_BDB_LFP_BL_DATA_SIZE_REV_234;
		else
			exp_size = EXP_BDB_LFP_BL_DATA_SIZE_REV_191;

		if (get_blocksize(backlight_data) >= exp_size) {
			const struct lfp_backlight_control_method *method;

			method = &backlight_data->backlight_control[panel_type];
			i915->vbt.backlight.type = method->type;
			i915->vbt.backlight.controller = method->controller;
		}
	}

	i915->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz;
	i915->vbt.backlight.active_low_pwm = entry->active_low_pwm;
+5 −0
Original line number Diff line number Diff line
@@ -814,6 +814,11 @@ struct lfp_brightness_level {
	u16 reserved;
} __packed;

#define EXP_BDB_LFP_BL_DATA_SIZE_REV_191 \
	offsetof(struct bdb_lfp_backlight_data, brightness_level)
#define EXP_BDB_LFP_BL_DATA_SIZE_REV_234 \
	offsetof(struct bdb_lfp_backlight_data, brightness_precision_bits)

struct bdb_lfp_backlight_data {
	u8 entry_size;
	struct lfp_backlight_data_entry data[16];