mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-26 05:34:13 +08:00
kasan: simplify kasan_update_kunit_status() and call sites
- Rename kasan_update_kunit_status() to update_kunit_status() (the function is static). - Move the IS_ENABLED(CONFIG_KUNIT) to the function's definition instead of duplicating it at call sites. - Obtain and check current->kunit_test within the function. Link: https://lkml.kernel.org/r/dac26d811ae31856c3d7666de0b108a3735d962d.1646237226.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Reviewed-by: Alexander Potapenko <glider@google.com> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Marco Elver <elver@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
476b1dc2bc
commit
3784c299ea
@ -357,24 +357,31 @@ static bool report_enabled(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_KUNIT)
|
#if IS_ENABLED(CONFIG_KUNIT)
|
||||||
static void kasan_update_kunit_status(struct kunit *cur_test, bool sync)
|
static void update_kunit_status(bool sync)
|
||||||
{
|
{
|
||||||
|
struct kunit *test;
|
||||||
struct kunit_resource *resource;
|
struct kunit_resource *resource;
|
||||||
struct kunit_kasan_status *status;
|
struct kunit_kasan_status *status;
|
||||||
|
|
||||||
resource = kunit_find_named_resource(cur_test, "kasan_status");
|
test = current->kunit_test;
|
||||||
|
if (!test)
|
||||||
|
return;
|
||||||
|
|
||||||
|
resource = kunit_find_named_resource(test, "kasan_status");
|
||||||
if (!resource) {
|
if (!resource) {
|
||||||
kunit_set_failure(cur_test);
|
kunit_set_failure(test);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = (struct kunit_kasan_status *)resource->data;
|
status = (struct kunit_kasan_status *)resource->data;
|
||||||
WRITE_ONCE(status->report_found, true);
|
WRITE_ONCE(status->report_found, true);
|
||||||
WRITE_ONCE(status->sync_fault, sync);
|
WRITE_ONCE(status->sync_fault, sync);
|
||||||
|
|
||||||
kunit_put_resource(resource);
|
kunit_put_resource(resource);
|
||||||
}
|
}
|
||||||
#endif /* IS_ENABLED(CONFIG_KUNIT) */
|
#else
|
||||||
|
static void update_kunit_status(bool sync) { }
|
||||||
|
#endif
|
||||||
|
|
||||||
void kasan_report_invalid_free(void *object, unsigned long ip)
|
void kasan_report_invalid_free(void *object, unsigned long ip)
|
||||||
{
|
{
|
||||||
@ -383,10 +390,7 @@ void kasan_report_invalid_free(void *object, unsigned long ip)
|
|||||||
|
|
||||||
object = kasan_reset_tag(object);
|
object = kasan_reset_tag(object);
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_KUNIT)
|
update_kunit_status(true);
|
||||||
if (current->kunit_test)
|
|
||||||
kasan_update_kunit_status(current->kunit_test, true);
|
|
||||||
#endif /* IS_ENABLED(CONFIG_KUNIT) */
|
|
||||||
|
|
||||||
start_report(&flags);
|
start_report(&flags);
|
||||||
pr_err("BUG: KASAN: double-free or invalid-free in %pS\n", (void *)ip);
|
pr_err("BUG: KASAN: double-free or invalid-free in %pS\n", (void *)ip);
|
||||||
@ -402,10 +406,7 @@ void kasan_report_async(void)
|
|||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_KUNIT)
|
update_kunit_status(false);
|
||||||
if (current->kunit_test)
|
|
||||||
kasan_update_kunit_status(current->kunit_test, false);
|
|
||||||
#endif /* IS_ENABLED(CONFIG_KUNIT) */
|
|
||||||
|
|
||||||
start_report(&flags);
|
start_report(&flags);
|
||||||
pr_err("BUG: KASAN: invalid-access\n");
|
pr_err("BUG: KASAN: invalid-access\n");
|
||||||
@ -424,10 +425,7 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write,
|
|||||||
void *untagged_addr;
|
void *untagged_addr;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_KUNIT)
|
update_kunit_status(true);
|
||||||
if (current->kunit_test)
|
|
||||||
kasan_update_kunit_status(current->kunit_test, true);
|
|
||||||
#endif /* IS_ENABLED(CONFIG_KUNIT) */
|
|
||||||
|
|
||||||
disable_trace_on_warning();
|
disable_trace_on_warning();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user