Message ID | 6-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Make vfio_mdev type safe | expand |
On Tue, Mar 23, 2021 at 02:55:23PM -0300, Jason Gunthorpe wrote: > The next patch will use these in mdev_sysfs.c > > While here remove the now dead code checks for NULL, a mdev_type can never > have a NULL parent. I'd normally just move that into the patch that uses it, but the mechanical change looks fine: Reviewed-by: Christoph Hellwig <hch@lst.de>
> From: Jason Gunthorpe <jgg@nvidia.com> > Sent: Wednesday, March 24, 2021 1:55 AM > > The next patch will use these in mdev_sysfs.c > > While here remove the now dead code checks for NULL, a mdev_type can > never > have a NULL parent. > > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> > --- > drivers/vfio/mdev/mdev_core.c | 23 +++-------------------- > drivers/vfio/mdev/mdev_private.h | 12 ++++++++++++ > 2 files changed, 15 insertions(+), 20 deletions(-) > > diff --git a/drivers/vfio/mdev/mdev_core.c > b/drivers/vfio/mdev/mdev_core.c > index 5ca0efa5266bad..7ec21c907397a5 100644 > --- a/drivers/vfio/mdev/mdev_core.c > +++ b/drivers/vfio/mdev/mdev_core.c > @@ -45,7 +45,7 @@ static struct mdev_parent *__find_parent_device(struct > device *dev) > return NULL; > } > > -static void mdev_release_parent(struct kref *kref) > +void mdev_release_parent(struct kref *kref) > { > struct mdev_parent *parent = container_of(kref, struct mdev_parent, > ref); > @@ -55,20 +55,6 @@ static void mdev_release_parent(struct kref *kref) > put_device(dev); > } > > -static struct mdev_parent *mdev_get_parent(struct mdev_parent *parent) > -{ > - if (parent) > - kref_get(&parent->ref); > - > - return parent; > -} > - > -static void mdev_put_parent(struct mdev_parent *parent) > -{ > - if (parent) > - kref_put(&parent->ref, mdev_release_parent); > -} > - > /* Caller must hold parent unreg_sem read or write lock */ > static void mdev_device_remove_common(struct mdev_device *mdev) > { > @@ -243,12 +229,9 @@ int mdev_device_create(struct mdev_type *type, > const guid_t *uuid) > { > int ret; > struct mdev_device *mdev, *tmp; > - struct mdev_parent *parent; > - > - parent = mdev_get_parent(type->parent); > - if (!parent) > - return -EINVAL; > + struct mdev_parent *parent = type->parent; > > + mdev_get_parent(parent); > mutex_lock(&mdev_list_lock); > > /* Check for duplicate */ > diff --git a/drivers/vfio/mdev/mdev_private.h > b/drivers/vfio/mdev/mdev_private.h > index debf27f95b4f10..10eccc35782c4d 100644 > --- a/drivers/vfio/mdev/mdev_private.h > +++ b/drivers/vfio/mdev/mdev_private.h > @@ -46,4 +46,16 @@ void mdev_remove_sysfs_files(struct mdev_device > *mdev); > int mdev_device_create(struct mdev_type *kobj, const guid_t *uuid); > int mdev_device_remove(struct mdev_device *dev); > > +void mdev_release_parent(struct kref *kref); > + > +static inline void mdev_get_parent(struct mdev_parent *parent) > +{ > + kref_get(&parent->ref); > +} > + > +static inline void mdev_put_parent(struct mdev_parent *parent) > +{ > + kref_put(&parent->ref, mdev_release_parent); > +} > + > #endif /* MDEV_PRIVATE_H */ > -- > 2.31.0
On Tue, 23 Mar 2021 14:55:23 -0300 Jason Gunthorpe <jgg@nvidia.com> wrote: > The next patch will use these in mdev_sysfs.c > > While here remove the now dead code checks for NULL, a mdev_type can never > have a NULL parent. > > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> > --- > drivers/vfio/mdev/mdev_core.c | 23 +++-------------------- > drivers/vfio/mdev/mdev_private.h | 12 ++++++++++++ > 2 files changed, 15 insertions(+), 20 deletions(-) Reviewed-by: Cornelia Huck <cohuck@redhat.com>
diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 5ca0efa5266bad..7ec21c907397a5 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -45,7 +45,7 @@ static struct mdev_parent *__find_parent_device(struct device *dev) return NULL; } -static void mdev_release_parent(struct kref *kref) +void mdev_release_parent(struct kref *kref) { struct mdev_parent *parent = container_of(kref, struct mdev_parent, ref); @@ -55,20 +55,6 @@ static void mdev_release_parent(struct kref *kref) put_device(dev); } -static struct mdev_parent *mdev_get_parent(struct mdev_parent *parent) -{ - if (parent) - kref_get(&parent->ref); - - return parent; -} - -static void mdev_put_parent(struct mdev_parent *parent) -{ - if (parent) - kref_put(&parent->ref, mdev_release_parent); -} - /* Caller must hold parent unreg_sem read or write lock */ static void mdev_device_remove_common(struct mdev_device *mdev) { @@ -243,12 +229,9 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) { int ret; struct mdev_device *mdev, *tmp; - struct mdev_parent *parent; - - parent = mdev_get_parent(type->parent); - if (!parent) - return -EINVAL; + struct mdev_parent *parent = type->parent; + mdev_get_parent(parent); mutex_lock(&mdev_list_lock); /* Check for duplicate */ diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index debf27f95b4f10..10eccc35782c4d 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -46,4 +46,16 @@ void mdev_remove_sysfs_files(struct mdev_device *mdev); int mdev_device_create(struct mdev_type *kobj, const guid_t *uuid); int mdev_device_remove(struct mdev_device *dev); +void mdev_release_parent(struct kref *kref); + +static inline void mdev_get_parent(struct mdev_parent *parent) +{ + kref_get(&parent->ref); +} + +static inline void mdev_put_parent(struct mdev_parent *parent) +{ + kref_put(&parent->ref, mdev_release_parent); +} + #endif /* MDEV_PRIVATE_H */
The next patch will use these in mdev_sysfs.c While here remove the now dead code checks for NULL, a mdev_type can never have a NULL parent. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> --- drivers/vfio/mdev/mdev_core.c | 23 +++-------------------- drivers/vfio/mdev/mdev_private.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 20 deletions(-)