* [PATCH v1] usb: typec: ucsi: Only set number of plug altmodes after registration
@ 2024-06-25 0:46 Jameson Thies
2024-06-25 0:50 ` Benson Leung
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jameson Thies @ 2024-06-25 0:46 UTC (permalink / raw)
To: heikki.krogerus, linux-usb
Cc: jthies, jonathanh, bleung, abhishekpandit, andersson,
dmitry.baryshkov, fabrice.gasnier, gregkh, hdegoede,
neil.armstrong, rajaram.regupathy, saranya.gopal, linux-kernel
Move the setting of the plug's number of alternate modes into the
same condition as the plug's registration to prevent dereferencing the
connector's plug pointer while it is null.
Fixes: c313a44ac9cd ("usb: typec: ucsi: Always set number of alternate modes")
Suggested-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Jameson Thies <jthies@google.com>
---
drivers/usb/typec/ucsi/ucsi.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 76c48d873b2a..77e46bf4a098 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1180,13 +1180,13 @@ static int ucsi_check_cable(struct ucsi_connector *con)
ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
if (ret < 0)
return ret;
- }
- if (con->plug_altmode[0]) {
- num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
- typec_plug_set_num_altmodes(con->plug, num_plug_am);
- } else {
- typec_plug_set_num_altmodes(con->plug, 0);
+ if (con->plug_altmode[0]) {
+ num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
+ typec_plug_set_num_altmodes(con->plug, num_plug_am);
+ } else {
+ typec_plug_set_num_altmodes(con->plug, 0);
+ }
}
return 0;
base-commit: 819984a0dd3606b7c46fe156cd56a0dc0d604788
--
2.45.2.741.gdbec12cfda-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v1] usb: typec: ucsi: Only set number of plug altmodes after registration
2024-06-25 0:46 [PATCH v1] usb: typec: ucsi: Only set number of plug altmodes after registration Jameson Thies
@ 2024-06-25 0:50 ` Benson Leung
2024-06-25 10:55 ` Jon Hunter
2024-06-25 14:32 ` Heikki Krogerus
2 siblings, 0 replies; 4+ messages in thread
From: Benson Leung @ 2024-06-25 0:50 UTC (permalink / raw)
To: Jameson Thies
Cc: heikki.krogerus, linux-usb, jonathanh, abhishekpandit, andersson,
dmitry.baryshkov, fabrice.gasnier, gregkh, hdegoede,
neil.armstrong, rajaram.regupathy, saranya.gopal, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1614 bytes --]
Hi Jameson,
On Tue, Jun 25, 2024 at 12:46:07AM +0000, Jameson Thies wrote:
> Move the setting of the plug's number of alternate modes into the
> same condition as the plug's registration to prevent dereferencing the
> connector's plug pointer while it is null.
>
> Fixes: c313a44ac9cd ("usb: typec: ucsi: Always set number of alternate modes")
> Suggested-by: Jon Hunter <jonathanh@nvidia.com>
> Signed-off-by: Jameson Thies <jthies@google.com>
Reviewed-by: Benson Leung <bleung@chromium.org>
Thanks,
Benson
> ---
> drivers/usb/typec/ucsi/ucsi.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 76c48d873b2a..77e46bf4a098 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1180,13 +1180,13 @@ static int ucsi_check_cable(struct ucsi_connector *con)
> ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
> if (ret < 0)
> return ret;
> - }
>
> - if (con->plug_altmode[0]) {
> - num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
> - typec_plug_set_num_altmodes(con->plug, num_plug_am);
> - } else {
> - typec_plug_set_num_altmodes(con->plug, 0);
> + if (con->plug_altmode[0]) {
> + num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
> + typec_plug_set_num_altmodes(con->plug, num_plug_am);
> + } else {
> + typec_plug_set_num_altmodes(con->plug, 0);
> + }
> }
>
> return 0;
>
> base-commit: 819984a0dd3606b7c46fe156cd56a0dc0d604788
> --
> 2.45.2.741.gdbec12cfda-goog
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] usb: typec: ucsi: Only set number of plug altmodes after registration
2024-06-25 0:46 [PATCH v1] usb: typec: ucsi: Only set number of plug altmodes after registration Jameson Thies
2024-06-25 0:50 ` Benson Leung
@ 2024-06-25 10:55 ` Jon Hunter
2024-06-25 14:32 ` Heikki Krogerus
2 siblings, 0 replies; 4+ messages in thread
From: Jon Hunter @ 2024-06-25 10:55 UTC (permalink / raw)
To: Jameson Thies, heikki.krogerus, linux-usb
Cc: bleung, abhishekpandit, andersson, dmitry.baryshkov,
fabrice.gasnier, gregkh, hdegoede, neil.armstrong,
rajaram.regupathy, saranya.gopal, linux-kernel,
linux-tegra@vger.kernel.org
On 25/06/2024 01:46, Jameson Thies wrote:
> Move the setting of the plug's number of alternate modes into the
> same condition as the plug's registration to prevent dereferencing the
> connector's plug pointer while it is null.
>
> Fixes: c313a44ac9cd ("usb: typec: ucsi: Always set number of alternate modes")
> Suggested-by: Jon Hunter <jonathanh@nvidia.com>
> Signed-off-by: Jameson Thies <jthies@google.com>
> ---
> drivers/usb/typec/ucsi/ucsi.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 76c48d873b2a..77e46bf4a098 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1180,13 +1180,13 @@ static int ucsi_check_cable(struct ucsi_connector *con)
> ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
> if (ret < 0)
> return ret;
> - }
>
> - if (con->plug_altmode[0]) {
> - num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
> - typec_plug_set_num_altmodes(con->plug, num_plug_am);
> - } else {
> - typec_plug_set_num_altmodes(con->plug, 0);
> + if (con->plug_altmode[0]) {
> + num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
> + typec_plug_set_num_altmodes(con->plug, num_plug_am);
> + } else {
> + typec_plug_set_num_altmodes(con->plug, 0);
> + }
> }
>
> return 0;
>
> base-commit: 819984a0dd3606b7c46fe156cd56a0dc0d604788
Fixes it for me!
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Reviewed-by: Jon Hunter <jonathanh@nvidia.com>
Thanks!
Jon
--
nvpublic
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] usb: typec: ucsi: Only set number of plug altmodes after registration
2024-06-25 0:46 [PATCH v1] usb: typec: ucsi: Only set number of plug altmodes after registration Jameson Thies
2024-06-25 0:50 ` Benson Leung
2024-06-25 10:55 ` Jon Hunter
@ 2024-06-25 14:32 ` Heikki Krogerus
2 siblings, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2024-06-25 14:32 UTC (permalink / raw)
To: Jameson Thies
Cc: linux-usb, jonathanh, bleung, abhishekpandit, andersson,
dmitry.baryshkov, fabrice.gasnier, gregkh, hdegoede,
neil.armstrong, rajaram.regupathy, saranya.gopal, linux-kernel
On Tue, Jun 25, 2024 at 12:46:07AM +0000, Jameson Thies wrote:
> Move the setting of the plug's number of alternate modes into the
> same condition as the plug's registration to prevent dereferencing the
> connector's plug pointer while it is null.
>
> Fixes: c313a44ac9cd ("usb: typec: ucsi: Always set number of alternate modes")
> Suggested-by: Jon Hunter <jonathanh@nvidia.com>
> Signed-off-by: Jameson Thies <jthies@google.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> drivers/usb/typec/ucsi/ucsi.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 76c48d873b2a..77e46bf4a098 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1180,13 +1180,13 @@ static int ucsi_check_cable(struct ucsi_connector *con)
> ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
> if (ret < 0)
> return ret;
> - }
>
> - if (con->plug_altmode[0]) {
> - num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
> - typec_plug_set_num_altmodes(con->plug, num_plug_am);
> - } else {
> - typec_plug_set_num_altmodes(con->plug, 0);
> + if (con->plug_altmode[0]) {
> + num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
> + typec_plug_set_num_altmodes(con->plug, num_plug_am);
> + } else {
> + typec_plug_set_num_altmodes(con->plug, 0);
> + }
> }
>
> return 0;
>
> base-commit: 819984a0dd3606b7c46fe156cd56a0dc0d604788
> --
> 2.45.2.741.gdbec12cfda-goog
--
heikki
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-06-25 14:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-25 0:46 [PATCH v1] usb: typec: ucsi: Only set number of plug altmodes after registration Jameson Thies
2024-06-25 0:50 ` Benson Leung
2024-06-25 10:55 ` Jon Hunter
2024-06-25 14:32 ` Heikki Krogerus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox