Re: [PATCH v1] usb: typec: ucsi: displayport: Fix OOB altmode array index

From: Jameson Thies

Date: Tue Sep 01 2026 - 21:16:51 EST


Hi Heikki and Andrei,
thanks for taking a look. I'll follow up with a v2 of this patch to
address your comments. Answers below with some additional comments.

> > Can you remove the above line while at it?

Will remove in v2.

> > Shouldn't that be the other way around?

I'm not sure I understand. Because UCSI_MAX_ALTMODES is set to 30 in
ucsi.h, verifying 'cur' is less than UCSI_MAX_ALTMODES will still
evaluate to false if 'cur' is 0xff. This update maintains the existing
functionality and prevents the driver from using an out of bounds
index.

> Looks fine, but shouldn't we return an error if an invalid value is
> received, similar to the Thunderbolt implementation?

Sounds good to me, but I think we should split up the
UCSI_MAX_ALTMODES check and the port_altmode check. Returning EBUSY
doesn't seem like an appropriate error code if the PPM returns an out
of range option. I think we should return EINVAL here.