Message ID | 11-v2-20d933792272+4ff-vfio1_jgg@nvidia.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Embed struct vfio_device in all sub-structures | expand |
> From: Jason Gunthorpe <jgg@nvidia.com> > Sent: Saturday, March 13, 2021 8:56 AM > > The macro wrongly uses 'dev' as both the macro argument and the member > name, which means it fails compilation if any caller uses a word other > than 'dev' as the single argument. Fix this defect by making it into > proper static inline, which is more clear and typesafe anyhow. > > Reviewed-by: Christoph Hellwig <hch@lst.de> > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> > --- > drivers/vfio/mdev/mdev_private.h | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/vfio/mdev/mdev_private.h > b/drivers/vfio/mdev/mdev_private.h > index 7d922950caaf3c..74c2e541146999 100644 > --- a/drivers/vfio/mdev/mdev_private.h > +++ b/drivers/vfio/mdev/mdev_private.h > @@ -35,7 +35,10 @@ struct mdev_device { > bool active; > }; > > -#define to_mdev_device(dev) container_of(dev, struct mdev_device, dev) > +static inline struct mdev_device *to_mdev_device(struct device *dev) > +{ > + return container_of(dev, struct mdev_device, dev); > +} > #define dev_is_mdev(d) ((d)->bus == &mdev_bus_type) > > struct mdev_type { > -- > 2.30.2
On Fri, 12 Mar 2021 20:56:03 -0400 Jason Gunthorpe <jgg@nvidia.com> wrote: > The macro wrongly uses 'dev' as both the macro argument and the member > name, which means it fails compilation if any caller uses a word other > than 'dev' as the single argument. Fix this defect by making it into > proper static inline, which is more clear and typesafe anyhow. > > Reviewed-by: Christoph Hellwig <hch@lst.de> > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> > --- > drivers/vfio/mdev/mdev_private.h | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h > index 7d922950caaf3c..74c2e541146999 100644 > --- a/drivers/vfio/mdev/mdev_private.h > +++ b/drivers/vfio/mdev/mdev_private.h > @@ -35,7 +35,10 @@ struct mdev_device { > bool active; > }; > > -#define to_mdev_device(dev) container_of(dev, struct mdev_device, dev) > +static inline struct mdev_device *to_mdev_device(struct device *dev) > +{ > + return container_of(dev, struct mdev_device, dev); > +} > #define dev_is_mdev(d) ((d)->bus == &mdev_bus_type) > > struct mdev_type { Fixes: 99e3123e3d72 ("vfio-mdev: Make mdev_device private and abstract interfaces")
On Tue, Mar 16, 2021 at 04:55:27PM -0600, Alex Williamson wrote: > On Fri, 12 Mar 2021 20:56:03 -0400 > Jason Gunthorpe <jgg@nvidia.com> wrote: > > > The macro wrongly uses 'dev' as both the macro argument and the member > > name, which means it fails compilation if any caller uses a word other > > than 'dev' as the single argument. Fix this defect by making it into > > proper static inline, which is more clear and typesafe anyhow. > > > > Reviewed-by: Christoph Hellwig <hch@lst.de> > > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> > > drivers/vfio/mdev/mdev_private.h | 5 ++++- > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h > > index 7d922950caaf3c..74c2e541146999 100644 > > +++ b/drivers/vfio/mdev/mdev_private.h > > @@ -35,7 +35,10 @@ struct mdev_device { > > bool active; > > }; > > > > -#define to_mdev_device(dev) container_of(dev, struct mdev_device, dev) > > +static inline struct mdev_device *to_mdev_device(struct device *dev) > > +{ > > + return container_of(dev, struct mdev_device, dev); > > +} > > #define dev_is_mdev(d) ((d)->bus == &mdev_bus_type) > > > > struct mdev_type { > > Fixes: 99e3123e3d72 ("vfio-mdev: Make mdev_device private and abstract interfaces") Ok, but it isn't a bug until the next patch that adds new callers for to_mdev_device() Jason
On Fri, 12 Mar 2021 20:56:03 -0400 Jason Gunthorpe <jgg@nvidia.com> wrote: > The macro wrongly uses 'dev' as both the macro argument and the member > name, which means it fails compilation if any caller uses a word other > than 'dev' as the single argument. Fix this defect by making it into > proper static inline, which is more clear and typesafe anyhow. > > Reviewed-by: Christoph Hellwig <hch@lst.de> > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> > --- > drivers/vfio/mdev/mdev_private.h | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) Reviewed-by: Cornelia Huck <cohuck@redhat.com>
diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index 7d922950caaf3c..74c2e541146999 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -35,7 +35,10 @@ struct mdev_device { bool active; }; -#define to_mdev_device(dev) container_of(dev, struct mdev_device, dev) +static inline struct mdev_device *to_mdev_device(struct device *dev) +{ + return container_of(dev, struct mdev_device, dev); +} #define dev_is_mdev(d) ((d)->bus == &mdev_bus_type) struct mdev_type {