Skip to contentSkip to conversation

lib/string_choices: Add str_up_down() helper

PATCH Applied Michal Wajdeczko 3 participants 6 messages Jul 25, 2024 – Aug 8, 2024

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

PATCH 1/2 lib/string_choices: Add str_up_down() helper

Add str_up_down() helper to return "up" or "down" string literal.

---
Cc: Kees Cook <[email protected]>
Cc: Andy Shevchenko <[email protected]>

---
 include/linux/string_choices.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/string_choices.h +5 -0
index d9ebe20229f8..bcde3c9cff81 100644
@@ -42,6 +42,11 @@ static inline const char *str_yes_no(bool v)
 	return v ? "yes" : "no";
 }
 
+static inline const char *str_up_down(bool v)
+{
+	return v ? "up" : "down";
+}
+
 /**
  * str_plural - Return the simple pluralization based on English counts
  * @num: Number used for deciding pluralization
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 coccinelle: Add rules to find str_up_down() replacements

Add rules for finding places where str_up_down() can be used. This currently finds over 20 locations.

---
Cc: Kees Cook <[email protected]>
Cc: Andy Shevchenko <[email protected]>
---
./drivers/net/bonding/bond_sysfs.c:511:32-38: opportunity for str_up_down(active) ./drivers/net/bonding/bond_procfs.c:101:37-64: opportunity for str_up_down(netif_carrier_ok ( bond -> dev )) ./drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:6088:5-36: opportunity for str_up_down(e -> flags & BRCMF_EVENT_MSG_LINK) ./drivers/media/platform/ti/cal/cal-camerarx.c:194:3-9: opportunity for str_up_down(enable) ./drivers/net/dsa/mv88e6xxx/port.c:178:2-38: opportunity for str_up_down(reg & MV88E6XXX_PORT_MAC_CTL_LINK_UP) ./drivers/net/ethernet/faraday/ftgmac100.c:1737:5-16: opportunity for str_up_down(nd -> link_up) ./drivers/pinctrl/pinctrl-stmfx.c:382:7-11: opportunity for str_up_down(pupd) ./drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c:2175:6-14: opportunity for str_up_down(state . up) ./drivers/block/aoe/aoeblk.c:40:4-23: opportunity for str_up_down(d -> flags & DEVFL_UP) ./drivers/ntb/test/ntb_perf.c:1224:3-39: opportunity for str_up_down(test_bit ( PERF_STS_LNKUP , & peer -> sts )) ./drivers/crypto/intel/qat/qat_common/adf_sysfs.c:28:9-35: opportunity for str_up_down(adf_dev_started ( accel_dev )) ./drivers/fsi/fsi-sbefifo.c:459:39-41: opportunity for str_up_down(up)
./net/ncsi/ncsi-manage.c:1282:8-26: opportunity for str_up_down(ncm -> data [ 2 ] & 0x1) ./net/ncsi/ncsi-aen.c:78:13-23: opportunity for str_up_down(data & 0x1)
./drivers/net/phy/phylink.c:1788:49-51: opportunity for str_up_down(up)
./drivers/net/phy/phylink.c:2109:39-41: opportunity for str_up_down(up)
./drivers/ntb/test/ntb_tool.c:299:2-4: opportunity for str_up_down(up)
./drivers/ufs/core/ufshcd.c:1186:4-12: opportunity for str_up_down(scale_up) ./drivers/ufs/core/ufshcd.c:1559:3-11: opportunity for str_up_down(scale_up) ./drivers/ntb/hw/mscc/ntb_hw_switchtec.c:513:4-12: opportunity for str_up_down(link_sta) ./drivers/ata/sata_via.c:362:8-14: opportunity for str_up_down(online) ./drivers/usb/host/oxu210hp-hcd.c:2784:39-44: opportunity for str_up_down(is_on) ./drivers/net/ethernet/smsc/smc91x.c:1178:8-19: opportunity for str_up_down(new_carrier)

---
 scripts/coccinelle/api/string_choices.cocci | 23 +++++++++++++++++++++
 1 file changed, 23 insertions(+)
scripts/coccinelle/api/string_choices.cocci +23 -0
index a71966c0494e..d517f6bc850b 100644
@@ -39,3 +39,26 @@ e << str_plural_r.E;
 @@
 
 coccilib.report.print_report(p[0], "opportunity for str_plural(%s)" % e)
+
+@str_up_down depends on patch@
+expression E;
+@@
+(
+-	((E) ? "up" : "down")
++	str_up_down(E)
+)
+
+@str_up_down_r depends on !patch exists@
+expression E;
+position P;
+@@
+(
+*	((E@P) ? "up" : "down")
+)
+
+@script:python depends on report@
+p << str_up_down_r.P;
+e << str_up_down_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_up_down(%s)" % e)
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 2/2] coccinelle: Add rules to find str_up_down() replacements

Quoted 2 lines · Michal Wajdeczko

Add rules for finding places where str_up_down() can be used. This currently finds over 20 locations.

This would be need an update as well in accordance with the review comment on patch 1.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
In reply to Michal Wajdeczko
Quoted 1 line · Michal Wajdeczko

Add str_up_down() helper to return "up" or "down" string literal.

...

include/linux/string_choices.h static inline const char *str_yes_no(bool v) · line 48

Quoted 4 lines
include/linux/string_choices.h +4 -0
+static inline const char *str_up_down(bool v)
+{
+	return v ? "up" : "down";
+}

Can you please add a respective macro for str_down_up() as it's done for (some) others?

P.S. Yes, I see these two has been applied, so perhaps followup?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#5 lore raw
Quoted 5 lines · Andy Shevchenko
Quoted 1 line · Michal Wajdeczko

Add str_up_down() helper to return "up" or "down" string literal.

...

Quoted 7 lines

include/linux/string_choices.h static inline const char *str_yes_no(bool v) · line 48

Quoted 4 lines
include/linux/string_choices.h +4 -0
+static inline const char *str_up_down(bool v)
+{
+	return v ? "up" : "down";
+}

Can you please add a respective macro for str_down_up() as it's done for (some) others?

e.g.

#define str_down_up(v) str_up_down(!(v))

Signature · 1 line
Kees Cook