Re: [PATCH] drm/i915/bios: Move a variable assignment behind a null pointer check in intel_bios_encoder_supports_dp_dual_mode()

Markus Elfring <[email protected]> Tue, 28 Jul 2026 14:15:12 +0200
Newsgroups gmane.linux.kernel,gmane.comp.freedesktop.xorg.drivers.intel,gmane.comp.video.dri.devel,gmane.linux.kernel.janitors
Message-ID <[email protected]>
>> The address of a data structure member was determined before
>> a corresponding null pointer check in the implementation of
>> the function =E2=80=9Cintel_bios_encoder_supports_dp_dual_mode=E2=80=9D=
.
>>
>> Thus avoid the risk for undefined behaviour by reducing the scope for
>> the variable =E2=80=9Cchild=E2=80=9D behind condition checks.
=E2=80=A6
>> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
>> @@ -3514,8 +3514,6 @@ bool intel_bios_is_port_present(struct intel_disp=
lay *display, enum port port)
>> =20
>>  bool intel_bios_encoder_supports_dp_dual_mode(const struct intel_bios_=
encoder_data *devdata)
>>  {
>> -	const struct child_device_config *child =3D &devdata->child;
>> -
>>  	if (!devdata)
>>  		return false;
>> =20
>> @@ -3523,6 +3521,8 @@ bool intel_bios_encoder_supports_dp_dual_mode(con=
st struct intel_bios_encoder_da
>>  	    !intel_bios_encoder_supports_hdmi(devdata))
>>  		return false;
>> =20
>> +	const struct child_device_config *child =3D &devdata->child;
>> +
>=20
> does it compile?
>=20
> please keep the variable definition where it is and move only its
> assignment after the null check.
Would you find the proposed adjustment more acceptable if a bit of source =
code
would be moved into another function?
https://refactoring.com/catalog/extractFunction.html

Regards,
Markus