Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

[PATCH] mm/kfence: Use str_write_read() helper in get_access_type()

0 views
Skip to first unread message

Thorsten Blum

unread,
Jan 15, 2025, 4:03:19 AMJan 15
to Alexander Potapenko, Marco Elver, Dmitry Vyukov, Andrew Morton, Thorsten Blum, Anshuman Khandual, kasa...@googlegroups.com, linu...@kvack.org, linux-...@vger.kernel.org
Remove hard-coded strings by using the str_write_read() helper function.

Suggested-by: Anshuman Khandual <anshuman...@arm.com>
Signed-off-by: Thorsten Blum <thorst...@linux.dev>
---
mm/kfence/kfence_test.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c
index f65fb182466d..00034e37bc9f 100644
--- a/mm/kfence/kfence_test.c
+++ b/mm/kfence/kfence_test.c
@@ -20,6 +20,7 @@
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/string.h>
+#include <linux/string_choices.h>
#include <linux/tracepoint.h>
#include <trace/events/printk.h>

@@ -88,7 +89,7 @@ struct expect_report {

static const char *get_access_type(const struct expect_report *r)
{
- return r->is_write ? "write" : "read";
+ return str_write_read(r->is_write);
}

/* Check observed report matches information in @r. */
--
2.47.1

Marco Elver

unread,
Jan 15, 2025, 4:48:13 AMJan 15
to Thorsten Blum, Alexander Potapenko, Dmitry Vyukov, Andrew Morton, Anshuman Khandual, kasa...@googlegroups.com, linu...@kvack.org, linux-...@vger.kernel.org
On Wed, 15 Jan 2025 at 10:03, Thorsten Blum <thorst...@linux.dev> wrote:
>
> Remove hard-coded strings by using the str_write_read() helper function.
>
> Suggested-by: Anshuman Khandual <anshuman...@arm.com>
> Signed-off-by: Thorsten Blum <thorst...@linux.dev>
> ---
> mm/kfence/kfence_test.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)

Why only change the one in kfence_test.c?

$ grep '"read"' mm/kfence/*
mm/kfence/kfence_test.c: return r->is_write ? "write" : "read";
mm/kfence/report.c: return is_write ? "write" : "read";

> diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c
> index f65fb182466d..00034e37bc9f 100644
> --- a/mm/kfence/kfence_test.c
> +++ b/mm/kfence/kfence_test.c
> @@ -20,6 +20,7 @@
> #include <linux/slab.h>
> #include <linux/spinlock.h>
> #include <linux/string.h>
> +#include <linux/string_choices.h>
> #include <linux/tracepoint.h>
> #include <trace/events/printk.h>
>
> @@ -88,7 +89,7 @@ struct expect_report {
>
> static const char *get_access_type(const struct expect_report *r)
> {
> - return r->is_write ? "write" : "read";
> + return str_write_read(r->is_write);
> }
>
> /* Check observed report matches information in @r. */
> --
> 2.47.1
>
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/kasan-dev/20250115090303.918192-2-thorsten.blum%40linux.dev.

Thorsten Blum

unread,
Jan 15, 2025, 10:56:10 AMJan 15
to Alexander Potapenko, Marco Elver, Dmitry Vyukov, Andrew Morton, Thorsten Blum, Anshuman Khandual, kasa...@googlegroups.com, linu...@kvack.org, linux-...@vger.kernel.org
Remove hard-coded strings by using the str_write_read() helper function.

Suggested-by: Anshuman Khandual <anshuman...@arm.com>
Signed-off-by: Thorsten Blum <thorst...@linux.dev>
---
Changes in v2:
- Use str_write_read() in report.c as suggested by Marco Elver (thanks!)
- Link to v1: https://lore.kernel.org/r/20250115090303.918...@linux.dev/
---
mm/kfence/kfence_test.c | 3 ++-
mm/kfence/report.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c
index f65fb182466d..00034e37bc9f 100644
--- a/mm/kfence/kfence_test.c
+++ b/mm/kfence/kfence_test.c
@@ -20,6 +20,7 @@
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/string.h>
+#include <linux/string_choices.h>
#include <linux/tracepoint.h>
#include <trace/events/printk.h>

@@ -88,7 +89,7 @@ struct expect_report {

static const char *get_access_type(const struct expect_report *r)
{
- return r->is_write ? "write" : "read";
+ return str_write_read(r->is_write);
}

/* Check observed report matches information in @r. */
diff --git a/mm/kfence/report.c b/mm/kfence/report.c
index 6370c5207d1a..10e6802a2edf 100644
--- a/mm/kfence/report.c
+++ b/mm/kfence/report.c
@@ -16,6 +16,7 @@
#include <linux/sprintf.h>
#include <linux/stacktrace.h>
#include <linux/string.h>
+#include <linux/string_choices.h>
#include <linux/sched/clock.h>
#include <trace/events/error_report.h>

@@ -184,7 +185,7 @@ static void print_diff_canary(unsigned long address, size_t bytes_to_show,

static const char *get_access_type(bool is_write)
{
- return is_write ? "write" : "read";
+ return str_write_read(is_write);
}

void kfence_report_error(unsigned long address, bool is_write, struct pt_regs *regs,
--
2.47.1

Marco Elver

unread,
Jan 15, 2025, 11:21:06 AMJan 15
to Thorsten Blum, Alexander Potapenko, Dmitry Vyukov, Andrew Morton, Anshuman Khandual, kasa...@googlegroups.com, linu...@kvack.org, linux-...@vger.kernel.org
On Wed, 15 Jan 2025 at 16:56, Thorsten Blum <thorst...@linux.dev> wrote:
>
> Remove hard-coded strings by using the str_write_read() helper function.
>
> Suggested-by: Anshuman Khandual <anshuman...@arm.com>
> Signed-off-by: Thorsten Blum <thorst...@linux.dev>
> ---
> Changes in v2:
> - Use str_write_read() in report.c as suggested by Marco Elver (thanks!)
> - Link to v1: https://lore.kernel.org/r/20250115090303.918...@linux.dev/

Reviewed-by: Marco Elver <el...@google.com>
Reply all
Reply to author
Forward
0 new messages