* [PATCH] usb: typec: altmode: Fix typec_altmode_get_partner sometimes returning an invalid pointer
@ 2020-04-22 14:43 Hans de Goede
2020-04-23 10:19 ` Heikki Krogerus
0 siblings, 1 reply; 2+ messages in thread
From: Hans de Goede @ 2020-04-22 14:43 UTC (permalink / raw)
To: Greg Kroah-Hartman, Heikki Krogerus
Cc: Hans de Goede, linux-usb, Naoki Kiryu, stable
From: Naoki Kiryu <naonaokiryu2@gmail.com>
Before this commit, typec_altmode_get_partner would return a
const struct typec_altmode * pointing to address 0x08 when
to_altmode(adev)->partner was NULL.
Add a check for to_altmode(adev)->partner being NULL to fix this.
BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=206365
BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1785972
Fixes: 5f54a85db5df ("usb: typec: Make sure an alt mode exist before getting its partner")
Cc: stable@vger.kernel.org
Signed-off-by: Naoki Kiryu <naonaokiryu2@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/usb/typec/bus.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c
index c823122f9cb7..e8ddb81cb6df 100644
--- a/drivers/usb/typec/bus.c
+++ b/drivers/usb/typec/bus.c
@@ -198,7 +198,10 @@ EXPORT_SYMBOL_GPL(typec_altmode_vdm);
const struct typec_altmode *
typec_altmode_get_partner(struct typec_altmode *adev)
{
- return adev ? &to_altmode(adev)->partner->adev : NULL;
+ if (!adev || !to_altmode(adev)->partner)
+ return NULL;
+
+ return &to_altmode(adev)->partner->adev;
}
EXPORT_SYMBOL_GPL(typec_altmode_get_partner);
--
2.26.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: typec: altmode: Fix typec_altmode_get_partner sometimes returning an invalid pointer
2020-04-22 14:43 [PATCH] usb: typec: altmode: Fix typec_altmode_get_partner sometimes returning an invalid pointer Hans de Goede
@ 2020-04-23 10:19 ` Heikki Krogerus
0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2020-04-23 10:19 UTC (permalink / raw)
To: Hans de Goede; +Cc: Greg Kroah-Hartman, linux-usb, Naoki Kiryu, stable
On Wed, Apr 22, 2020 at 04:43:45PM +0200, Hans de Goede wrote:
> From: Naoki Kiryu <naonaokiryu2@gmail.com>
>
> Before this commit, typec_altmode_get_partner would return a
> const struct typec_altmode * pointing to address 0x08 when
> to_altmode(adev)->partner was NULL.
>
> Add a check for to_altmode(adev)->partner being NULL to fix this.
>
> BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=206365
> BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1785972
> Fixes: 5f54a85db5df ("usb: typec: Make sure an alt mode exist before getting its partner")
> Cc: stable@vger.kernel.org
> Signed-off-by: Naoki Kiryu <naonaokiryu2@gmail.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> drivers/usb/typec/bus.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c
> index c823122f9cb7..e8ddb81cb6df 100644
> --- a/drivers/usb/typec/bus.c
> +++ b/drivers/usb/typec/bus.c
> @@ -198,7 +198,10 @@ EXPORT_SYMBOL_GPL(typec_altmode_vdm);
> const struct typec_altmode *
> typec_altmode_get_partner(struct typec_altmode *adev)
> {
> - return adev ? &to_altmode(adev)->partner->adev : NULL;
> + if (!adev || !to_altmode(adev)->partner)
> + return NULL;
> +
> + return &to_altmode(adev)->partner->adev;
> }
> EXPORT_SYMBOL_GPL(typec_altmode_get_partner);
>
> --
> 2.26.0
thanks,
--
heikki
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-04-23 10:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-22 14:43 [PATCH] usb: typec: altmode: Fix typec_altmode_get_partner sometimes returning an invalid pointer Hans de Goede
2020-04-23 10:19 ` Heikki Krogerus
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.