2021-05-19 19:26:43

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v2 1/1] usb: typec: tcpm: Use LE to CPU conversion when accessing msg->header

Sparse is not happy about strict type handling:
.../typec/tcpm/tcpm.c:2720:27: warning: restricted __le16 degrades to integer
.../typec/tcpm/tcpm.c:2814:32: warning: restricted __le16 degrades to integer

Fix this by converting LE to CPU before use.

Fixes: ae8a2ca8a221 ("usb: typec: Group all TCPCI/TCPM code together")
Fixes: 64f7c494a3c0 ("typec: tcpm: Add support for sink PPS related messages")
Cc: Adam Thomson <[email protected]>
Signed-off-by: Andy Shevchenko <[email protected]>
---
v2: fixed subject prefix
drivers/usb/typec/tcpm/tcpm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 64133e586c64..8fdfd7f65ad7 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -2717,7 +2717,7 @@ static void tcpm_pd_ext_msg_request(struct tcpm_port *port,
enum pd_ext_msg_type type = pd_header_type_le(msg->header);
unsigned int data_size = pd_ext_header_data_size_le(msg->ext_msg.header);

- if (!(msg->ext_msg.header & PD_EXT_HDR_CHUNKED)) {
+ if (!(le16_to_cpu(msg->ext_msg.header) & PD_EXT_HDR_CHUNKED)) {
tcpm_pd_handle_msg(port, PD_MSG_CTRL_NOT_SUPP, NONE_AMS);
tcpm_log(port, "Unchunked extended messages unsupported");
return;
@@ -2811,7 +2811,7 @@ static void tcpm_pd_rx_handler(struct kthread_work *work)
"Data role mismatch, initiating error recovery");
tcpm_set_state(port, ERROR_RECOVERY, 0);
} else {
- if (msg->header & PD_HEADER_EXT_HDR)
+ if (le16_to_cpu(msg->header) & PD_HEADER_EXT_HDR)
tcpm_pd_ext_msg_request(port, msg);
else if (cnt)
tcpm_pd_data_request(port, msg);
--
2.30.2



2021-05-19 20:21:20

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] usb: typec: tcpm: Use LE to CPU conversion when accessing msg->header

On 5/19/21 3:03 AM, Andy Shevchenko wrote:
> Sparse is not happy about strict type handling:
> .../typec/tcpm/tcpm.c:2720:27: warning: restricted __le16 degrades to integer
> .../typec/tcpm/tcpm.c:2814:32: warning: restricted __le16 degrades to integer
>
> Fix this by converting LE to CPU before use.
>
> Fixes: ae8a2ca8a221 ("usb: typec: Group all TCPCI/TCPM code together")
> Fixes: 64f7c494a3c0 ("typec: tcpm: Add support for sink PPS related messages")
> Cc: Adam Thomson <[email protected]>
> Signed-off-by: Andy Shevchenko <[email protected]>

Reviewed-by: Guenter Roeck <[email protected]>

> ---
> v2: fixed subject prefix
> drivers/usb/typec/tcpm/tcpm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 64133e586c64..8fdfd7f65ad7 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -2717,7 +2717,7 @@ static void tcpm_pd_ext_msg_request(struct tcpm_port *port,
> enum pd_ext_msg_type type = pd_header_type_le(msg->header);
> unsigned int data_size = pd_ext_header_data_size_le(msg->ext_msg.header);
>
> - if (!(msg->ext_msg.header & PD_EXT_HDR_CHUNKED)) {
> + if (!(le16_to_cpu(msg->ext_msg.header) & PD_EXT_HDR_CHUNKED)) {
> tcpm_pd_handle_msg(port, PD_MSG_CTRL_NOT_SUPP, NONE_AMS);
> tcpm_log(port, "Unchunked extended messages unsupported");
> return;
> @@ -2811,7 +2811,7 @@ static void tcpm_pd_rx_handler(struct kthread_work *work)
> "Data role mismatch, initiating error recovery");
> tcpm_set_state(port, ERROR_RECOVERY, 0);
> } else {
> - if (msg->header & PD_HEADER_EXT_HDR)
> + if (le16_to_cpu(msg->header) & PD_HEADER_EXT_HDR)
> tcpm_pd_ext_msg_request(port, msg);
> else if (cnt)
> tcpm_pd_data_request(port, msg);
>


2021-05-20 16:38:37

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] usb: typec: tcpm: Use LE to CPU conversion when accessing msg->header

On Wed, May 19, 2021 at 01:03:58PM +0300, Andy Shevchenko wrote:
> Sparse is not happy about strict type handling:
> .../typec/tcpm/tcpm.c:2720:27: warning: restricted __le16 degrades to integer
> .../typec/tcpm/tcpm.c:2814:32: warning: restricted __le16 degrades to integer
>
> Fix this by converting LE to CPU before use.
>
> Fixes: ae8a2ca8a221 ("usb: typec: Group all TCPCI/TCPM code together")
> Fixes: 64f7c494a3c0 ("typec: tcpm: Add support for sink PPS related messages")
> Cc: Adam Thomson <[email protected]>
> Signed-off-by: Andy Shevchenko <[email protected]>

Reviewed-by: Heikki Krogerus <[email protected]>

> ---
> v2: fixed subject prefix
> drivers/usb/typec/tcpm/tcpm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 64133e586c64..8fdfd7f65ad7 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -2717,7 +2717,7 @@ static void tcpm_pd_ext_msg_request(struct tcpm_port *port,
> enum pd_ext_msg_type type = pd_header_type_le(msg->header);
> unsigned int data_size = pd_ext_header_data_size_le(msg->ext_msg.header);
>
> - if (!(msg->ext_msg.header & PD_EXT_HDR_CHUNKED)) {
> + if (!(le16_to_cpu(msg->ext_msg.header) & PD_EXT_HDR_CHUNKED)) {
> tcpm_pd_handle_msg(port, PD_MSG_CTRL_NOT_SUPP, NONE_AMS);
> tcpm_log(port, "Unchunked extended messages unsupported");
> return;
> @@ -2811,7 +2811,7 @@ static void tcpm_pd_rx_handler(struct kthread_work *work)
> "Data role mismatch, initiating error recovery");
> tcpm_set_state(port, ERROR_RECOVERY, 0);
> } else {
> - if (msg->header & PD_HEADER_EXT_HDR)
> + if (le16_to_cpu(msg->header) & PD_HEADER_EXT_HDR)
> tcpm_pd_ext_msg_request(port, msg);
> else if (cnt)
> tcpm_pd_data_request(port, msg);
> --
> 2.30.2

--
heikki

2021-05-21 20:10:12

by Adam Thomson

[permalink] [raw]
Subject: RE: [PATCH v2 1/1] usb: typec: tcpm: Use LE to CPU conversion when accessing msg->header

On 19 May 2021 11:04, Andy Shevchenko wrote:

> Sparse is not happy about strict type handling:
> .../typec/tcpm/tcpm.c:2720:27: warning: restricted __le16 degrades to integer
> .../typec/tcpm/tcpm.c:2814:32: warning: restricted __le16 degrades to integer
>
> Fix this by converting LE to CPU before use.
>
> Fixes: ae8a2ca8a221 ("usb: typec: Group all TCPCI/TCPM code together")
> Fixes: 64f7c494a3c0 ("typec: tcpm: Add support for sink PPS related messages")
> Cc: Adam Thomson <[email protected]>
> Signed-off-by: Andy Shevchenko <[email protected]>

Reviewed-by: Adam Thomson <[email protected]>

> ---
> v2: fixed subject prefix
> drivers/usb/typec/tcpm/tcpm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 64133e586c64..8fdfd7f65ad7 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -2717,7 +2717,7 @@ static void tcpm_pd_ext_msg_request(struct
> tcpm_port *port,
> enum pd_ext_msg_type type = pd_header_type_le(msg->header);
> unsigned int data_size = pd_ext_header_data_size_le(msg-
> >ext_msg.header);
>
> - if (!(msg->ext_msg.header & PD_EXT_HDR_CHUNKED)) {
> + if (!(le16_to_cpu(msg->ext_msg.header) & PD_EXT_HDR_CHUNKED)) {
> tcpm_pd_handle_msg(port, PD_MSG_CTRL_NOT_SUPP,
> NONE_AMS);
> tcpm_log(port, "Unchunked extended messages unsupported");
> return;
> @@ -2811,7 +2811,7 @@ static void tcpm_pd_rx_handler(struct kthread_work
> *work)
> "Data role mismatch, initiating error recovery");
> tcpm_set_state(port, ERROR_RECOVERY, 0);
> } else {
> - if (msg->header & PD_HEADER_EXT_HDR)
> + if (le16_to_cpu(msg->header) & PD_HEADER_EXT_HDR)
> tcpm_pd_ext_msg_request(port, msg);
> else if (cnt)
> tcpm_pd_data_request(port, msg);
> --
> 2.30.2