Skip to contentSkip to conversation

drivers/net/ethernet/sfc/: Simplify code

PATCH In review Alejandro Colomar 2 participants 3 messages Nov 20, 2021 – Nov 22, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/net/ethernet/sfc/: Simplify code

That ternary operator has
the same exact code in both of the branches.

Unless there's some hidden magic in the condition, there's no reason for it to be,
and it can be replaced
by the code in one of the branches.

That code has been untouched since it was added,
so there's no information in git about
why it was written that way.

---
 drivers/net/ethernet/sfc/ethtool_common.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/net/ethernet/sfc/ethtool_common.c +1 -4
index bd552c7dffcb..1b9e8b0afb3c 100644
@@ -33,10 +33,7 @@ struct efx_sw_stat_desc {
 				get_stat_function) {			\
 	.name = #stat_name,						\
 	.source = EFX_ETHTOOL_STAT_SOURCE_##source_name,		\
-	.offset = ((((field_type *) 0) ==				\
-		      &((struct efx_##source_name *)0)->field) ?	\
-		    offsetof(struct efx_##source_name, field) :		\
-		    offsetof(struct efx_##source_name, field)),		\
+	.offset = offsetof(struct efx_##source_name, field),		\
 	.get_stat = get_stat_function,					\
 }
 
Signature · 1 line
2.33.1
maintainer
#1 lore raw
Quoted 8 lines · Alejandro Colomar

That ternary operator has
the same exact code in both of the branches.

Unless there's some hidden magic in the condition, there's no reason for it to be,
and it can be replaced
by the code in one of the branches.

Quoted 8 lines

That code has been untouched since it was added,
so there's no information in git about
why it was written that way.

I guess it's there for type-checking — essentially as an assert that
field_type == typeof(efx_##source_name.field). Probably when it was added there was no standard way to do this; now we could probably use <linux/typecheck.h> or some such.
The comment just above the macro does mention "with type-checking".

-ed

#2 lore raw

Hi Edward,

Quoted 18 lines · Edward Cree
Quoted 8 lines · Alejandro Colomar

That ternary operator has
the same exact code in both of the branches.

Unless there's some hidden magic in the condition, there's no reason for it to be,
and it can be replaced
by the code in one of the branches.

Quoted 8 lines

That code has been untouched since it was added,
so there's no information in git about
why it was written that way.

Quoted 5 lines

I guess it's there for type-checking — essentially as an assert that
field_type == typeof(efx_##source_name.field). Probably when it was added there was no standard way to do this; now we could probably use <linux/typecheck.h> or some such.
The comment just above the macro does mention "with type-checking".

Yes, that's why I suggested there was probably some black magic involved. But I couldn't read it, though.

I suggest replacing it with a static_assert(__same_type()) thingy.

Cheers,
Alex

Signature · 3 lines
Alejandro Colomar
Linux man-pages comaintainer; http://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/