Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp319631pxm; Wed, 2 Mar 2022 16:17:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJydzFYrXeZq+Zq9UURKUnvOssOl+MoYp4Ba1ZlgYiCgd9EL9zRsLsZtTp8JM98QnQDUUk5V X-Received: by 2002:a63:5451:0:b0:378:6b6c:ed83 with SMTP id e17-20020a635451000000b003786b6ced83mr20410545pgm.446.1646266641442; Wed, 02 Mar 2022 16:17:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646266641; cv=none; d=google.com; s=arc-20160816; b=HJuvpciYRr6lnul1HMUcjIiB3sUP7aDRnW9QbLof0npXIzkriAvhqLiKRMmZ7I9WvR Qk23jiZMzoJwxYlt/uNXBeLpecRPhXcYgXdgHg9l7fHxS6+V8PF425ZS/EuNhvNnoBEr TQZH6oJCAQc2g1Vmpv3q7Cvemr/LhtuEtT5GLNI7t28LOh+dEGQZwMeUaolxY7xRPlzv Ao1UqJP+v6WzvJNGEgU2YMlRvjMc1a54kMPLNbXhfV+IYg8iraE5XJba/FYHL7fHxahq YNE5filERy8r8KVpapX/TM73SntISGIByXuCYVzshd77a1wKhrAOpjwG93OuFa47bWU8 wwfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RoJ6KhPXk7RwGdhLlSmay7OZIFNg6mxUpxpaIs64SPw=; b=PvZqwH5+l9TrYw6ysJ3BUCZzT+umI2I15JOkLAC4aAEQjsRHzpEbqVR8KjgucoiOeq /JZPMALhG8y6OTPNUWUEICVqP9zBSPxrKywjfolXkcVbF7DoTVvjA5P87MRDWK/qLG2e JpymKbMgA11GwDxrVq29IjTJJWskAGH/GEB9cL3MgGBSBhi2XK1GjVAIOqkZgIOrwzcI k0/Eu3NOTxyvg6UdN+QdbsRwvg9le/SK5PLe03Ow3I44WoXpHsJvJf2A9Vaoyy5cf812 TA3n4iil1jCtqL3hfUajAMNUmT4wwt1bJOv2/TD4hQkYfzzd+VXM0Qm0tPpMrX3ZBme2 koww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=He6aO0Jg; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q1-20020a638c41000000b00372a8fb1571si517401pgn.344.2022.03.02.16.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 16:17:21 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=He6aO0Jg; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6F7881D6F53; Wed, 2 Mar 2022 15:31:19 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243186AbiCBQip (ORCPT + 99 others); Wed, 2 Mar 2022 11:38:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240513AbiCBQii (ORCPT ); Wed, 2 Mar 2022 11:38:38 -0500 X-Greylist: delayed 66 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 02 Mar 2022 08:37:54 PST Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D482F29CBC for ; Wed, 2 Mar 2022 08:37:53 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1646239072; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RoJ6KhPXk7RwGdhLlSmay7OZIFNg6mxUpxpaIs64SPw=; b=He6aO0JgCTzTNVfaICfLABWtZP0A3y0+aj6FYlfvf+mgRQAkTl3GWU/Tn7dKzAUWBQXWBe +5zV/8vXVNGiqruB3+klAWFioEYzmvGtBvAdTQqj8mMmuKz+GYYFtA2GylRDOYdKUN8grK ylTRltogUO+0CElKwAb2CS42S8905Es= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 07/22] kasan: simplify kasan_update_kunit_status and call sites Date: Wed, 2 Mar 2022 17:36:27 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Konovalov - 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. Signed-off-by: Andrey Konovalov --- mm/kasan/report.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 2d892ec050be..59db81211b8a 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -357,24 +357,31 @@ static bool report_enabled(void) } #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_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) { - kunit_set_failure(cur_test); + kunit_set_failure(test); return; } status = (struct kunit_kasan_status *)resource->data; WRITE_ONCE(status->report_found, true); WRITE_ONCE(status->sync_fault, sync); + 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) { @@ -383,10 +390,7 @@ void kasan_report_invalid_free(void *object, unsigned long ip) object = kasan_reset_tag(object); -#if IS_ENABLED(CONFIG_KUNIT) - if (current->kunit_test) - kasan_update_kunit_status(current->kunit_test, true); -#endif /* IS_ENABLED(CONFIG_KUNIT) */ + update_kunit_status(true); start_report(&flags); 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; -#if IS_ENABLED(CONFIG_KUNIT) - if (current->kunit_test) - kasan_update_kunit_status(current->kunit_test, false); -#endif /* IS_ENABLED(CONFIG_KUNIT) */ + update_kunit_status(false); start_report(&flags); 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; unsigned long flags; -#if IS_ENABLED(CONFIG_KUNIT) - if (current->kunit_test) - kasan_update_kunit_status(current->kunit_test, true); -#endif /* IS_ENABLED(CONFIG_KUNIT) */ + update_kunit_status(true); disable_trace_on_warning(); -- 2.25.1