Re: [PATCH v3 1/3] vfio/pci: Extract duplicated code into macro

Gerd Bayer
2024-05-17T14:22:59Z

On Mon, 2024-04-29 at 10:31 -0600, Alex Williamson wrote:
> On Thu, 25 Apr 2024 18:56:02 +0200
> Gerd Bayer <gbayer@linux.ibm.com> wrote:
>
> > vfio_pci_core_do_io_rw() repeats the same code for multiple access
> > widths. Factor this out into a macro
> >
> > Suggested-by: Alex Williamson <alex.williamson@redhat.com>
> > Signed-off-by: Gerd Bayer <gbayer@linux.ibm.com>
> > ---
> >  drivers/vfio/pci/vfio_pci_rdwr.c | 106 ++++++++++++++-------------
> > ----
> >  1 file changed, 46 insertions(+), 60 deletions(-)
> >
> > diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c
> > b/drivers/vfio/pci/vfio_pci_rdwr.c
> > index 03b8f7ada1ac..3335f1b868b1 100644
> > --- a/drivers/vfio/pci/vfio_pci_rdwr.c
> > +++ b/drivers/vfio/pci/vfio_pci_rdwr.c
> > @@ -90,6 +90,40 @@ VFIO_IOREAD(8)
> >  VFIO_IOREAD(16)
> >  VFIO_IOREAD(32)
> >
> > +#define
> > VFIO_IORDWR(size) \
> > +static int vfio_pci_core_iordwr##size(struct vfio_pci_core_device
> > *vdev,\
> > + bool iswrite, bool
> > test_mem, \
> > + void __iomem *io, char __user
> > *buf, \
> > + loff_t off, size_t
> > *filled) \
>
> I realized later after proposing this that we should drop 'core' from
> the name since the resulting functions are not currently exported.
> It also helps with the wordiness.  Thanks,
>
> Alex
>
>
Sure that's easy enough.

Thanks, Gerd