Re: [PATCH v1 1/2] irqdomain: Unify checks for bus_token

From: Matti Vaittinen
Date: Tue Aug 13 2024 - 05:41:35 EST


On 8/12/24 22:29, Andy Shevchenko wrote:
The code uses if (bus_token) and if (bus_token == DOMAIN_BUS_ANY).
Since bus_token is enum, the later is more robust against changes.
Unify all checks to follow the latter variant.

I don't really have a strong opinion on this but for me the
if (bus_token) reads better. Te bus_token is either set (and set to something else but zero), or not. This logic is nicely reflected by the check 'if (bus_token)'. Still, I suppose the 'DOMAIN_BUS_ANY' is for a reason, and some people indeed claim that consistency matters ;)

Fixes: 0b21add71bd9 ("irqdomain: Handle domain bus token in irq_domain_create()")
Fixes: 1bf2c9282927 ("irqdomain: Cleanup domain name allocation")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
---
kernel/irq/irqdomain.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 01001eb615ec..18d253e10e87 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -130,8 +130,10 @@ EXPORT_SYMBOL_GPL(irq_domain_free_fwnode);
static int alloc_name(struct irq_domain *domain, char *base, enum irq_domain_bus_token bus_token)
{
- domain->name = bus_token ? kasprintf(GFP_KERNEL, "%s-%d", base, bus_token) :
- kasprintf(GFP_KERNEL, "%s", base);
+ if (bus_token == DOMAIN_BUS_ANY)
+ domain->name = kasprintf(GFP_KERNEL, "%s", base);
+ else
+ domain->name = kasprintf(GFP_KERNEL, "%s-%d", base, bus_token);

You could do:
domain->name = bus_token == DOMAIN_BUS_ANY ? kasprintf(...
to squeeze this a bit more compact (and to maintain the previous style) - but my personal preference is to not have a ternary. Well, again nothing I would have a really strong opinion.

Anyways, the logic looks solid to me so, FWIW:

Reviewed-by: Matti Vaittinen <mazziesaccount@xxxxxxxxx>

Yours,
-- Matti

--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~