From: Maxim Korotkov <korotkov.maxim.s@gmail.com>
To: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Maxim Korotkov <korotkov.maxim.s@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
lvc-project@linuxtesting.org
Subject: [PATCH] usb: typec: fix potential NULL dereference
Date: Mon, 17 Apr 2023 22:50:03 +0300 [thread overview]
Message-ID: <20230417195003.19504-1-korotkov.maxim.s@gmail.com> (raw)
The pointer 'adev' was being dereferenced before being checked for NULL
in the 'type_alt mode_enter()' and 'type_alt mode_exit()' functions.
Although this is a hypothetical issue, it's better to move the pointer
assignment after the NULL check to avoid any potential problems.
Found by Linux Verification Center with Svace static analyzer.
Fixes: 8a37d87d72f0 ("usb: typec: Bus type for alternate modes")
Signed-off-by: Maxim Korotkov <korotkov.maxim.s@gmail.com>
---
drivers/usb/typec/bus.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c
index 098f0efaa58d..ae0aca8f33db 100644
--- a/drivers/usb/typec/bus.c
+++ b/drivers/usb/typec/bus.c
@@ -125,13 +125,16 @@ EXPORT_SYMBOL_GPL(typec_altmode_notify);
*/
int typec_altmode_enter(struct typec_altmode *adev, u32 *vdo)
{
- struct altmode *partner = to_altmode(adev)->partner;
- struct typec_altmode *pdev = &partner->adev;
+ struct altmode *partner;
+ struct typec_altmode *pdev;
int ret;
if (!adev || adev->active)
return 0;
+ partner = to_altmode(adev)->partner;
+ pdev = &partner->adev;
+
if (!pdev->ops || !pdev->ops->enter)
return -EOPNOTSUPP;
@@ -156,13 +159,15 @@ EXPORT_SYMBOL_GPL(typec_altmode_enter);
*/
int typec_altmode_exit(struct typec_altmode *adev)
{
- struct altmode *partner = to_altmode(adev)->partner;
- struct typec_altmode *pdev = &partner->adev;
+ struct altmode *partner;
+ struct typec_altmode *pdev;
int ret;
if (!adev || !adev->active)
return 0;
+ partner = to_altmode(adev)->partner;
+ pdev = &partner->adev;
if (!pdev->ops || !pdev->ops->exit)
return -EOPNOTSUPP;
--
2.37.2
next reply other threads:[~2023-04-17 19:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-17 19:50 Maxim Korotkov [this message]
2023-04-18 6:16 ` Greg Kroah-Hartman
2023-04-18 6:56 ` Maxim Korotkov
2023-04-20 8:39 ` Heikki Krogerus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230417195003.19504-1-korotkov.maxim.s@gmail.com \
--to=korotkov.maxim.s@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®