From patchwork Fri Nov 10 20:08:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 13452742 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F1A9C4332F for ; Fri, 10 Nov 2023 20:08:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 38CB710E238; Fri, 10 Nov 2023 20:08:40 +0000 (UTC) Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by gabe.freedesktop.org (Postfix) with ESMTPS id 60C0F10E238 for ; Fri, 10 Nov 2023 20:08:39 +0000 (UTC) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da13698a6d3so3141750276.0 for ; Fri, 10 Nov 2023 12:08:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699646918; x=1700251718; darn=lists.freedesktop.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=4YunHZgtb5nkD4PkAgnIRkW9gO+ZcmaQMUyBJXXvNgg=; b=Ycw+xOer7SjdcpwvpBoGKvEdvRQCfZ3dUqM/ZOnwCt0SP2QxSHEb47MmYGTi9RlQsR RVnsqMIgt9tgdqQ9dyI0wwSn2xRg5FEGgvvxhQ0w5zX8YRZDIqWvKyNUhi2DfbvxKP2x qij/RY6fGFr8/VskksHyXqMzzU+47feEc8ogko97rPmDRk6DLrjuJpw2hgUI8ZleWKlM Kif1iio65XZ7u4JJiRgQ5agq7Gbcqq7a8vSUTXspfP92UxEUSWu4pjSz66ffpGnPrUCI UJkCAhjPnmyBz5spo6cR8Xwp+DogeEqolgR5GJM900K0aYEwn7Ey9ezZ6x6e59WyEy88 4gQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699646918; x=1700251718; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4YunHZgtb5nkD4PkAgnIRkW9gO+ZcmaQMUyBJXXvNgg=; b=Auc3cHtBD7mg4vKAsywmemiHM0NOp+b1M8j+0NMbEaA4WNdgbk2ttFf9QXol6MFin5 rfb+cOijzutPsKWwdZ8wYXg5XCV1QRHUUS44qcKak75l3YT7gAhNG2CBWQvWkVLXo/wJ z/j9ADsSbIJfTMXHcwLvYGLVRL1p3wdKws9odYEjjNL6xMEGVKnjOFbDtaw7fvGNZJtu Wy9w2ql47fvq0BwuxLH+BXhn0g73jrsEzW0NcsS20oFNhLMN4Q6JOTofAcAXL1EWMP6V v9zOXvG64I41Dysf9nL6WtGJgHzoyhRPx39fmR7xV0peUTHdq+EqcqpDo+HCJxDNBKsa ZmZw== X-Gm-Message-State: AOJu0YzvJfBZFy/unj1eicCHlqdZRsR6p0f7Dg/1WeWbyjEfyQMNfUgO 1NJDrkS/OriO84LryoUq3sgInC+yvIGfWw== X-Google-Smtp-Source: AGHT+IHpA8elPSDmxOHqJghOs6XywJyufpnZHYdeTgE8gm6TvPMzYUyvszmAZYiKI4lKiyHTNGpdXhSKe/S/Cw== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a25:d849:0:b0:d9a:f3dc:7d18 with SMTP id p70-20020a25d849000000b00d9af3dc7d18mr3271ybg.13.1699646918475; Fri, 10 Nov 2023 12:08:38 -0800 (PST) Date: Sat, 11 Nov 2023 04:08:26 +0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231110200830.1832556-1-davidgow@google.com> Subject: [PATCH 1/3] kunit: Add a macro to wrap a deferred action function From: David Gow To: Nathan Chancellor , Kees Cook , Brendan Higgins , Rae Moar , dlatypov@google.com, Maxime Ripard , Arthur Grillo , Shuah Khan X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kselftest@vger.kernel.org, David Gow , Emma Anholt , Benjamin Berg , Thomas Zimmermann , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, =?utf-8?q?Ma?= =?utf-8?q?=C3=ADra_Canal?= , Richard Fitzgerald , linux-hardening@vger.kernel.org, Sami Tolvanen , kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" KUnit's deferred action API accepts a void(*)(void *) function pointer which is called when the test is exited. However, we very frequently want to use existing functions which accept a single pointer, but which may not be of type void*. While this is probably dodgy enough to be on the wrong side of the C standard, it's been often used for similar callbacks, and gcc's -Wcast-function-type seems to ignore cases where the only difference is the type of the argument, assuming it's compatible (i.e., they're both pointers to data). However, clang 16 has introduced -Wcast-function-type-strict, which no longer permits any deviation in function pointer type. This seems to be because it'd break CFI, which validates the type of function calls. This rather ruins our attempts to cast functions to defer them, and leaves us with a few options. The one we've chosen is to implement a macro which will generate a wrapper function which accepts a void*, and casts the argument to the appropriate type. For example, if you were trying to wrap: void foo_close(struct foo *handle); you could use: KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_foo_close, foo_close, struct foo *); This would create a new kunit_action_foo_close() function, of type kunit_action_t, which could be passed into kunit_add_action() and similar functions. In addition to defining this macro, update KUnit and its tests to use it. Link: https://github.com/ClangBuiltLinux/linux/issues/1750 Signed-off-by: David Gow Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor Reviewed-by: Maxime Ripard Acked-by: Daniel Vetter for merging through kunit --- This is a follow-up to the RFC here: https://lore.kernel.org/linux-kselftest/20230915050125.3609689-1-davidgow@google.com/ There's no difference in the macro implementation, just an update to the KUnit tests to use it. This version is intended to complement: https://lore.kernel.org/all/20231106172557.2963-1-rf@opensource.cirrus.com/ There are also two follow-up patches in the series to use this macro in various DRM tests. Hopefully this will solve any CFI issues that show up with KUnit. Thanks, -- David --- include/kunit/resource.h | 9 +++++++++ lib/kunit/kunit-test.c | 5 +---- lib/kunit/test.c | 6 ++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/kunit/resource.h b/include/kunit/resource.h index c7383e90f5c9..4110e13970dc 100644 --- a/include/kunit/resource.h +++ b/include/kunit/resource.h @@ -390,6 +390,15 @@ void kunit_remove_resource(struct kunit *test, struct kunit_resource *res); /* A 'deferred action' function to be used with kunit_add_action. */ typedef void (kunit_action_t)(void *); +/* We can't cast function pointers to kunit_action_t if CFI is enabled. */ +#define KUNIT_DEFINE_ACTION_WRAPPER(wrapper, orig, arg_type) \ + static void wrapper(void *in) \ + { \ + arg_type arg = (arg_type)in; \ + orig(arg); \ + } + + /** * kunit_add_action() - Call a function when the test ends. * @test: Test case to associate the action with. diff --git a/lib/kunit/kunit-test.c b/lib/kunit/kunit-test.c index de2113a58fa0..ee6927c60979 100644 --- a/lib/kunit/kunit-test.c +++ b/lib/kunit/kunit-test.c @@ -538,10 +538,7 @@ static struct kunit_suite kunit_resource_test_suite = { #if IS_BUILTIN(CONFIG_KUNIT_TEST) /* This avoids a cast warning if kfree() is passed direct to kunit_add_action(). */ -static void kfree_wrapper(void *p) -{ - kfree(p); -} +KUNIT_DEFINE_ACTION_WRAPPER(kfree_wrapper, kfree, const void *); static void kunit_log_test(struct kunit *test) { diff --git a/lib/kunit/test.c b/lib/kunit/test.c index f2eb71f1a66c..0308865194bb 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -772,6 +772,8 @@ static struct notifier_block kunit_mod_nb = { }; #endif +KUNIT_DEFINE_ACTION_WRAPPER(kfree_action_wrapper, kfree, const void *) + void *kunit_kmalloc_array(struct kunit *test, size_t n, size_t size, gfp_t gfp) { void *data; @@ -781,7 +783,7 @@ void *kunit_kmalloc_array(struct kunit *test, size_t n, size_t size, gfp_t gfp) if (!data) return NULL; - if (kunit_add_action_or_reset(test, (kunit_action_t *)kfree, data) != 0) + if (kunit_add_action_or_reset(test, kfree_action_wrapper, data) != 0) return NULL; return data; @@ -793,7 +795,7 @@ void kunit_kfree(struct kunit *test, const void *ptr) if (!ptr) return; - kunit_release_action(test, (kunit_action_t *)kfree, (void *)ptr); + kunit_release_action(test, kfree_action_wrapper, (void *)ptr); } EXPORT_SYMBOL_GPL(kunit_kfree); From patchwork Fri Nov 10 20:08:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 13452743 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C220DC4332F for ; Fri, 10 Nov 2023 20:08:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E70CE10E23F; Fri, 10 Nov 2023 20:08:44 +0000 (UTC) Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by gabe.freedesktop.org (Postfix) with ESMTPS id A9F3510E23F for ; Fri, 10 Nov 2023 20:08:43 +0000 (UTC) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dae71322ed4so3022353276.1 for ; Fri, 10 Nov 2023 12:08:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699646923; x=1700251723; darn=lists.freedesktop.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=51fJBfx3imxlXxpJCLaVZXz5cvn77oR86IbzpiZXKNs=; b=MrgCfCEwUhXFw46T1rAf2koIl/emeQp0pcpysiNRq218G5PJO67SqRnSVlIUF4mr64 UgR3HagQn1ak0IEsreOntrSASGP4g0TLNOPvC9NrinQ2+ysrQz/7eK5807hKgzTpTH80 bwhVb2K+exXSpH7lMAyT3fk4DgbEw0zUj2BGDUzMXN3qOyn2+f872gl1Gujzn1Z+8+ik Alrjhl/eXvMlz+bqQkJ1O6tfkWfyC96i3q1WzJqX+XoVOf+vMkrz0kt/snk22byAd605 oMdA3UG8+fZBAKVB/Abbbz2LW5L7sLeGw2uZQjlvGd1hZsq66ZRoR70s/bS+sEN0a+fJ 4ZgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699646923; x=1700251723; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=51fJBfx3imxlXxpJCLaVZXz5cvn77oR86IbzpiZXKNs=; b=VWyhkRVP6Ijptg8pE4nz0wMrwRAYXlDrC7q3gkYqeRi2NT360N4e+RTLXOjKVpL467 Akzzjy2gUx4lEQQh7pGFscMc0C03iArdy00w8KOzHM5nvV+mtdX63Of2qO1FFbUO9H83 bs9OaQy1S6eMLrmYN3hCDmYy+ThoJYTSlB9ywgQaZ3NI7kisaULRqMTUELMXmC8/QrAz CKPKWL+WpqpXiWrhdOTWWwKgkScF++sX4CUN96a2YqA24mtUFtDoR12q2tQSoTta0f9E /vZUIt0DY3JYM4AyEq8YIwaqsrZnTlM6Y16b4wzC5k/adYOK74ImNA+T/v3I6KQ+zSxm xe7A== X-Gm-Message-State: AOJu0YwWyQv5q0e8j+Kxrh7K8dIiT25n9ZuPH6DzUNbbTMSWuJ3AvcYj CUg4g5PzLtgKfPspwd+yKkFcQCqo2qzrCg== X-Google-Smtp-Source: AGHT+IGDK07iaPg+g9N2kLo9bN2a5OkVBolpHXkG2QTgPQJFeKS5zwURLPQj7RWzYTJuEXCxK3CW75e1iydlNQ== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a05:6902:182:b0:d9a:ec95:9687 with SMTP id t2-20020a056902018200b00d9aec959687mr3348ybh.11.1699646922890; Fri, 10 Nov 2023 12:08:42 -0800 (PST) Date: Sat, 11 Nov 2023 04:08:27 +0800 In-Reply-To: <20231110200830.1832556-1-davidgow@google.com> Mime-Version: 1.0 References: <20231110200830.1832556-1-davidgow@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231110200830.1832556-2-davidgow@google.com> Subject: [PATCH 2/3] drm/tests: Use KUNIT_DEFINE_ACTION_WRAPPER() From: David Gow To: Nathan Chancellor , Kees Cook , Brendan Higgins , Rae Moar , dlatypov@google.com, Maxime Ripard , Arthur Grillo , Shuah Khan X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kselftest@vger.kernel.org, David Gow , Emma Anholt , Benjamin Berg , Thomas Zimmermann , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, =?utf-8?q?Ma?= =?utf-8?q?=C3=ADra_Canal?= , Richard Fitzgerald , linux-hardening@vger.kernel.org, Sami Tolvanen , kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In order to pass functions to kunit_add_action(), they need to be of the kunit_action_t type. While casting the function pointer can work, it will break control-flow integrity. drm_kunit_helpers already defines wrappers, but we now have a macro which does this automatically. Using this greatly reduces the boilerplate needed. Signed-off-by: David Gow Acked-by: Maxime Ripard --- This patch should be a no-op, just moving to use a standard macro to implement these wrappers rather than hand-coding them. Let me know if you'd prefer to take these in separately via the drm trees, or if you're okay with having this whole series go via kselftest/kunit. Cheers, -- David --- drivers/gpu/drm/tests/drm_kunit_helpers.c | 30 +++++++---------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c index bccb33b900f3..c251e6b34de0 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -27,27 +27,15 @@ static struct platform_driver fake_platform_driver = { }, }; -static void kunit_action_platform_driver_unregister(void *ptr) -{ - struct platform_driver *drv = ptr; - - platform_driver_unregister(drv); - -} - -static void kunit_action_platform_device_put(void *ptr) -{ - struct platform_device *pdev = ptr; - - platform_device_put(pdev); -} - -static void kunit_action_platform_device_del(void *ptr) -{ - struct platform_device *pdev = ptr; - - platform_device_del(pdev); -} +KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_platform_driver_unregister, + platform_driver_unregister, + struct platform_driver *); +KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_platform_device_put, + platform_device_put, + struct platform_device *); +KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_platform_device_del, + platform_device_del, + struct platform_device *); /** * drm_kunit_helper_alloc_device - Allocate a mock device for a KUnit test From patchwork Fri Nov 10 20:08:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 13452744 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86A48C4167D for ; Fri, 10 Nov 2023 20:08:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EC21A10E25C; Fri, 10 Nov 2023 20:08:50 +0000 (UTC) Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by gabe.freedesktop.org (Postfix) with ESMTPS id D9C4110E247 for ; Fri, 10 Nov 2023 20:08:47 +0000 (UTC) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-daa2684f67eso1952211276.0 for ; Fri, 10 Nov 2023 12:08:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699646927; x=1700251727; darn=lists.freedesktop.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IAkJ89LUqtxG0K+MSJnco+XQD27u+TKLaVoOcPh4bOc=; b=EL6Qpr9y33R3ArrggROnIHaKG/JUQatULnKQ2yvNLwocjjt3z+VTUnPS2qCJN4haSY gU3bB9pwyxl1O8VSswZkffyNGo6vA33nM0iRTik4A3MpuNU6QPxYyP1N51easiblsm2W J5nW5OMbAE67ZkjhtvPrKoS92SfuDHizVr72YOem+VGneDlokEjNF6dESG/aqIKZRCyP 0xiPP+fNvPc3JeR/ZhxvecVyLDs/ee3U6/rTlmdFVR2kaxyWzeUiBKbjC9E6solan7+n U+aItmJ+r2pSm2mk6gAv+eiuUbzWSddDBc77nI/xFEut9/uPRzApWPpiBaaI2iKwCvS4 vYaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699646927; x=1700251727; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IAkJ89LUqtxG0K+MSJnco+XQD27u+TKLaVoOcPh4bOc=; b=hAmRJZy38txXyfx/dxBMp0JMExyRaQJ4TQ+j0ESzQeiqeam125IxrKDwXahaVlvKGk p0QPdS665UF28FgPHM+QJbq2dyoeal+QlwJBXKUsvmt7ln7R5Pv4T8+wTP4DaUkONmkE rl9A9mDKHI21s2DosawksBaPXv40CB81+EXe836TA+uZhcb5qRUn+BHIdHCGr/eIfEK9 29E5KiZzto4RPw0y+AbWIsxGCKkjO4swsPV7BZJmcNqvKHWV/d5TJ086NajZwl9p8k8P NHYA7G9gXQoS3bM0Wio4DxIZkvNnhbJkeD1ASyaYQynR+BgDta2Z08x4HU9ZaqMoUAHJ tcuw== X-Gm-Message-State: AOJu0YylHgqZ7NNuIafKpCf9oDpjDM2f/zqFsXTqQNwE9aWnfEzc0dUc ThfVC1D5wopcoRAsx6ppg7GbrcMJIhIx/w== X-Google-Smtp-Source: AGHT+IG2qICxw/Ih6W1d00Yw7wl6gZh00iMH2vxhyvW4HtVTUR9T6SIeeV3AzuFmY7j3gx/bERyrecNPMvP5+g== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a05:6902:18d:b0:d89:42d7:e72d with SMTP id t13-20020a056902018d00b00d8942d7e72dmr141489ybh.3.1699646927074; Fri, 10 Nov 2023 12:08:47 -0800 (PST) Date: Sat, 11 Nov 2023 04:08:28 +0800 In-Reply-To: <20231110200830.1832556-1-davidgow@google.com> Mime-Version: 1.0 References: <20231110200830.1832556-1-davidgow@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231110200830.1832556-3-davidgow@google.com> Subject: [PATCH 3/3] drm/vc4: tests: Use KUNIT_DEFINE_ACTION_WRAPPER From: David Gow To: Nathan Chancellor , Kees Cook , Brendan Higgins , Rae Moar , dlatypov@google.com, Maxime Ripard , Arthur Grillo , Shuah Khan X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kselftest@vger.kernel.org, David Gow , Emma Anholt , Benjamin Berg , Thomas Zimmermann , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, =?utf-8?q?Ma?= =?utf-8?q?=C3=ADra_Canal?= , Richard Fitzgerald , linux-hardening@vger.kernel.org, Sami Tolvanen , kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In order to pass functions to kunit_add_action(), they need to be of the kunit_action_t type. While casting the function pointer can work, it will break control-flow integrity. vc4_mock already defines such a wrapper for drm_dev_unregister(), but it involves less boilerplate to use the new macro, so replace the manual implementation. Signed-off-by: David Gow --- This patch should be a no-op, just moving to use a standard macro to implement these wrappers rather than hand-coding them. Let me know if you'd prefer to take these in separately via the drm trees, or if you're okay with having this whole series go via kselftest/kunit. Cheers, -- David --- drivers/gpu/drm/vc4/tests/vc4_mock.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/vc4/tests/vc4_mock.c b/drivers/gpu/drm/vc4/tests/vc4_mock.c index 63ca46f4cb35..becb3dbaa548 100644 --- a/drivers/gpu/drm/vc4/tests/vc4_mock.c +++ b/drivers/gpu/drm/vc4/tests/vc4_mock.c @@ -153,12 +153,9 @@ static int __build_mock(struct kunit *test, struct drm_device *drm, return 0; } -static void kunit_action_drm_dev_unregister(void *ptr) -{ - struct drm_device *drm = ptr; - - drm_dev_unregister(drm); -} +KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_drm_dev_unregister, + drm_dev_unregister, + struct drm_device *); static struct vc4_dev *__mock_device(struct kunit *test, bool is_vc5) {