All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] usb: typec: altmodes/displayport: verify compatible source/sink role combination
@ 2023-10-16 22:56 RD Babiera
  2023-10-17 21:33 ` Prashant Malani
  0 siblings, 1 reply; 3+ messages in thread
From: RD Babiera @ 2023-10-16 22:56 UTC (permalink / raw)
  To: heikki.krogerus, gregkh
  Cc: badhri, linux-usb, linux-kernel, RD Babiera, stable

DisplayPort Alt Mode CTS test 10.3.8 states that both sides of the
connection shall be compatible with one another such that the connection
is not Source to Source or Sink to Sink.

The DisplayPort driver currently checks for a compatible pin configuration
that resolves into a source and sink combination. The CTS test is designed
to send a Discover Modes message that has a compatible pin configuration
but advertises the same port capability as the device; the current check
fails this.

Verify that the port and port partner resolve into a valid source and sink
combination before checking for a compatible pin configuration.

Fixes: 0e3bb7d6894d ("usb: typec: Add driver for DisplayPort alternate mode")
Cc: stable@vger.kernel.org
Signed-off-by: RD Babiera <rdbabiera@google.com>
---
 drivers/usb/typec/altmodes/displayport.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
index 718da02036d8..3b35a6b8cb72 100644
--- a/drivers/usb/typec/altmodes/displayport.c
+++ b/drivers/usb/typec/altmodes/displayport.c
@@ -575,9 +575,18 @@ int dp_altmode_probe(struct typec_altmode *alt)
 	struct fwnode_handle *fwnode;
 	struct dp_altmode *dp;
 	int ret;
+	int port_cap, partner_cap;
 
 	/* FIXME: Port can only be DFP_U. */
 
+	/* Make sure that the port and partner can resolve into source and sink */
+	port_cap = DP_CAP_CAPABILITY(port->vdo);
+	partner_cap = DP_CAP_CAPABILITY(alt->vdo);
+	if (!((port_cap & DP_CAP_DFP_D) && (partner_cap & DP_CAP_UFP_D)) &&
+	    !((port_cap & DP_CAP_UFP_D) && (partner_cap & DP_CAP_DFP_D))) {
+		return -ENODEV;
+	}
+
 	/* Make sure we have compatiple pin configurations */
 	if (!(DP_CAP_PIN_ASSIGN_DFP_D(port->vdo) &
 	      DP_CAP_PIN_ASSIGN_UFP_D(alt->vdo)) &&

base-commit: d0d27ef87e1ca974ed93ed4f7d3c123cbd392ba6
-- 
2.42.0.655.g421f12c284-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] usb: typec: altmodes/displayport: verify compatible source/sink role combination
  2023-10-16 22:56 [PATCH v1] usb: typec: altmodes/displayport: verify compatible source/sink role combination RD Babiera
@ 2023-10-17 21:33 ` Prashant Malani
  2023-10-18 20:06   ` RD Babiera
  0 siblings, 1 reply; 3+ messages in thread
From: Prashant Malani @ 2023-10-17 21:33 UTC (permalink / raw)
  To: RD Babiera
  Cc: heikki.krogerus, gregkh, badhri, linux-usb, linux-kernel, stable

Hi RD,

On Mon, Oct 16, 2023 at 3:56 PM RD Babiera <rdbabiera@google.com> wrote:
>
> DisplayPort Alt Mode CTS test 10.3.8 states that both sides of the
> connection shall be compatible with one another such that the connection
> is not Source to Source or Sink to Sink.
>
> The DisplayPort driver currently checks for a compatible pin configuration
> that resolves into a source and sink combination. The CTS test is designed
> to send a Discover Modes message that has a compatible pin configuration
> but advertises the same port capability as the device; the current check
> fails this.
>
> Verify that the port and port partner resolve into a valid source and sink
> combination before checking for a compatible pin configuration.
>
> Fixes: 0e3bb7d6894d ("usb: typec: Add driver for DisplayPort alternate mode")
> Cc: stable@vger.kernel.org
> Signed-off-by: RD Babiera <rdbabiera@google.com>
> ---
>  drivers/usb/typec/altmodes/displayport.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
> index 718da02036d8..3b35a6b8cb72 100644
> --- a/drivers/usb/typec/altmodes/displayport.c
> +++ b/drivers/usb/typec/altmodes/displayport.c
> @@ -575,9 +575,18 @@ int dp_altmode_probe(struct typec_altmode *alt)
>         struct fwnode_handle *fwnode;
>         struct dp_altmode *dp;
>         int ret;
> +       int port_cap, partner_cap;

VDOs are 32-bit, so u32 is probably better here.

>
>         /* FIXME: Port can only be DFP_U. */
>
> +       /* Make sure that the port and partner can resolve into source and sink */
> +       port_cap = DP_CAP_CAPABILITY(port->vdo);
> +       partner_cap = DP_CAP_CAPABILITY(alt->vdo);
> +       if (!((port_cap & DP_CAP_DFP_D) && (partner_cap & DP_CAP_UFP_D)) &&

nit: bitwise '&' has a higher precedence than logical '&&', so the
innermost parentheses shouldn't be necessary:

           if (!(port_cap & DP_CAP_DFP_D && partner_cap & DP_CAP_UFP_D) &&
               !(port_cap & DP_CAP_UFP_D && partner_cap & DP_CAP_DFP_D))
                   return -ENODEV;
                ...

OTOH, perhaps you should just introduce a macro that performs this
bitwise operation for even better
readability. Something like

#define DP_CAP_IS_DFP_D(_cap_)        (!!(DP_CAP_CAPABILITY(_cap_) &
DP_CAP_DFP_D))

(not sure if "!!" is tolerated in kernel style, but you get the gist...)


> +           !((port_cap & DP_CAP_UFP_D) && (partner_cap & DP_CAP_DFP_D))) {
> +               return -ENODEV;

Single line if statements can drop curly braces [1]

Best regards,

-Prashant

[1] https://www.kernel.org/doc/html/v4.10/process/coding-style.html#placing-braces-and-spaces

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] usb: typec: altmodes/displayport: verify compatible source/sink role combination
  2023-10-17 21:33 ` Prashant Malani
@ 2023-10-18 20:06   ` RD Babiera
  0 siblings, 0 replies; 3+ messages in thread
From: RD Babiera @ 2023-10-18 20:06 UTC (permalink / raw)
  To: Prashant Malani
  Cc: heikki.krogerus, gregkh, badhri, linux-usb, linux-kernel, stable

On Tue, Oct 17, 2023 at 2:33 PM Prashant Malani <pmalani@chromium.org> wrote:
> OTOH, perhaps you should just introduce a macro that performs this
> bitwise operation for even better
> readability. Something like
>
> #define DP_CAP_IS_DFP_D(_cap_)        (!!(DP_CAP_CAPABILITY(_cap_) &
> DP_CAP_DFP_D))

I'll take this approach, thanks for the feedback Prashant!

---

Best,
RD

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-18 20:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-16 22:56 [PATCH v1] usb: typec: altmodes/displayport: verify compatible source/sink role combination RD Babiera
2023-10-17 21:33 ` Prashant Malani
2023-10-18 20:06   ` RD Babiera

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.