* [PATCH 1/2] lib/string_choices: Add str_up_down() helper
@ 2024-07-25 10:18 Michal Wajdeczko
2024-07-25 10:18 ` [PATCH 2/2] coccinelle: Add rules to find str_up_down() replacements Michal Wajdeczko
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Michal Wajdeczko @ 2024-07-25 10:18 UTC (permalink / raw)
To: linux-hardening; +Cc: Michal Wajdeczko, Kees Cook, Andy Shevchenko
Add str_up_down() helper to return "up" or "down" string literal.
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
---
Cc: Kees Cook <keescook@chromium.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/string_choices.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/include/linux/string_choices.h b/include/linux/string_choices.h
index d9ebe20229f8..bcde3c9cff81 100644
--- a/include/linux/string_choices.h
+++ b/include/linux/string_choices.h
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/2] coccinelle: Add rules to find str_up_down() replacements
2024-07-25 10:18 [PATCH 1/2] lib/string_choices: Add str_up_down() helper Michal Wajdeczko
@ 2024-07-25 10:18 ` Michal Wajdeczko
2024-08-08 9:11 ` Andy Shevchenko
2024-08-06 4:40 ` [PATCH 1/2] lib/string_choices: Add str_up_down() helper Kees Cook
2024-08-08 9:10 ` Andy Shevchenko
2 siblings, 1 reply; 6+ messages in thread
From: Michal Wajdeczko @ 2024-07-25 10:18 UTC (permalink / raw)
To: linux-hardening; +Cc: Michal Wajdeczko, Kees Cook, Andy Shevchenko
Add rules for finding places where str_up_down() can be used.
This currently finds over 20 locations.
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
---
Cc: Kees Cook <keescook@chromium.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
./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(+)
diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci
index a71966c0494e..d517f6bc850b 100644
--- a/scripts/coccinelle/api/string_choices.cocci
+++ b/scripts/coccinelle/api/string_choices.cocci
@@ -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)
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] lib/string_choices: Add str_up_down() helper
2024-07-25 10:18 [PATCH 1/2] lib/string_choices: Add str_up_down() helper Michal Wajdeczko
2024-07-25 10:18 ` [PATCH 2/2] coccinelle: Add rules to find str_up_down() replacements Michal Wajdeczko
@ 2024-08-06 4:40 ` Kees Cook
2024-08-08 9:10 ` Andy Shevchenko
2 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2024-08-06 4:40 UTC (permalink / raw)
To: linux-hardening, Michal Wajdeczko; +Cc: Kees Cook, Andy Shevchenko
On Thu, 25 Jul 2024 12:18:40 +0200, Michal Wajdeczko wrote:
> Add str_up_down() helper to return "up" or "down" string literal.
>
>
Applied to for-next/hardening, thanks!
[1/2] lib/string_choices: Add str_up_down() helper
https://git.kernel.org/kees/c/3ff37dbb1ae9
[2/2] coccinelle: Add rules to find str_up_down() replacements
https://git.kernel.org/kees/c/d518b5f7f2d5
Take care,
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH 1/2] lib/string_choices: Add str_up_down() helper
2024-07-25 10:18 [PATCH 1/2] lib/string_choices: Add str_up_down() helper Michal Wajdeczko
2024-07-25 10:18 ` [PATCH 2/2] coccinelle: Add rules to find str_up_down() replacements Michal Wajdeczko
2024-08-06 4:40 ` [PATCH 1/2] lib/string_choices: Add str_up_down() helper Kees Cook
@ 2024-08-08 9:10 ` Andy Shevchenko
2024-08-08 17:57 ` Kees Cook
2 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2024-08-08 9:10 UTC (permalink / raw)
To: Michal Wajdeczko; +Cc: linux-hardening, Kees Cook
On Thu, Jul 25, 2024 at 12:18:40PM +0200, Michal Wajdeczko wrote:
> Add str_up_down() helper to return "up" or "down" string literal.
...
> +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?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH 1/2] lib/string_choices: Add str_up_down() helper
2024-08-08 9:10 ` Andy Shevchenko
@ 2024-08-08 17:57 ` Kees Cook
0 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2024-08-08 17:57 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Michal Wajdeczko, linux-hardening
On Thu, Aug 08, 2024 at 12:10:12PM +0300, Andy Shevchenko wrote:
> On Thu, Jul 25, 2024 at 12:18:40PM +0200, Michal Wajdeczko wrote:
> > Add str_up_down() helper to return "up" or "down" string literal.
>
> ...
>
> > +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))
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-08-08 17:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-25 10:18 [PATCH 1/2] lib/string_choices: Add str_up_down() helper Michal Wajdeczko
2024-07-25 10:18 ` [PATCH 2/2] coccinelle: Add rules to find str_up_down() replacements Michal Wajdeczko
2024-08-08 9:11 ` Andy Shevchenko
2024-08-06 4:40 ` [PATCH 1/2] lib/string_choices: Add str_up_down() helper Kees Cook
2024-08-08 9:10 ` Andy Shevchenko
2024-08-08 17:57 ` Kees Cook
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.