On Fri, Mar 24, 2023 at 03:02:46AM +0000, Tian, Kevin wrote: > External email: Use caution opening links or attachments > > > > From: Nicolin Chen <nicolinc@xxxxxxxxxx> > > Sent: Thursday, March 23, 2023 4:33 PM > > > > +int iommufd_access_replace(struct iommufd_access *access, u32 ioas_id) > > +{ > > + struct iommufd_ioas *new_ioas; > > + > > + mutex_lock(&access->ioas_lock); > > + if (!access->ioas) { > > mutex_unlock(&access->ioas_lock); > > - iommufd_put_object(obj); > > - return rc; > > + return -ENOENT; > > + } > > + if (access->ioas->obj.id == ioas_id) { > > + mutex_unlock(&access->ioas_lock); > > + return 0; > > } > > - iommufd_ref_to_users(obj); > > > > + new_ioas = iommufd_access_change_pt(access, ioas_id); > > + if (IS_ERR(new_ioas)) { > > + mutex_unlock(&access->ioas_lock); > > + return PTR_ERR(new_ioas); > > + } > > + __iommufd_access_detach(access); > > access->ioas = new_ioas; > > access->ioas_unpin = new_ioas; > > Above three lines can be moved into iommufd_access_change_pt(): > > If (access->ioas) > __iommufd_access_detach(access); > access->ioas = new_ioas; > access->ioas_unpin = new_ioas; > > Then both attach/replace can end by calling the common function. OK. Will do that in v6. Thanks Nicolin