From patchwork Tue Sep 26 16:39:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Pagani X-Patchwork-Id: 13399371 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B074AE7E652 for ; Tue, 26 Sep 2023 16:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235345AbjIZQkP (ORCPT ); Tue, 26 Sep 2023 12:40:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235275AbjIZQkM (ORCPT ); Tue, 26 Sep 2023 12:40:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78D85136 for ; Tue, 26 Sep 2023 09:39:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695746364; 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=av4Q5tr0bnozwSJldJa/tKMZzYdZGmoPuhbGkeCDqlg=; b=WJfGaTgtzJKWMm0mGKlLq5KOsU41kWvfDHxakXauvgQKcw3xYpueIcVv1n7AFTjGjk79sB 0JVcOhgSsO3R5yUgkiMmDcrN90b9CIwzeDtK0Vk5byRuuWfYrre6STi+cu5sDPU3qzMtN4 cLNWOwousvZtZ/5ni4QhAZOQMvYJRsU= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-223-B8JoD4OVOAyZIryDpv1TDg-1; Tue, 26 Sep 2023 12:39:23 -0400 X-MC-Unique: B8JoD4OVOAyZIryDpv1TDg-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-31fd48da316so7252452f8f.3 for ; Tue, 26 Sep 2023 09:39:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695746362; x=1696351162; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=av4Q5tr0bnozwSJldJa/tKMZzYdZGmoPuhbGkeCDqlg=; b=pxnJKOqGYoVGK+ODFRBM2d/FB0rnV5HQcoyDo7+C5+iqrukj6fN6G/2ejXRDIMGFwl Fe6DHvi5INP3SUYZE0703q2JoGpCbE5h+EKkOv0j9hJroE2p4j6PoFqXkW91Whm+62/0 gf4jZcmhiRRs5LFAN3rC5yjbyARfhKv2IPKCgQnf6jW+Kb/S12lJotkdP1iX6AzaOppF W9ct0YQbXali6QluiLQsJG1UJDrfBTfHk1Z6otFcIiopyV4GpnIFUEckwt5T0cKvefIJ 7Qnami1wYg45vPZmof9fkNqbwvTIqoi3E2OsdlnWTe7OtXxauw8EfbpctZtG4Y7Lt4MR 87PQ== X-Gm-Message-State: AOJu0YyZ70riC09awNJQp62L9IXTGrUcu3MOf7/3JH7F96uvBNw0jZYk UdALRgWZPthA3xlW7/F46paMgXhwRI8CCgECM/AHAjgjQNE7H5SVLeKdWjFpJDvCF5OlNNH4+OI UmQLPYWnE7N9HoTl87coCWPTJeI2h X-Received: by 2002:adf:f891:0:b0:320:66:cf67 with SMTP id u17-20020adff891000000b003200066cf67mr8551639wrp.18.1695746362269; Tue, 26 Sep 2023 09:39:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH4ila2SCVWp13EofwUd5ovY7r6En2sCXu1+29pWKRQjRuQNyl9s1EJv237ExyfKfZoffbgNA== X-Received: by 2002:adf:f891:0:b0:320:66:cf67 with SMTP id u17-20020adff891000000b003200066cf67mr8551628wrp.18.1695746362039; Tue, 26 Sep 2023 09:39:22 -0700 (PDT) Received: from klayman.redhat.com (net-2-34-30-58.cust.vodafonedsl.it. [2.34.30.58]) by smtp.gmail.com with ESMTPSA id w10-20020adfde8a000000b0031fba0a746bsm15171803wrl.9.2023.09.26.09.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 09:39:21 -0700 (PDT) From: Marco Pagani To: Moritz Fischer , Wu Hao , Xu Yilun , Tom Rix Cc: Marco Pagani , linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH 1/4] fpga: add helpers for the FPGA KUnit test suites. Date: Tue, 26 Sep 2023 18:39:08 +0200 Message-ID: <20230926163911.66114-2-marpagan@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230926163911.66114-1-marpagan@redhat.com> References: <20230926163911.66114-1-marpagan@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org Add helpers to facilitate the registration of minimal platform drivers to support the parent platform devices used for testing. Signed-off-by: Marco Pagani --- drivers/fpga/tests/fpga-test-helpers.h | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 drivers/fpga/tests/fpga-test-helpers.h diff --git a/drivers/fpga/tests/fpga-test-helpers.h b/drivers/fpga/tests/fpga-test-helpers.h new file mode 100644 index 000000000000..fcad3249be68 --- /dev/null +++ b/drivers/fpga/tests/fpga-test-helpers.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * KUnit test for the FPGA Manager + * + * Copyright (C) 2023 Red Hat, Inc. + * + * Author: Marco Pagani + */ + +#ifndef FPGA_KUNIT_HELPERS_ +#define FPGA_KUNIT_HELPERS_ + +#define TEST_PDEV_NAME "fpga-test-pdev" + +#define TEST_PLATFORM_DRIVER(__drv_name) \ + __TEST_PLATFORM_DRIVER(__drv_name, TEST_PDEV_NAME) +/* + * Helper macro for defining a minimal platform driver that can + * be registered to support the parent platform devices used for + * testing. + */ +#define __TEST_PLATFORM_DRIVER(__drv_name, __dev_name) \ +static struct platform_driver __drv_name = { \ + .driver = { \ + .name = __dev_name, \ + }, \ +} + +#endif /* FPGA_KUNIT_HELPERS_ */ From patchwork Tue Sep 26 16:39:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Pagani X-Patchwork-Id: 13399373 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E313EE7E653 for ; Tue, 26 Sep 2023 16:42:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235321AbjIZQkW (ORCPT ); Tue, 26 Sep 2023 12:40:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235316AbjIZQkU (ORCPT ); Tue, 26 Sep 2023 12:40:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2AC6FC for ; Tue, 26 Sep 2023 09:39:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695746371; 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=6vekRvbFuhbc4qXIoy5r5sKVR277TKztySBeIjCszjQ=; b=i+qy6EO/DNqHHEPbjcoN+v0n6W2YgKM2ZAenGx0VbT52qDnWG+RRQD2b+ifaGzR/WX18oO fH+RGHMklzL16+vXkiF3PubNWfQYW0MHD/nwa3SR+kmEcR1Lgn0hAQ1AX24gCuvFmrOj96 sIdkKes9JMkz5kPjrY/swCVFXNT930k= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-550-Vu0dcFLYN8OEUkzfMgfdFw-1; Tue, 26 Sep 2023 12:39:29 -0400 X-MC-Unique: Vu0dcFLYN8OEUkzfMgfdFw-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-32320b9d671so4165718f8f.3 for ; Tue, 26 Sep 2023 09:39:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695746369; x=1696351169; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6vekRvbFuhbc4qXIoy5r5sKVR277TKztySBeIjCszjQ=; b=l+L7Wh4CGNACNBjOB+LRf8nECNgczFtBJqFRnjRydAFMc2xIDQnOJrVmTvJ+XFXbSB CONuihg/Zf46RXKwoLlxotIM9W3QQqV2p7jvkKeT/yXxOilQxsMDA//ZSMgJ6252252K Kd/rpnuuMrJOxpx/uCUHx1zuuvd8W1USKRpD4JAdKG6hcP5zmk0ztcnKsW5RytsisQt3 WcjlQRSdSHAcZ1ERitaJpfoF5vyKnUP+uRJou1U3GfGO4oo+QPHDh1zDz4EurojudI6p RjZcBPl0MBH7g8lsisucteX92zPm2EOgcNktMwGTDiKgWDjIrvXMNMhQfsQVT5F4wShU EYOA== X-Gm-Message-State: AOJu0YwWy86Y/UhJ6Hp7XS49iHTEkxc7klfoNegpGKqsXRQ/tf5PTUJA DF1TYDobxPUrGs4pLQ38fWvM6WwxO2bKZdVC8arkEFkA/Or6MsZgg/lzdb4fIcCi5E04tcFRK8W +EGTQahKnLjsxegLeNfQ1 X-Received: by 2002:a05:6000:1c7:b0:31f:bdfd:5d30 with SMTP id t7-20020a05600001c700b0031fbdfd5d30mr10927467wrx.57.1695746368815; Tue, 26 Sep 2023 09:39:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEX8EcPEYL9XNbW5emDb2L3Wp36IHDUsyIYnSB9fUqrAGottXlbDsMYpWyM4tCp7IPkDH1AaQ== X-Received: by 2002:a05:6000:1c7:b0:31f:bdfd:5d30 with SMTP id t7-20020a05600001c700b0031fbdfd5d30mr10927453wrx.57.1695746368621; Tue, 26 Sep 2023 09:39:28 -0700 (PDT) Received: from klayman.redhat.com (net-2-34-30-58.cust.vodafonedsl.it. [2.34.30.58]) by smtp.gmail.com with ESMTPSA id w10-20020adfde8a000000b0031fba0a746bsm15171803wrl.9.2023.09.26.09.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 09:39:28 -0700 (PDT) From: Marco Pagani To: Moritz Fischer , Wu Hao , Xu Yilun , Tom Rix Cc: Marco Pagani , linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org, Jinjie Ruan Subject: [PATCH 2/4] fpga: add a platform driver to the FPGA Manager test suite Date: Tue, 26 Sep 2023 18:39:09 +0200 Message-ID: <20230926163911.66114-3-marpagan@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230926163911.66114-1-marpagan@redhat.com> References: <20230926163911.66114-1-marpagan@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org Register a minimal platform driver associated with the parent platform device used for testing to prevent a null-ptr-deref when try_module_get() is called by fpga_mgr_get(). Fixes: ccbc1c302115 ("fpga: add an initial KUnit suite for the FPGA Manager") Reported-by: Jinjie Ruan Signed-off-by: Marco Pagani --- drivers/fpga/tests/fpga-mgr-test.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/fpga/tests/fpga-mgr-test.c b/drivers/fpga/tests/fpga-mgr-test.c index 6acec55b60ce..30de474d7def 100644 --- a/drivers/fpga/tests/fpga-mgr-test.c +++ b/drivers/fpga/tests/fpga-mgr-test.c @@ -14,6 +14,8 @@ #include #include +#include "fpga-test-helpers.h" + #define HEADER_FILL 'H' #define IMAGE_FILL 'P' #define IMAGE_BLOCK 1024 @@ -277,6 +279,18 @@ static void fpga_mgr_test_img_load_sgt(struct kunit *test) sg_free_table(ctx->img_info->sgt); } +TEST_PLATFORM_DRIVER(test_platform_driver); + +static int fpga_mgr_test_suite_init(struct kunit_suite *suite) +{ + return platform_driver_register(&test_platform_driver); +} + +static void fpga_mgr_test_suite_exit(struct kunit_suite *suite) +{ + platform_driver_unregister(&test_platform_driver); +} + static int fpga_mgr_test_init(struct kunit *test) { struct mgr_ctx *ctx; @@ -284,7 +298,7 @@ static int fpga_mgr_test_init(struct kunit *test) ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); - ctx->pdev = platform_device_register_simple("mgr_pdev", PLATFORM_DEVID_AUTO, NULL, 0); + ctx->pdev = platform_device_register_simple(TEST_PDEV_NAME, PLATFORM_DEVID_AUTO, NULL, 0); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->pdev); ctx->mgr = devm_fpga_mgr_register(&ctx->pdev->dev, "Fake FPGA Manager", &fake_mgr_ops, @@ -317,6 +331,8 @@ static struct kunit_case fpga_mgr_test_cases[] = { static struct kunit_suite fpga_mgr_suite = { .name = "fpga_mgr", + .suite_init = fpga_mgr_test_suite_init, + .suite_exit = fpga_mgr_test_suite_exit, .init = fpga_mgr_test_init, .exit = fpga_mgr_test_exit, .test_cases = fpga_mgr_test_cases, From patchwork Tue Sep 26 16:39:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Pagani X-Patchwork-Id: 13399372 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D27F8E7E652 for ; Tue, 26 Sep 2023 16:42:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235317AbjIZQk1 (ORCPT ); Tue, 26 Sep 2023 12:40:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235334AbjIZQkY (ORCPT ); Tue, 26 Sep 2023 12:40:24 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15E15B3 for ; Tue, 26 Sep 2023 09:39:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695746377; 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=bU5dbp4PmbcRGMxxeBcidbIs/vd32ofMq8iILiK+4+o=; b=ARFByj3pfgy0AiNK5oJAen2kPF2j/FX1q5YlaHDVS+HZraaCEijScvwrp1ld/IwWLdXvSm Psk9dQdO7pV2hM+mumRPDKdcB5LGU7gmVgpwYkFZYSgmlO4cbqtvrd7tUAbUBmxjay0foG PvlkJhPod502MdIbEwRQgKiknvezpvk= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-575-FmhFGzzyMS-ousMh3SyeWQ-1; Tue, 26 Sep 2023 12:39:36 -0400 X-MC-Unique: FmhFGzzyMS-ousMh3SyeWQ-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-40526a782f7so84907435e9.2 for ; Tue, 26 Sep 2023 09:39:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695746375; x=1696351175; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bU5dbp4PmbcRGMxxeBcidbIs/vd32ofMq8iILiK+4+o=; b=nP2uQX6LHWE+eRbvC+DSEznL3tZEu19VLvLc0SVZIuo2gFZP6/ml9JWu+noa7UcNCf Ra4/iEeLuA3RpwKWb0GPBEqKpSqzUjK9isYs+b0OTxO/bKQoyKutDOov9wNE8F9P9tya inPpz2V8eGgSkMDjxjLUt6XSh/4eE/Hw/tV22/1XgNldVlfU9lxWeSw50C+IpFYiPqZT 3icAAoQT3wfi3s39yqAQaXiUdjSnK/AZf+TEfrIJ3EhRyqCsFKc6qRkEmWc9q0y8aF00 r+Ej6WrAywwyJR+4T+vyV0QX2GhDBqwIuj5bApA2IBlYUB9BcOicY4KgQP3YXVna5uja 0BMg== X-Gm-Message-State: AOJu0Yyfk9+xnWbwMKkSFFij5vEy1cKbTbpxdEDhKkXxDTlUU4zDsQbD sPRnIpBwP/xTOEqA3aP5qAcAXr6TCdaXnoguqijEjqxlJU+WLwf4JEyzsFSZxY28cwxEzWL4Kwq e/ANbgLixQNNy1CGMHd2Z X-Received: by 2002:a5d:4a12:0:b0:319:5a7c:6418 with SMTP id m18-20020a5d4a12000000b003195a7c6418mr10305777wrq.43.1695746375043; Tue, 26 Sep 2023 09:39:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2Qn5SYxz3S2izx2vdfof5gEmi912zq7TwxOe/Jk4swl4vtQThviKly5b00inzBZj4Y0gVmw== X-Received: by 2002:a5d:4a12:0:b0:319:5a7c:6418 with SMTP id m18-20020a5d4a12000000b003195a7c6418mr10305767wrq.43.1695746374845; Tue, 26 Sep 2023 09:39:34 -0700 (PDT) Received: from klayman.redhat.com (net-2-34-30-58.cust.vodafonedsl.it. [2.34.30.58]) by smtp.gmail.com with ESMTPSA id w10-20020adfde8a000000b0031fba0a746bsm15171803wrl.9.2023.09.26.09.39.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 09:39:34 -0700 (PDT) From: Marco Pagani To: Moritz Fischer , Wu Hao , Xu Yilun , Tom Rix Cc: Marco Pagani , linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org, Jinjie Ruan Subject: [PATCH 3/4] fpga: add a platform driver to the FPGA Bridge test suite Date: Tue, 26 Sep 2023 18:39:10 +0200 Message-ID: <20230926163911.66114-4-marpagan@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230926163911.66114-1-marpagan@redhat.com> References: <20230926163911.66114-1-marpagan@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org Register a minimal platform driver associated with the parent platform device used for testing to prevent a null-ptr-deref when try_module_get() is called by __fpga_bridge_get(). Fixes: 9e6823481e5f ("fpga: add an initial KUnit suite for the FPGA Bridge") Reported-by: Jinjie Ruan Signed-off-by: Marco Pagani --- drivers/fpga/tests/fpga-bridge-test.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/fpga/tests/fpga-bridge-test.c b/drivers/fpga/tests/fpga-bridge-test.c index 1d258002cdd7..4bd4ecaa7e90 100644 --- a/drivers/fpga/tests/fpga-bridge-test.c +++ b/drivers/fpga/tests/fpga-bridge-test.c @@ -13,6 +13,8 @@ #include #include +#include "fpga-test-helpers.h" + struct bridge_stats { bool enable; }; @@ -53,7 +55,7 @@ static struct bridge_ctx *register_test_bridge(struct kunit *test) ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); - ctx->pdev = platform_device_register_simple("bridge_pdev", PLATFORM_DEVID_AUTO, NULL, 0); + ctx->pdev = platform_device_register_simple(TEST_PDEV_NAME, PLATFORM_DEVID_AUTO, NULL, 0); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->pdev); ctx->bridge = fpga_bridge_register(&ctx->pdev->dev, "Fake FPGA bridge", &fake_bridge_ops, @@ -144,6 +146,18 @@ static void fpga_bridge_test_get_put_list(struct kunit *test) unregister_test_bridge(ctx_1); } +TEST_PLATFORM_DRIVER(test_platform_driver); + +static int fpga_bridge_test_suite_init(struct kunit_suite *suite) +{ + return platform_driver_register(&test_platform_driver); +} + +static void fpga_bridge_test_suite_exit(struct kunit_suite *suite) +{ + platform_driver_unregister(&test_platform_driver); +} + static int fpga_bridge_test_init(struct kunit *test) { test->priv = register_test_bridge(test); @@ -165,6 +179,8 @@ static struct kunit_case fpga_bridge_test_cases[] = { static struct kunit_suite fpga_bridge_suite = { .name = "fpga_bridge", + .suite_init = fpga_bridge_test_suite_init, + .suite_exit = fpga_bridge_test_suite_exit, .init = fpga_bridge_test_init, .exit = fpga_bridge_test_exit, .test_cases = fpga_bridge_test_cases, From patchwork Tue Sep 26 16:39:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Pagani X-Patchwork-Id: 13399374 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2D12E7E653 for ; Tue, 26 Sep 2023 16:42:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233309AbjIZQkh (ORCPT ); Tue, 26 Sep 2023 12:40:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235338AbjIZQkf (ORCPT ); Tue, 26 Sep 2023 12:40:35 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6654B127 for ; Tue, 26 Sep 2023 09:39:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695746383; 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=4eFMXkTSJCSP/LuqcR7rWb5lOePf6Wh6Ne6wvaIuhIA=; b=cQBp40S4V3qD5Fa6Lb7UhNtKlOEvxVCQ6jcjQbizHG2JxGqcI45oV2Ohm8PQyEy23RHTXx A6gZMLJ05UkYLmRjtkfReaG7YH/MWxwB7rZGrWZ5U7JmCPY8l3pBFSv8PKzFCpFhIoJwtz jqn+9SCzepa4M5qwCLWylY/E1owZpVA= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-iKJgtnXJPemHSlAP-q2GhQ-1; Tue, 26 Sep 2023 12:39:41 -0400 X-MC-Unique: iKJgtnXJPemHSlAP-q2GhQ-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-32006e08483so7258176f8f.0 for ; Tue, 26 Sep 2023 09:39:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695746381; x=1696351181; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4eFMXkTSJCSP/LuqcR7rWb5lOePf6Wh6Ne6wvaIuhIA=; b=YDcbaWGEva4cq27V5sHSSczCxKbUDkLADAqnckunIULTc+fu8iPFZXWD3M/mPQwVW5 wLCKw1lL9J8K0j66K5aTJnyGjXo8NKtzdUyYZQsAqPFw0dq9JpwyTz2TYJH9rv/h3kma PnbubqXkP7hBbUovfFSyVA1GjBOKo2dTC4ZMSqm7vtACk8TvEorZLYyMC0nNsIkqZjEG Ye+gAEnKgiHZnMe1RnDIsOBVh46siorhWTJ7s+tRCgIA+GwryTrBma1C3H86QgTpaGoJ VyMFpkYQ0jaxPEFFunJBzQr4VD3kAow+Nr9lYAKVwj9byLoeYmR50k22ToYBMquxKpAb Y1Jg== X-Gm-Message-State: AOJu0Yxpdz5GspYVpoQs8QoKvsoFjvXUL3W3AT/qCqCra/5BKd9TKqxp DrwwT1szGv4l6aIDH5PjRlOuLDXFKae/25ahr+kY6VRVgUE61dJjxH4xBYZanL48vOouRqfuK5j Y3je2d98ZjT9//qadZXse X-Received: by 2002:a5d:56c9:0:b0:31f:fe07:fdde with SMTP id m9-20020a5d56c9000000b0031ffe07fddemr9729683wrw.12.1695746380842; Tue, 26 Sep 2023 09:39:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUzG68zTc6qAMQk8wPrXZnR6Yg9EbQypSNQDKJk51ynUeeBSq0ziuucyRh1aV70ovihFHzwA== X-Received: by 2002:a5d:56c9:0:b0:31f:fe07:fdde with SMTP id m9-20020a5d56c9000000b0031ffe07fddemr9729663wrw.12.1695746380594; Tue, 26 Sep 2023 09:39:40 -0700 (PDT) Received: from klayman.redhat.com (net-2-34-30-58.cust.vodafonedsl.it. [2.34.30.58]) by smtp.gmail.com with ESMTPSA id w10-20020adfde8a000000b0031fba0a746bsm15171803wrl.9.2023.09.26.09.39.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 09:39:40 -0700 (PDT) From: Marco Pagani To: Moritz Fischer , Wu Hao , Xu Yilun , Tom Rix Cc: Marco Pagani , linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org, Jinjie Ruan Subject: [PATCH 4/4] fpga: add a platform driver to the FPGA Region test suite Date: Tue, 26 Sep 2023 18:39:11 +0200 Message-ID: <20230926163911.66114-5-marpagan@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230926163911.66114-1-marpagan@redhat.com> References: <20230926163911.66114-1-marpagan@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org Register a minimal platform driver associated with the parent platform device used for testing to prevent a null-ptr-deref when try_module_get() is called by fpga_region_get(). Also, fix a typo in the suite's name. Fixes: 64a5f972c93d ("fpga: add an initial KUnit suite for the FPGA Region") Reported-by: Jinjie Ruan Signed-off-by: Marco Pagani --- drivers/fpga/tests/fpga-region-test.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/fpga/tests/fpga-region-test.c b/drivers/fpga/tests/fpga-region-test.c index 9f9d50ee7871..5ff688b394f9 100644 --- a/drivers/fpga/tests/fpga-region-test.c +++ b/drivers/fpga/tests/fpga-region-test.c @@ -15,6 +15,8 @@ #include #include +#include "fpga-test-helpers.h" + struct mgr_stats { u32 write_count; }; @@ -132,6 +134,18 @@ static void fpga_region_test_program_fpga(struct kunit *test) fpga_image_info_free(img_info); } +TEST_PLATFORM_DRIVER(test_platform_driver); + +static int fpga_region_test_suite_init(struct kunit_suite *suite) +{ + return platform_driver_register(&test_platform_driver); +} + +static void fpga_region_test_suite_exit(struct kunit_suite *suite) +{ + platform_driver_unregister(&test_platform_driver); +} + /* * The configuration used in this test suite uses a single bridge to * limit the code under test to a single unit. The functions used by the @@ -146,14 +160,15 @@ static int fpga_region_test_init(struct kunit *test) ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); - ctx->mgr_pdev = platform_device_register_simple("mgr_pdev", PLATFORM_DEVID_AUTO, NULL, 0); + ctx->mgr_pdev = platform_device_register_simple(TEST_PDEV_NAME, PLATFORM_DEVID_AUTO, + NULL, 0); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->mgr_pdev); ctx->mgr = devm_fpga_mgr_register(&ctx->mgr_pdev->dev, "Fake FPGA Manager", &fake_mgr_ops, &ctx->mgr_stats); KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(ctx->mgr)); - ctx->bridge_pdev = platform_device_register_simple("bridge_pdev", PLATFORM_DEVID_AUTO, + ctx->bridge_pdev = platform_device_register_simple(TEST_PDEV_NAME, PLATFORM_DEVID_AUTO, NULL, 0); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->bridge_pdev); @@ -163,7 +178,7 @@ static int fpga_region_test_init(struct kunit *test) ctx->bridge_stats.enable = true; - ctx->region_pdev = platform_device_register_simple("region_pdev", PLATFORM_DEVID_AUTO, + ctx->region_pdev = platform_device_register_simple(TEST_PDEV_NAME, PLATFORM_DEVID_AUTO, NULL, 0); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->region_pdev); @@ -195,12 +210,13 @@ static void fpga_region_test_exit(struct kunit *test) static struct kunit_case fpga_region_test_cases[] = { KUNIT_CASE(fpga_region_test_class_find), KUNIT_CASE(fpga_region_test_program_fpga), - {} }; static struct kunit_suite fpga_region_suite = { - .name = "fpga_mgr", + .name = "fpga_region", + .suite_init = fpga_region_test_suite_init, + .suite_exit = fpga_region_test_suite_exit, .init = fpga_region_test_init, .exit = fpga_region_test_exit, .test_cases = fpga_region_test_cases,