Hi Ajay,

On Tue, Feb 05, 2019 at 12:59:27AM +0000, Ajay Gupta wrote:
> > +static int ucsi_register_altmode(struct ucsi_connector *con,
> > +                            struct typec_altmode_desc *desc,
> > +                            u8 recipient)
> > +{
> > +   struct typec_altmode *alt;
> > +   int ret;
> > +   int i;
> > +
> > +   switch (recipient) {
> > +   case UCSI_RECIPIENT_CON:
> > +           i = ucsi_next_altmode(con->port_altmode);
> > +           if (i < 0) {
> > +                   ret = i;
> > +                   goto err;
> > +           }
> > +
> > +           desc->mode = ucsi_altmode_next_mode(con->port_altmode,
> > +                                               desc->svid);
> > +
> > +           alt = typec_port_register_altmode(con->port, desc);
> > +           if (IS_ERR(alt)) {
> > +                   ret = PTR_ERR(alt);
> > +                   goto err;
> > +           }
> > +
> > +           con->port_altmode[i] = alt;
> > +           break;
> > +   case UCSI_RECIPIENT_SOP:
> > +           i = ucsi_next_altmode(con->partner_altmode);
> We are seeing duplicate partner altmode devices getting created when we set
> "active" file from 1->0->1 Please add a check here to see if altmode device
> already exists.
> 
> [...]
>         case UCSI_RECIPIENT_SOP:
>                 /* check to see if partner altmode already exists */
>                 if (ucsi_altmode_found(con->partner_altmode, desc))
>                         break;
> 
>                 i = ucsi_next_altmode(con->partner_altmode);
>        if (i < 0) {
> [...]
> 
> 
> static bool ucsi_altmode_found(struct typec_altmode **alt,
>                                struct typec_altmode_desc *desc)
> {
>         int i;
> 
>         for (i = 0; i < UCSI_MAX_ALTMODES; i++) {
>                 if (!alt[i])
>                         return false;
>                 if (alt[i]->svid == desc->svid && alt[i]->vdo == desc->vdo)
>                         return true;
>         }
> 
>         return false;
> }
OK. I'll prepare new version later this week.


thanks,

-- 
heikki

Reply via email to