usb: dwc2: gadget: sparse warning of context imbalance
Subsystems (2)
PATCH v3 1/2 usb: dwc2: gadget: sparse warning of context imbalance
sparse was giving the following warning:
warning: context imbalance in 's3c_hsotg_ep_enable'
- different lock contexts for basic block
we were returning ENOMEM while still holding the spinlock. The sparse warning was fixed by releasing the spinlock before return.
--- drivers/usb/dwc2/gadget.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/dwc2/gadget.c +5 -2
@@ -2561,8 +2561,10 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, hs_ep->fifo_size = val;break ; } -if (i ==8 ) -return -ENOMEM ; +if (i ==8 ) { + ret = -ENOMEM ; + goto error; + } }/* for non control endpoints, set PID to D0 */
@@ -2579,6 +2581,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,/* enable the endpoint interrupt */ s3c_hsotg_ctrl_epint (hsotg, index, dir_in,1 ); +error:spin_unlock_irqrestore (&hsotg->lock, flags);return ret; }
Signature · 1 line
1.8.1.2
PATCH v3 2/2 usb: dwc2: gadget: modify return statement
modified the function to have a single return statement at the end instead of multiple return statement in the middle of the function to improve the readability of the code.
This patch depends on the previous patch of the series.
--- drivers/usb/dwc2/gadget.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/dwc2/gadget.c +3 -1
@@ -2471,7 +2471,8 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, dir_in = (desc->bEndpointAddress &USB_ENDPOINT_DIR_MASK ) ?1 :0 ;if (dir_in != hs_ep->dir_in) {dev_err (hsotg->dev,"%s: direction mismatch!\n" , __func__); -return -EINVAL ; + ret = -EINVAL ; + goto error1; } mps =usb_endpoint_maxp (desc);
@@ -2583,6 +2584,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, error:spin_unlock_irqrestore (&hsotg->lock, flags); +error1:return ret; }
Signature · 1 line
1.8.1.2
RE: [PATCH v3 2/2] usb: dwc2: gadget: modify return statement
From: Of Sudip Mukherjee
Quoted 3 lines
modified the function to have a single return statement at the end instead of multiple return statement in the middle of the function to improve the readability of the code.
Many of us would disagree with you there.
Early returns actually make the code easier to read, certainly better than a goto 'end of function'.
David
Quoted 36 lines
This patch depends on the previous patch of the series.
Signed-off-by Sudip Mukherjee <[email protected]>--- drivers/usb/dwc2/gadget.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/dwc2/gadget.c +3
-2@@ -2471,7 +2471,8 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, dir_in = (desc->bEndpointAddress &USB_ENDPOINT_DIR_MASK ) ?1 :0 ;if (dir_in != hs_ep->dir_in) {dev_err (hsotg->dev,"%s: direction mismatch!\n" , __func__); -return -EINVAL ; + ret = -EINVAL ; + goto error1; } mps =usb_endpoint_maxp (desc);@@ -2583,6 +2584,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, error:spin_unlock_irqrestore (&hsotg->lock, flags); +error1:return ret; } --1.8.1.2
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 2/2] usb: dwc2: gadget: modify return statement
Quoted 9 lines · David Laight
From: Of Sudip Mukherjee
Quoted 3 lines
modified the function to have a single return statement at the end instead of multiple return statement in the middle of the function to improve the readability of the code.
Many of us would disagree with you there.
Early returns actually make the code easier to read, certainly better than a goto 'end of function'.
actually , frankly speaking, this first return statement was also easier for me to understand. But in my v1 patch , Paul mentioned :
Quoted 2 lines
For a long function like this, I'd rather keep a single return point at the end.
so I thought he meant all the return statements in the function.
thanks
sudip
Quoted 40 lines
David
Quoted 36 lines
This patch depends on the previous patch of the series.
Signed-off-by Sudip Mukherjee <[email protected]>--- drivers/usb/dwc2/gadget.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/dwc2/gadget.c +3
-2@@ -2471,7 +2471,8 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, dir_in = (desc->bEndpointAddress &USB_ENDPOINT_DIR_MASK ) ?1 :0 ;if (dir_in != hs_ep->dir_in) {dev_err (hsotg->dev,"%s: direction mismatch!\n" , __func__); -return -EINVAL ; + ret = -EINVAL ; + goto error1; } mps =usb_endpoint_maxp (desc);@@ -2583,6 +2584,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, error:spin_unlock_irqrestore (&hsotg->lock, flags); +error1:return ret; } --1.8.1.2
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH v3 2/2] usb: dwc2: gadget: modify return statement
Quoted 13 lines
From: Sudip Mukherjee [mailto:[email protected]]
Sent: Friday, October 17, 2014 3:03 AMQuoted 9 lines · David Laight
From: Of Sudip Mukherjee
Quoted 3 lines
modified the function to have a single return statement at the end instead of multiple return statement in the middle of the function to improve the readability of the code.
Many of us would disagree with you there.
Early returns actually make the code easier to read, certainly better than a goto 'end of function'.
Quoted 5 lines
actually , frankly speaking, this first return statement was also easier for me to understand. But in my v1 patch , Paul mentioned :
Quoted 2 lines
For a long function like this, I'd rather keep a single return point at the end.
so I thought he meant all the return statements in the function.
What I didn't like about your first patch was that there were two places where the spinlock was released. I think that is error-prone, as can be seen by the original bug. But I am OK with leaving the first return statement as-is, since the spinlock is not held there.
So I think we should apply patch 1, and drop patch 2.
Signature · 1 line
Paul
RE: [PATCH v3 2/2] usb: dwc2: gadget: modify return statement
In reply to Sudip MukherjeeQuoted 29 lines
From: Sudip Mukherjee [mailto:[email protected]]
Sent: Thursday, October 16, 2014 9:44 PMmodified the function to have a single return statement at the end instead of multiple return statement in the middle of the function to improve the readability of the code.
This patch depends on the previous patch of the series.
Signed-off-by Sudip Mukherjee <[email protected]>--- drivers/usb/dwc2/gadget.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/dwc2/gadget.c +2
-1@@ -2471,7 +2471,8 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, dir_in = (desc->bEndpointAddress &USB_ENDPOINT_DIR_MASK ) ?1 :0 ;if (dir_in != hs_ep->dir_in) {dev_err (hsotg->dev,"%s: direction mismatch!\n" , __func__); -return -EINVAL ; + ret = -EINVAL ; + goto error1; } mps =usb_endpoint_maxp (desc);
drivers/usb/dwc2/gadget.c static int s3c_hsotg_ep_enable(struct usb_ep *ep, · line 2589
Quoted 6 lines
drivers/usb/dwc2/gadget.c +1
-0@@ -2583,6 +2584,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, error:spin_unlock_irqrestore (&hsotg->lock, flags); +error1:return ret; }
According to the discussion in another thread, let's drop this patch.
Signature · 1 line
Paul
Quoted 33 lines
From: Sudip Mukherjee [mailto:[email protected]]
Sent: Thursday, October 16, 2014 9:44 PMsparse was giving the following warning:
warning: context imbalance in 's3c_hsotg_ep_enable'
- different lock contexts for basic blockwe were returning ENOMEM while still holding the spinlock. The sparse warning was fixed by releasing the spinlock before return.
Signed-off-by Sudip Mukherjee <[email protected]>--- drivers/usb/dwc2/gadget.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/usb/dwc2/gadget.c +4
-2@@ -2561,8 +2561,10 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, hs_ep->fifo_size = val;break ; } -if (i ==8 ) -return -ENOMEM ; +if (i ==8 ) { + ret = -ENOMEM ; + goto error; + } }/* for non control endpoints, set PID to D0 */
drivers/usb/dwc2/gadget.c static int s3c_hsotg_ep_enable(struct usb_ep *ep, · line 2587
Quoted 7 lines
drivers/usb/dwc2/gadget.c +1
-0@@ -2579,6 +2581,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,/* enable the endpoint interrupt */ s3c_hsotg_ctrl_epint (hsotg, index, dir_in,1 ); +error:spin_unlock_irqrestore (&hsotg->lock, flags);return ret; }
Quoted 36 lines · Paul Zimmerman
Quoted 36 lines
From: Sudip Mukherjee [mailto:[email protected]]
Sent: Thursday, October 16, 2014 9:44 PMsparse was giving the following warning:
warning: context imbalance in 's3c_hsotg_ep_enable'
- different lock contexts for basic blockwe were returning ENOMEM while still holding the spinlock. The sparse warning was fixed by releasing the spinlock before return.
Signed-off-by Sudip Mukherjee <[email protected]>--- drivers/usb/dwc2/gadget.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/usb/dwc2/gadget.c +4
-2@@ -2561,8 +2561,10 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, hs_ep->fifo_size = val;break ; } -if (i ==8 ) -return -ENOMEM ; +if (i ==8 ) { + ret = -ENOMEM ; + goto error; + } }/* for non control endpoints, set PID to D0 */ @@ -2579,6 +2581,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,/* enable the endpoint interrupt */ s3c_hsotg_ctrl_epint (hsotg, index, dir_in,1 );
Quoted 6 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_ep_enable(struct usb_ep *ep, · line 2587
Quoted 4 lines
drivers/usb/dwc2/gadget.c +1
-0+error:spin_unlock_irqrestore (&hsotg->lock, flags);return ret; }Acked-by Paul Zimmerman <[email protected]>
v3.18-rc or v3.19 ?
Signature · 1 line
balbi
Quoted 40 lines
From: Felipe Balbi [mailto:[email protected]]
Sent: Friday, October 17, 2014 11:52 AMQuoted 36 lines · Paul Zimmerman
Quoted 36 lines
From: Sudip Mukherjee [mailto:[email protected]]
Sent: Thursday, October 16, 2014 9:44 PMsparse was giving the following warning:
warning: context imbalance in 's3c_hsotg_ep_enable'
- different lock contexts for basic blockwe were returning ENOMEM while still holding the spinlock. The sparse warning was fixed by releasing the spinlock before return.
Signed-off-by Sudip Mukherjee <[email protected]>--- drivers/usb/dwc2/gadget.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/usb/dwc2/gadget.c +4
-2@@ -2561,8 +2561,10 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, hs_ep->fifo_size = val;break ; } -if (i ==8 ) -return -ENOMEM ; +if (i ==8 ) { + ret = -ENOMEM ; + goto error; + } }/* for non control endpoints, set PID to D0 */ @@ -2579,6 +2581,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,/* enable the endpoint interrupt */ s3c_hsotg_ctrl_epint (hsotg, index, dir_in,1 );
Quoted 8 lines
Quoted 6 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_ep_enable(struct usb_ep *ep, · line 2587
Quoted 4 lines
drivers/usb/dwc2/gadget.c +1
-0+error:spin_unlock_irqrestore (&hsotg->lock, flags);return ret; }Acked-by Paul Zimmerman <[email protected]>v3.18-rc or v3.19 ?
v3.18-rc, since it's a bugfix. And I forgot, this should be marked for 3.17 stable too.
Signature · 1 line
Paul
Quoted 47 lines · Paul Zimmerman
Quoted 47 lines
From: Felipe Balbi [mailto:[email protected]]
Sent: Friday, October 17, 2014 11:52 AMQuoted 42 lines · Paul Zimmerman
Quoted 33 lines
From: Sudip Mukherjee [mailto:[email protected]]
Sent: Thursday, October 16, 2014 9:44 PMsparse was giving the following warning:
warning: context imbalance in 's3c_hsotg_ep_enable'
- different lock contexts for basic blockwe were returning ENOMEM while still holding the spinlock. The sparse warning was fixed by releasing the spinlock before return.
Signed-off-by Sudip Mukherjee <[email protected]>--- drivers/usb/dwc2/gadget.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/usb/dwc2/gadget.c +4
-2@@ -2561,8 +2561,10 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, hs_ep->fifo_size = val;break ; } -if (i ==8 ) -return -ENOMEM ; +if (i ==8 ) { + ret = -ENOMEM ; + goto error; + } }/* for non control endpoints, set PID to D0 */ drivers/usb/dwc2/gadget.c static int s3c_hsotg_ep_enable(struct usb_ep *ep, · line 2587
Quoted 7 lines
drivers/usb/dwc2/gadget.c +1
-0@@ -2579,6 +2581,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,/* enable the endpoint interrupt */ s3c_hsotg_ctrl_epint (hsotg, index, dir_in,1 ); +error:spin_unlock_irqrestore (&hsotg->lock, flags);return ret; }Acked-by Paul Zimmerman <[email protected]>
Quoted 4 lines
Quoted 1 line
v3.18-rc or v3.19 ?
v3.18-rc, since it's a bugfix. And I forgot, this should be marked for 3.17 stable too.
Alright, I'll add that.
Signature · 1 line
balbi
Quoted 47 lines · Paul Zimmerman
Quoted 47 lines
From: Felipe Balbi [mailto:[email protected]]
Sent: Friday, October 17, 2014 11:52 AMQuoted 42 lines · Paul Zimmerman
Quoted 33 lines
From: Sudip Mukherjee [mailto:[email protected]]
Sent: Thursday, October 16, 2014 9:44 PMsparse was giving the following warning:
warning: context imbalance in 's3c_hsotg_ep_enable'
- different lock contexts for basic blockwe were returning ENOMEM while still holding the spinlock. The sparse warning was fixed by releasing the spinlock before return.
Signed-off-by Sudip Mukherjee <[email protected]>--- drivers/usb/dwc2/gadget.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/usb/dwc2/gadget.c +4
-2@@ -2561,8 +2561,10 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, hs_ep->fifo_size = val;break ; } -if (i ==8 ) -return -ENOMEM ; +if (i ==8 ) { + ret = -ENOMEM ; + goto error; + } }/* for non control endpoints, set PID to D0 */ drivers/usb/dwc2/gadget.c static int s3c_hsotg_ep_enable(struct usb_ep *ep, · line 2587
Quoted 7 lines
drivers/usb/dwc2/gadget.c +1
-0@@ -2579,6 +2581,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,/* enable the endpoint interrupt */ s3c_hsotg_ctrl_epint (hsotg, index, dir_in,1 ); +error:spin_unlock_irqrestore (&hsotg->lock, flags);return ret; }Acked-by Paul Zimmerman <[email protected]>
Quoted 5 lines
Quoted 1 line
v3.18-rc or v3.19 ?
v3.18-rc, since it's a bugfix. And I forgot, this should be marked for 3.17 stable too.
hi,
this is not yet added to linux-next , is something pending from my side?
thanks
sudip
Quoted 3 lines
Signature · 1 line
Paul
Greg Kroah-Hartman
maintainerQuoted 48 lines · Sudip Mukherjee
Quoted 47 lines · Paul Zimmerman
Quoted 47 lines
From: Felipe Balbi [mailto:[email protected]]
Sent: Friday, October 17, 2014 11:52 AMQuoted 42 lines · Paul Zimmerman
Quoted 33 lines
From: Sudip Mukherjee [mailto:[email protected]]
Sent: Thursday, October 16, 2014 9:44 PMsparse was giving the following warning:
warning: context imbalance in 's3c_hsotg_ep_enable'
- different lock contexts for basic blockwe were returning ENOMEM while still holding the spinlock. The sparse warning was fixed by releasing the spinlock before return.
Signed-off-by Sudip Mukherjee <[email protected]>--- drivers/usb/dwc2/gadget.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/usb/dwc2/gadget.c +4
-2@@ -2561,8 +2561,10 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, hs_ep->fifo_size = val;break ; } -if (i ==8 ) -return -ENOMEM ; +if (i ==8 ) { + ret = -ENOMEM ; + goto error; + } }/* for non control endpoints, set PID to D0 */ drivers/usb/dwc2/gadget.c static int s3c_hsotg_ep_enable(struct usb_ep *ep, · line 2587
Quoted 7 lines
drivers/usb/dwc2/gadget.c +1
-0@@ -2579,6 +2581,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,/* enable the endpoint interrupt */ s3c_hsotg_ctrl_epint (hsotg, index, dir_in,1 ); +error:spin_unlock_irqrestore (&hsotg->lock, flags);return ret; }Acked-by Paul Zimmerman <[email protected]>
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
v3.18-rc or v3.19 ?
v3.18-rc, since it's a bugfix. And I forgot, this should be marked for 3.17 stable too.
hi,
this is not yet added to linux-next , is something pending from my side?
Patience.