Re: [PATCH rdma-next v4 01/12] RDMA/core: Introduce RDMA subsystem ibdev_* print functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Apr 02, 2019 at 10:05:00AM +0300, Gal Pressman wrote:
> >>>> +#elif defined(DEBUG)
> >>>> +#define ibdev_dbg(__dev, format, args...)                       \
> >>>> +	ibdev_printk(KERN_DEBUG, __dev, format, ##args)
> >>>> +#else
> >>>> +#define ibdev_dbg(__dev, format, args...)                       \
> >>>> +({                                                              \
> >>>> +	if (0)                                                  \
> >>>
> >>> Why isn't "empty macro" enough here and we need "if (0)"?
> >>
> >> I was wondering as well :).
> >> This is copied from the netdev_dbg counterpart, my best guess is some kind of
> >> compilation checks in case debug is disabled but I can't even convince myself..
> > 
> > It is a trick to get the compiler to do a format & type check even
> > when debug is disabled.
> > 
> > Personally I prefer the much clearer non #define version
> > 
> > __printf(2, 3)
> > static inline void ibdev_dbg(const struct ib_device *dev, const char
> > *format, ...) {}
> > 
> > Instead of the macro tricks.
> 
> Wouldn't that lose the format type checking? For example passing a pointer to %d?

No, the static inline has the __printf attribute so the compiler checks it even
though the inline is empty

Jason



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux