Re: [PATCH v5] printk: Userspace format enumeration support

From: Chris Down
Date: Fri Apr 16 2021 - 09:56:34 EST


Hey Petr, Rasmus,

Apologies for the delay, I've been out ill for a while so I'm just coming back to look at this.

Petr Mladek writes:
Anyway, on to the other thing I mentioned on dev_err and friends: I
think it would improve readability and make it a lot easier to (probably
in a later patch) add support for all those dev_* and net_* and whatever
other subsystems have their own wrappers

This is great point! There are many other subsystem specific wrappers,
e,g, ata_dev_printk(), netdev_printk(), snd_printk(), dprintk().
We should make it easy to index them as well.

These would be nice to have, but we should agree about how we store things internally.

For example, in printk we typically store the level inline as part of the format string at compile time. However, for `dev_printk`, it's passed entirely separately from the format string after preprocessing is already concluded (or at least, not in a way we can easily parse it the same way we do for printk()):

void dev_printk(const char *level, const struct device *dev, const char *fmt, ...)

One (ugly) way to handle this would be to have a new "level" field in the printk index entry, with semantics that if it's some sentinel value, look at the format itself for the format, otherwise if it's some other value, the level field itself is the level.

This will work, but it's pretty ugly. Any better suggestions? :-)

Thanks,

Chris