lkml.org 
[lkml]   [2020]   [Feb]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 5/9] usb: roles: Provide the switch drivers handle to the switch in the API
Hi,

On Tue, Feb 18, 2020 at 07:23:41AM +0000, Peter Chen wrote:
> > > @@ -1118,6 +1119,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
> > > }
> > >
> > > if (ci_role_switch.fwnode) {
> > > + ci_role_switch.driver_data = ci;
> > > ci->role_switch = usb_role_switch_register(dev,
> > > &ci_role_switch);
>
> Why the struct usb_role_switch_desc needs drvdata, the struct
> usb_role_switch has already one?

I'm assuming that you are asking why not just register the switch,
and then call usb_role_switch_set_drvdata(), right?

That may create a race condition where the switch is accessed before
the driver data is available. That can happen for example if the
switch is exposed to the user space.

To play it safe, supplying the driver data as part of the descriptor.
That way we can be sure that the driver data is always available
the moment the switch is registered.

thanks,

--
heikki
\
 
 \ /
  Last update: 2020-02-18 13:27    [W:0.119 / U:6.404 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site