linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] usb: gadget: composite: fix delayed_status race condition when set_interface
@ 2018-06-22  6:33 Chunfeng Yun
  2018-06-22  6:33 ` [PATCH 2/2] usb: core: phy: fix return value checking about devm_of_phy_get_by_index() Chunfeng Yun
  0 siblings, 1 reply; 6+ messages in thread
From: Chunfeng Yun @ 2018-06-22  6:33 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Felipe Balbi
  Cc: Martin Blumenstingl, Matthias Brugger, Chunfeng Yun, linux-usb,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek

It happens when enable debug log, if set_alt() returns
USB_GADGET_DELAYED_STATUS and usb_composite_setup_continue()
is called before increasing count of @delayed_status,
so fix it by using spinlock of @cdev->lock.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Tested-by: Jay Hsu <shih-chieh.hsu@mediatek.com>
---
 drivers/usb/gadget/composite.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index f242c2b..d2fa071 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1719,6 +1719,8 @@ static int fill_ext_prop(struct usb_configuration *c, int interface, u8 *buf)
 		 */
 		if (w_value && !f->get_alt)
 			break;
+
+		spin_lock(&cdev->lock);
 		value = f->set_alt(f, w_index, w_value);
 		if (value == USB_GADGET_DELAYED_STATUS) {
 			DBG(cdev,
@@ -1728,6 +1730,7 @@ static int fill_ext_prop(struct usb_configuration *c, int interface, u8 *buf)
 			DBG(cdev, "delayed_status count %d\n",
 					cdev->delayed_status);
 		}
+		spin_unlock(&cdev->lock);
 		break;
 	case USB_REQ_GET_INTERFACE:
 		if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] usb: core: phy: fix return value checking about devm_of_phy_get_by_index()
  2018-06-22  6:33 [PATCH 1/2] usb: gadget: composite: fix delayed_status race condition when set_interface Chunfeng Yun
@ 2018-06-22  6:33 ` Chunfeng Yun
  2018-06-24 18:00   ` Martin Blumenstingl
  0 siblings, 1 reply; 6+ messages in thread
From: Chunfeng Yun @ 2018-06-22  6:33 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Felipe Balbi
  Cc: Martin Blumenstingl, Matthias Brugger, Chunfeng Yun, linux-usb,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek

1. use IS_ERR() but not IS_ERR_OR_NULL() because devm_of_phy_get_by_index()
    never return NULL value;
2. devm_of_phy_get_by_index() should not fail for a valid index

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
 drivers/usb/core/phy.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
index 9879767..0f972e1 100644
--- a/drivers/usb/core/phy.c
+++ b/drivers/usb/core/phy.c
@@ -23,14 +23,11 @@ static int usb_phy_roothub_add_phy(struct device *dev, int index,
 				   struct list_head *list)
 {
 	struct usb_phy_roothub *roothub_entry;
-	struct phy *phy = devm_of_phy_get_by_index(dev, dev->of_node, index);
+	struct phy *phy;
 
-	if (IS_ERR_OR_NULL(phy)) {
-		if (!phy || PTR_ERR(phy) == -ENODEV)
-			return 0;
-		else
-			return PTR_ERR(phy);
-	}
+	phy = devm_of_phy_get_by_index(dev, dev->of_node, index);
+	if (IS_ERR(phy))
+		return PTR_ERR(phy);
 
 	roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), GFP_KERNEL);
 	if (!roothub_entry)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] usb: core: phy: fix return value checking about devm_of_phy_get_by_index()
  2018-06-22  6:33 ` [PATCH 2/2] usb: core: phy: fix return value checking about devm_of_phy_get_by_index() Chunfeng Yun
@ 2018-06-24 18:00   ` Martin Blumenstingl
  2018-06-25  5:29     ` Johan Hovold
  2018-06-25  6:37     ` Chunfeng Yun
  0 siblings, 2 replies; 6+ messages in thread
From: Martin Blumenstingl @ 2018-06-24 18:00 UTC (permalink / raw)
  To: chunfeng.yun, johan
  Cc: gregkh, felipe.balbi, matthias.bgg, linux-usb, devicetree,
	linux-kernel, linux-arm-kernel, linux-mediatek

Hello Chunfeng,

thank you for the patch!

On Fri, Jun 22, 2018 at 8:33 AM Chunfeng Yun <chunfeng.yun@mediatek.com> wrote:
>
> 1. use IS_ERR() but not IS_ERR_OR_NULL() because devm_of_phy_get_by_index()
>     never return NULL value;
ACK - good catch!

> 2. devm_of_phy_get_by_index() should not fail for a valid index
I have learned that the PHY framework can return -ENODEV if the PHY is:
1. supposed to be handled by the legacy USB PHY framework
2. the PHY node is disabled in devicetree

see [0] for the code in the PHY framework and [1] for the discussion
with Johan (who informed me of case #1, I added him on this mail)

> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> ---
>  drivers/usb/core/phy.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
> index 9879767..0f972e1 100644
> --- a/drivers/usb/core/phy.c
> +++ b/drivers/usb/core/phy.c
> @@ -23,14 +23,11 @@ static int usb_phy_roothub_add_phy(struct device *dev, int index,
>                                    struct list_head *list)
>  {
>         struct usb_phy_roothub *roothub_entry;
> -       struct phy *phy = devm_of_phy_get_by_index(dev, dev->of_node, index);
> +       struct phy *phy;
>
> -       if (IS_ERR_OR_NULL(phy)) {
> -               if (!phy || PTR_ERR(phy) == -ENODEV)
> -                       return 0;
> -               else
> -                       return PTR_ERR(phy);
> -       }
> +       phy = devm_of_phy_get_by_index(dev, dev->of_node, index);
> +       if (IS_ERR(phy))
> +               return PTR_ERR(phy);
@Johan can you please review this as well? maybe we need to keep the
-ENODEV check


Regards
Martin


[0] https://elixir.bootlin.com/linux/v4.18-rc2/source/drivers/phy/phy-core.c#L421
[1] https://lkml.org/lkml/2018/4/19/88

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] usb: core: phy: fix return value checking about devm_of_phy_get_by_index()
  2018-06-24 18:00   ` Martin Blumenstingl
@ 2018-06-25  5:29     ` Johan Hovold
  2018-06-25  6:37     ` Chunfeng Yun
  1 sibling, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2018-06-25  5:29 UTC (permalink / raw)
  To: Martin Blumenstingl
  Cc: chunfeng.yun, johan, gregkh, felipe.balbi, matthias.bgg,
	linux-usb, devicetree, linux-kernel, linux-arm-kernel,
	linux-mediatek

On Sun, Jun 24, 2018 at 08:00:01PM +0200, Martin Blumenstingl wrote:
> Hello Chunfeng,
> 
> thank you for the patch!
> 
> On Fri, Jun 22, 2018 at 8:33 AM Chunfeng Yun <chunfeng.yun@mediatek.com> wrote:

> > 2. devm_of_phy_get_by_index() should not fail for a valid index
> I have learned that the PHY framework can return -ENODEV if the PHY is:
> 1. supposed to be handled by the legacy USB PHY framework
> 2. the PHY node is disabled in devicetree
> 
> see [0] for the code in the PHY framework and [1] for the discussion
> with Johan (who informed me of case #1, I added him on this mail)
> 
> > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > ---
> >  drivers/usb/core/phy.c | 11 ++++-------
> >  1 file changed, 4 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
> > index 9879767..0f972e1 100644
> > --- a/drivers/usb/core/phy.c
> > +++ b/drivers/usb/core/phy.c
> > @@ -23,14 +23,11 @@ static int usb_phy_roothub_add_phy(struct device *dev, int index,
> >                                    struct list_head *list)
> >  {
> >         struct usb_phy_roothub *roothub_entry;
> > -       struct phy *phy = devm_of_phy_get_by_index(dev, dev->of_node, index);
> > +       struct phy *phy;
> >
> > -       if (IS_ERR_OR_NULL(phy)) {
> > -               if (!phy || PTR_ERR(phy) == -ENODEV)
> > -                       return 0;
> > -               else
> > -                       return PTR_ERR(phy);
> > -       }
> > +       phy = devm_of_phy_get_by_index(dev, dev->of_node, index);
> > +       if (IS_ERR(phy))
> > +               return PTR_ERR(phy);
> @Johan can you please review this as well? maybe we need to keep the
> -ENODEV check

Indeed, the -ENODEV check is still needed for the reasons you point out
above.

Johan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] usb: core: phy: fix return value checking about devm_of_phy_get_by_index()
  2018-06-24 18:00   ` Martin Blumenstingl
  2018-06-25  5:29     ` Johan Hovold
@ 2018-06-25  6:37     ` Chunfeng Yun
  2018-06-25 17:32       ` Martin Blumenstingl
  1 sibling, 1 reply; 6+ messages in thread
From: Chunfeng Yun @ 2018-06-25  6:37 UTC (permalink / raw)
  To: Martin Blumenstingl
  Cc: johan, gregkh, felipe.balbi, matthias.bgg, linux-usb, devicetree,
	linux-kernel, linux-arm-kernel, linux-mediatek

On Sun, 2018-06-24 at 20:00 +0200, Martin Blumenstingl wrote:
> Hello Chunfeng,
> 
> thank you for the patch!
> 
> On Fri, Jun 22, 2018 at 8:33 AM Chunfeng Yun <chunfeng.yun@mediatek.com> wrote:
> >
> > 1. use IS_ERR() but not IS_ERR_OR_NULL() because devm_of_phy_get_by_index()
> >     never return NULL value;
> ACK - good catch!
> 
> > 2. devm_of_phy_get_by_index() should not fail for a valid index
> I have learned that the PHY framework can return -ENODEV if the PHY is:
> 1. supposed to be handled by the legacy USB PHY framework
> 2. the PHY node is disabled in devicetree
A little confused, we can avoid this error by not using a disabled or
"usb-nop-xceiv" phy in host node.

If ignore error of -ENODEV, we will also skip an error case which we
don't want it happen. 

> 
> see [0] for the code in the PHY framework and [1] for the discussion
> with Johan (who informed me of case #1, I added him on this mail)
> 
> > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > ---
> >  drivers/usb/core/phy.c | 11 ++++-------
> >  1 file changed, 4 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
> > index 9879767..0f972e1 100644
> > --- a/drivers/usb/core/phy.c
> > +++ b/drivers/usb/core/phy.c
> > @@ -23,14 +23,11 @@ static int usb_phy_roothub_add_phy(struct device *dev, int index,
> >                                    struct list_head *list)
> >  {
> >         struct usb_phy_roothub *roothub_entry;
> > -       struct phy *phy = devm_of_phy_get_by_index(dev, dev->of_node, index);
> > +       struct phy *phy;
> >
> > -       if (IS_ERR_OR_NULL(phy)) {
> > -               if (!phy || PTR_ERR(phy) == -ENODEV)
> > -                       return 0;
> > -               else
> > -                       return PTR_ERR(phy);
> > -       }
> > +       phy = devm_of_phy_get_by_index(dev, dev->of_node, index);
> > +       if (IS_ERR(phy))
> > +               return PTR_ERR(phy);
> @Johan can you please review this as well? maybe we need to keep the
> -ENODEV check
> 
> 
> Regards
> Martin
> 
> 
> [0] https://elixir.bootlin.com/linux/v4.18-rc2/source/drivers/phy/phy-core.c#L421
> [1] https://lkml.org/lkml/2018/4/19/88



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] usb: core: phy: fix return value checking about devm_of_phy_get_by_index()
  2018-06-25  6:37     ` Chunfeng Yun
@ 2018-06-25 17:32       ` Martin Blumenstingl
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Blumenstingl @ 2018-06-25 17:32 UTC (permalink / raw)
  To: chunfeng.yun
  Cc: johan, gregkh, felipe.balbi, matthias.bgg, linux-usb, devicetree,
	linux-kernel, linux-arm-kernel, linux-mediatek

Hi Chunfeng,

On Mon, Jun 25, 2018 at 8:37 AM Chunfeng Yun <chunfeng.yun@mediatek.com> wrote:
>
> On Sun, 2018-06-24 at 20:00 +0200, Martin Blumenstingl wrote:
> > Hello Chunfeng,
> >
> > thank you for the patch!
> >
> > On Fri, Jun 22, 2018 at 8:33 AM Chunfeng Yun <chunfeng.yun@mediatek.com> wrote:
> > >
> > > 1. use IS_ERR() but not IS_ERR_OR_NULL() because devm_of_phy_get_by_index()
> > >     never return NULL value;
> > ACK - good catch!
> >
> > > 2. devm_of_phy_get_by_index() should not fail for a valid index
> > I have learned that the PHY framework can return -ENODEV if the PHY is:
> > 1. supposed to be handled by the legacy USB PHY framework
> > 2. the PHY node is disabled in devicetree
> A little confused, we can avoid this error by not using a disabled or
> "usb-nop-xceiv" phy in host node.
I think that would be the mid or long term goal

> If ignore error of -ENODEV, we will also skip an error case which we
> don't want it happen.
as far as I understand the problem is that there are .dts files out
there which specify "usb-nop-xceiv" in the "phys" property, see [0]
(there might be even some more out-of-tree cases)
so I think the -ENODEV check can only be removed once nothing uses
"usb-nop-xceiv" anymore


Regards
Martin


[0] https://patchwork.kernel.org/patch/10160181/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-06-25 17:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-22  6:33 [PATCH 1/2] usb: gadget: composite: fix delayed_status race condition when set_interface Chunfeng Yun
2018-06-22  6:33 ` [PATCH 2/2] usb: core: phy: fix return value checking about devm_of_phy_get_by_index() Chunfeng Yun
2018-06-24 18:00   ` Martin Blumenstingl
2018-06-25  5:29     ` Johan Hovold
2018-06-25  6:37     ` Chunfeng Yun
2018-06-25 17:32       ` Martin Blumenstingl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).