From: Sebin Sebastian <mailmesebin00@gmail.com>
To: linux-aspeed@lists.ozlabs.org
Subject: [PATCH v2 -next] usb: gadget: dereference before null check
Date: Thu, 30 Jun 2022 04:47:33 -0000 [thread overview]
Message-ID: <20220630044706.10772-1-mailmesebin00@gmail.com> (raw)
Fix coverity warning dereferencing before null check. _ep and desc is
dereferenced on all paths until the check for null. Move the
initializations after the check for null.
Coverity issue: 1518209
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Sebin Sebastian <mailmesebin00@gmail.com>
---
Changes since v1: Fix the build errors and warnings due to first patch.
Fix the undeclared 'ep' and 'maxpacket' error. Fix the ISO C90 warning.
drivers/usb/gadget/udc/aspeed_udc.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/drivers/usb/gadget/udc/aspeed_udc.c b/drivers/usb/gadget/udc/aspeed_udc.c
index d75a4e070bf7..a43cf8dde2a8 100644
--- a/drivers/usb/gadget/udc/aspeed_udc.c
+++ b/drivers/usb/gadget/udc/aspeed_udc.c
@@ -341,26 +341,33 @@ static void ast_udc_stop_activity(struct ast_udc_dev *udc)
static int ast_udc_ep_enable(struct usb_ep *_ep,
const struct usb_endpoint_descriptor *desc)
{
- u16 maxpacket = usb_endpoint_maxp(desc);
- struct ast_udc_ep *ep = to_ast_ep(_ep);
- struct ast_udc_dev *udc = ep->udc;
- u8 epnum = usb_endpoint_num(desc);
unsigned long flags;
u32 ep_conf = 0;
u8 dir_in;
u8 type;
+ u16 maxpacket;
+ struct ast_udc_ep *ep;
+ struct ast_udc_dev *udc;
+ u8 epnum;
- if (!_ep || !ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT ||
- maxpacket == 0 || maxpacket > ep->ep.maxpacket) {
+ if (!_ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) {
EP_DBG(ep, "Failed, invalid EP enable param\n");
return -EINVAL;
}
-
if (!udc->driver) {
EP_DBG(ep, "bogus device state\n");
return -ESHUTDOWN;
}
+ maxpacket = usb_endpoint_maxp(desc);
+ ep = to_ast_ep(_ep);
+ udc = ep->udc;
+ epnum = usb_endpoint_num(desc);
+ if (maxpacket == 0 || maxpacket > ep->ep.maxpacket) {
+ EP_DBG(ep, "Failed, invalid EP enable param\n");
+ return -EINVAL;
+ }
+
EP_DBG(ep, "maxpacket:0x%x\n", maxpacket);
spin_lock_irqsave(&udc->lock, flags);
--
2.34.1
WARNING: multiple messages have this Message-ID (diff)
From: Sebin Sebastian <mailmesebin00@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: mailmesebin00@gmail.com, skhan@linuxfoundation.org,
kernel test robot <lkp@intel.com>,
Neal Liu <neal_liu@aspeedtech.com>,
Felipe Balbi <balbi@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Joel Stanley <joel@jms.id.au>, Andrew Jeffery <andrew@aj.id.au>,
linux-aspeed@lists.ozlabs.org, linux-usb@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 -next] usb: gadget: dereference before null check
Date: Thu, 30 Jun 2022 10:17:06 +0530 [thread overview]
Message-ID: <20220630044706.10772-1-mailmesebin00@gmail.com> (raw)
Fix coverity warning dereferencing before null check. _ep and desc is
dereferenced on all paths until the check for null. Move the
initializations after the check for null.
Coverity issue: 1518209
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Sebin Sebastian <mailmesebin00@gmail.com>
---
Changes since v1: Fix the build errors and warnings due to first patch.
Fix the undeclared 'ep' and 'maxpacket' error. Fix the ISO C90 warning.
drivers/usb/gadget/udc/aspeed_udc.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/drivers/usb/gadget/udc/aspeed_udc.c b/drivers/usb/gadget/udc/aspeed_udc.c
index d75a4e070bf7..a43cf8dde2a8 100644
--- a/drivers/usb/gadget/udc/aspeed_udc.c
+++ b/drivers/usb/gadget/udc/aspeed_udc.c
@@ -341,26 +341,33 @@ static void ast_udc_stop_activity(struct ast_udc_dev *udc)
static int ast_udc_ep_enable(struct usb_ep *_ep,
const struct usb_endpoint_descriptor *desc)
{
- u16 maxpacket = usb_endpoint_maxp(desc);
- struct ast_udc_ep *ep = to_ast_ep(_ep);
- struct ast_udc_dev *udc = ep->udc;
- u8 epnum = usb_endpoint_num(desc);
unsigned long flags;
u32 ep_conf = 0;
u8 dir_in;
u8 type;
+ u16 maxpacket;
+ struct ast_udc_ep *ep;
+ struct ast_udc_dev *udc;
+ u8 epnum;
- if (!_ep || !ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT ||
- maxpacket == 0 || maxpacket > ep->ep.maxpacket) {
+ if (!_ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) {
EP_DBG(ep, "Failed, invalid EP enable param\n");
return -EINVAL;
}
-
if (!udc->driver) {
EP_DBG(ep, "bogus device state\n");
return -ESHUTDOWN;
}
+ maxpacket = usb_endpoint_maxp(desc);
+ ep = to_ast_ep(_ep);
+ udc = ep->udc;
+ epnum = usb_endpoint_num(desc);
+ if (maxpacket == 0 || maxpacket > ep->ep.maxpacket) {
+ EP_DBG(ep, "Failed, invalid EP enable param\n");
+ return -EINVAL;
+ }
+
EP_DBG(ep, "maxpacket:0x%x\n", maxpacket);
spin_lock_irqsave(&udc->lock, flags);
--
2.34.1
WARNING: multiple messages have this Message-ID (diff)
From: Sebin Sebastian <mailmesebin00@gmail.com>
Cc: mailmesebin00@gmail.com, skhan@linuxfoundation.org,
kernel test robot <lkp@intel.com>,
Neal Liu <neal_liu@aspeedtech.com>,
Felipe Balbi <balbi@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Joel Stanley <joel@jms.id.au>, Andrew Jeffery <andrew@aj.id.au>,
linux-aspeed@lists.ozlabs.org, linux-usb@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 -next] usb: gadget: dereference before null check
Date: Thu, 30 Jun 2022 10:17:06 +0530 [thread overview]
Message-ID: <20220630044706.10772-1-mailmesebin00@gmail.com> (raw)
Fix coverity warning dereferencing before null check. _ep and desc is
dereferenced on all paths until the check for null. Move the
initializations after the check for null.
Coverity issue: 1518209
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Sebin Sebastian <mailmesebin00@gmail.com>
---
Changes since v1: Fix the build errors and warnings due to first patch.
Fix the undeclared 'ep' and 'maxpacket' error. Fix the ISO C90 warning.
drivers/usb/gadget/udc/aspeed_udc.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/drivers/usb/gadget/udc/aspeed_udc.c b/drivers/usb/gadget/udc/aspeed_udc.c
index d75a4e070bf7..a43cf8dde2a8 100644
--- a/drivers/usb/gadget/udc/aspeed_udc.c
+++ b/drivers/usb/gadget/udc/aspeed_udc.c
@@ -341,26 +341,33 @@ static void ast_udc_stop_activity(struct ast_udc_dev *udc)
static int ast_udc_ep_enable(struct usb_ep *_ep,
const struct usb_endpoint_descriptor *desc)
{
- u16 maxpacket = usb_endpoint_maxp(desc);
- struct ast_udc_ep *ep = to_ast_ep(_ep);
- struct ast_udc_dev *udc = ep->udc;
- u8 epnum = usb_endpoint_num(desc);
unsigned long flags;
u32 ep_conf = 0;
u8 dir_in;
u8 type;
+ u16 maxpacket;
+ struct ast_udc_ep *ep;
+ struct ast_udc_dev *udc;
+ u8 epnum;
- if (!_ep || !ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT ||
- maxpacket == 0 || maxpacket > ep->ep.maxpacket) {
+ if (!_ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) {
EP_DBG(ep, "Failed, invalid EP enable param\n");
return -EINVAL;
}
-
if (!udc->driver) {
EP_DBG(ep, "bogus device state\n");
return -ESHUTDOWN;
}
+ maxpacket = usb_endpoint_maxp(desc);
+ ep = to_ast_ep(_ep);
+ udc = ep->udc;
+ epnum = usb_endpoint_num(desc);
+ if (maxpacket == 0 || maxpacket > ep->ep.maxpacket) {
+ EP_DBG(ep, "Failed, invalid EP enable param\n");
+ return -EINVAL;
+ }
+
EP_DBG(ep, "maxpacket:0x%x\n", maxpacket);
spin_lock_irqsave(&udc->lock, flags);
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2022-06-30 4:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-30 4:47 Sebin Sebastian [this message]
2022-06-30 4:47 ` [PATCH v2 -next] usb: gadget: dereference before null check Sebin Sebastian
2022-06-30 4:47 ` Sebin Sebastian
2022-06-30 6:54 ` Greg Kroah-Hartman
2022-06-30 6:54 ` Greg Kroah-Hartman
2022-06-30 6:54 ` Greg Kroah-Hartman
2022-06-30 11:03 ` Sebin Sebastian
2022-06-30 11:03 ` Sebin Sebastian
2022-06-30 11:03 ` Sebin Sebastian
2022-06-30 11:09 ` Greg Kroah-Hartman
2022-06-30 11:09 ` Greg Kroah-Hartman
2022-06-30 11:09 ` Greg Kroah-Hartman
2022-06-30 12:25 ` Sebin Sebastian
2022-06-30 12:26 ` Sebin Sebastian
2022-06-30 12:25 ` Sebin Sebastian
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=20220630044706.10772-1-mailmesebin00@gmail.com \
--to=mailmesebin00@gmail.com \
--cc=linux-aspeed@lists.ozlabs.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 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.