Re: [PATCH 08/11] vfio: selftests: Add dev_dbg

Jason Gunthorpe
2026-05-05T15:53:39Z

On Mon, May 04, 2026 at 09:15:38PM +0000, David Matlack wrote:
> On 2026-04-30 09:08 PM, Jason Gunthorpe wrote:
> > Enable it with a #define DEBUG at the top of the file. Allows leaving
> > behind debugging prints that are useful in case future changes are
> > required.
> >
> > Assisted-by: Claude:claude-opus-4.6
> > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> > ---
> > .../selftests/vfio/lib/include/libvfio/vfio_pci_device.h | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
> > diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h
> > index bb4525abd01a22..2d587b988c09fa 100644
> > --- a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h
> > +++ b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h
> > @@ -38,6 +38,12 @@ struct vfio_pci_device {
> > #define dev_info(_dev, _fmt, ...) printf("%s: " _fmt, (_dev)->bdf, ##__VA_ARGS__)
> > #define dev_err(_dev, _fmt, ...) fprintf(stderr, "%s: " _fmt, (_dev)->bdf, ##__VA_ARGS__)
> >
> > +#ifdef DEBUG
> > +#define dev_dbg dev_info
> > +#else
> > +#define dev_dbg(_dev, _fmt, ...) do { } while (0)
>
> Can you add something to make sure the format strings are still
> validated by the compiler even if DEBUG is not defined? (since it
> will almost never be defined). e.g.

Yeah, I did this with the usual "if (false) printk()" technique

Jason