From nobody Fri Feb 13 05:22:45 2026 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 6A3DAE71D4F for ; Fri, 29 Sep 2023 15:22:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233615AbjI2PWO (ORCPT ); Fri, 29 Sep 2023 11:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233556AbjI2PWK (ORCPT ); Fri, 29 Sep 2023 11:22:10 -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 97E1FDD for ; Fri, 29 Sep 2023 08:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696000879; 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=0DUH2bfyE6C8uTlVJHwvrkC7QPYIHAMcvQVh1UrVCss=; b=HeM1+WIosXRa2nsxhpl3wUxVclD9nCovhiDx/W46O/en/eeWmLhFXlOQYHDKtw47iV9oob lmPCELMMTVgkDyQ4XxFthSMUz9dXMg4H5li6IMs3psaqzOUOFT7M786fiPeViCAWKOsw76 WF3jvdnvTdWGdEzIr25cwaMb/wZE8Zc= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-571-nkowmXDEN-SdAGwCAHYSpw-1; Fri, 29 Sep 2023 11:21:18 -0400 X-MC-Unique: nkowmXDEN-SdAGwCAHYSpw-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4180b3a5119so185010141cf.1 for ; Fri, 29 Sep 2023 08:21:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696000878; x=1696605678; 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=0DUH2bfyE6C8uTlVJHwvrkC7QPYIHAMcvQVh1UrVCss=; b=srqCD+sPuz1iIFqLlCTihApYRg93y7NxH97GF9QDJEyc/drpDQVTEUY2j8xSL5k/DF tjX3h0s7JqeWHAF2uYpv07cX8Dse5cDUl+V/eiXuovax6OWilmuOzz3rR8S31MHdgNGh xVwdIOLjOCcfUiU4Xpd6zrbikpL6NdBpoIh2VpHELm91IlBrKUIbjDEJvgxU68h856ay OIn3uqwcxI+wQJ/6gTEYXnG4ewbMIaAYEVAXzD/7ipp4xvI+R5GwVI+BwdyZ/yqQQ0VP N01H3oeEJY7kJBoADzJAiQTRNNj7H55AjpSSRyxINlr4udrVS9SAFrXmGRFkVajiT6tb Ci0A== X-Gm-Message-State: AOJu0Yx9oTn0zhZyoVFglle1WGSJy1QDRo8I6OpMJqSq2Yh5YN+JSw/6 ip2RNcsfYb/P3Nref2UZE660bZHFVJHFYH4Nihti16M3b1e6wo1H/0a5SI2xuGATb7refl9lnhX mnHXAhoBWASSjw/rDn33ytjM= X-Received: by 2002:a05:622a:118e:b0:418:11ab:1c00 with SMTP id m14-20020a05622a118e00b0041811ab1c00mr5502844qtk.49.1696000878151; Fri, 29 Sep 2023 08:21:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZlhCTSd6qQ+sjvWEHY9Ok3klVHcIN817mjhPcqv1+65iA9JVgEHlreisFjo/ADJxKpJMnEg== X-Received: by 2002:a05:622a:118e:b0:418:11ab:1c00 with SMTP id m14-20020a05622a118e00b0041811ab1c00mr5502823qtk.49.1696000877846; Fri, 29 Sep 2023 08:21:17 -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 bq14-20020a05622a1c0e00b00419801b1094sm287053qtb.13.2023.09.29.08.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 08:21:17 -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 v2 1/4] fpga: add helpers for the FPGA KUnit test suites. Date: Fri, 29 Sep 2023 17:20:54 +0200 Message-ID: <20230929152057.85047-2-marpagan@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230929152057.85047-1-marpagan@redhat.com> References: <20230929152057.85047-1-marpagan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add helpers to facilitate the registration of minimal platform drivers to support 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/fp= ga-test-helpers.h new file mode 100644 index 000000000000..6a28ed30bf71 --- /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_H +#define _FPGA_KUNIT_HELPERS_H + +#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 =3D { \ + .driver =3D { \ + .name =3D __dev_name, \ + }, \ +} + +#endif /* _FPGA_KUNIT_HELPERS_H */ --=20 2.41.0 From nobody Fri Feb 13 05:22:45 2026 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 1D18EE71D53 for ; Fri, 29 Sep 2023 15:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233582AbjI2PWM (ORCPT ); Fri, 29 Sep 2023 11:22:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233552AbjI2PWK (ORCPT ); Fri, 29 Sep 2023 11:22:10 -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 0873BBF for ; Fri, 29 Sep 2023 08:21:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696000887; 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=YkO6UYGvOvLZwYAx7VHjqVQwFsXVSv6MHDfjtM4zzUYTOcYv3FsJnyLRbB02+zOPCjVMPb 9aKReMMi4K3YIENzitwUOand7FwcwjEjqyHMSrchuhxRL3wEqOXjDtYuXL2vAyFc4Q7o+e 41mN5JqCtiG544uEiF7bMAsJiVBqmTA= Received: from mail-vk1-f197.google.com (mail-vk1-f197.google.com [209.85.221.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-bU7GacFBPjuewLPxMfOhIg-1; Fri, 29 Sep 2023 11:21:25 -0400 X-MC-Unique: bU7GacFBPjuewLPxMfOhIg-1 Received: by mail-vk1-f197.google.com with SMTP id 71dfb90a1353d-49093c3acacso8104711e0c.0 for ; Fri, 29 Sep 2023 08:21:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696000885; x=1696605685; 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=CSAkSuahnSPYyamZoqCZ66t7Ue4+bNf+ZjWB22XeYDIdjI9kTMG4D/pTH+YeMDum/e Di0DCGNwlIqKq02g2IN1iglWfE573ITcWDi4h+HghzDyQuNt/HcPmYI2cAgxj30d8fSI Co4knmiimSgxrtUXmyn9c/U+epPwGM426D3klzYBxwjRiqMz3XQkoE72rGFHSr9NUZ+j qbBepmhkv7mwZTw8LtWIEwRxa3b1K8XQSNE/RLQ0eSRwDNyx1ErSx1Kau0mLvTz3bQuZ j9tsVY9kAkpab8y/Isebqmq15HaHncJkr/LSv6jRJLTmKbyWdknYlmderiWtNBMg3UTq EtoA== X-Gm-Message-State: AOJu0YzgCSyrJPJ+/4pGKclkExOQ1HWjhSFGKA6N60IIqumifgokeLPV nrJNTbXU0uSbm52sKuPQ4OaUkhanTzsqDm6iZjoN9UTC6aL2+F+FA76xuR0W64IzzTAtCGcX+7x Ro54xa/DciFQCwVeObG8BTxs= X-Received: by 2002:a05:6122:32cd:b0:49c:37a1:2358 with SMTP id ck13-20020a05612232cd00b0049c37a12358mr4322982vkb.14.1696000885103; Fri, 29 Sep 2023 08:21:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4gs4hEWcYKxSY0LaVxjaPFVuWUAi9sKJYkYSyuIRz/F7CcNcZSPh09BHPm2a9q2Pylaeasg== X-Received: by 2002:a05:6122:32cd:b0:49c:37a1:2358 with SMTP id ck13-20020a05612232cd00b0049c37a12358mr4322964vkb.14.1696000884850; Fri, 29 Sep 2023 08:21:24 -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 bq14-20020a05622a1c0e00b00419801b1094sm287053qtb.13.2023.09.29.08.21.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 08:21:24 -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 v2 2/4] fpga: add a platform driver to the FPGA Manager test suite Date: Fri, 29 Sep 2023 17:20:55 +0200 Message-ID: <20230929152057.85047-3-marpagan@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230929152057.85047-1-marpagan@redhat.com> References: <20230929152057.85047-1-marpagan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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-m= gr-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 =20 +#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 *t= est) sg_free_table(ctx->img_info->sgt); } =20 +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 =3D kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); =20 - ctx->pdev =3D platform_device_register_simple("mgr_pdev", PLATFORM_DEVID_= AUTO, NULL, 0); + ctx->pdev =3D platform_device_register_simple(TEST_PDEV_NAME, PLATFORM_DE= VID_AUTO, NULL, 0); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->pdev); =20 ctx->mgr =3D 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[] =3D { =20 static struct kunit_suite fpga_mgr_suite =3D { .name =3D "fpga_mgr", + .suite_init =3D fpga_mgr_test_suite_init, + .suite_exit =3D fpga_mgr_test_suite_exit, .init =3D fpga_mgr_test_init, .exit =3D fpga_mgr_test_exit, .test_cases =3D fpga_mgr_test_cases, --=20 2.41.0 From nobody Fri Feb 13 05:22:45 2026 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 09CCEE71D53 for ; Fri, 29 Sep 2023 15:22:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233635AbjI2PWX (ORCPT ); Fri, 29 Sep 2023 11:22:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233601AbjI2PWO (ORCPT ); Fri, 29 Sep 2023 11:22:14 -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 5BD4F1A7 for ; Fri, 29 Sep 2023 08:21:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696000894; 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=G06tgh5GOcgTz7fETM26pHVPdaWaKTJ096RYjAAu9GehTvDcosihwahGUcTHOrWouiLZs4 N3Yh51eJ2wkf35bWc8o/g35StgYcoIsh6qf+Lp2S47aL61+jkgvbjzGwpcb1LUI5QNnZaI 7Cg1vTr+h7yBWySflrEPW2hrBX/QhbA= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-664-7OVtCUmGO227bbUWFmYzgg-1; Fri, 29 Sep 2023 11:21:33 -0400 X-MC-Unique: 7OVtCUmGO227bbUWFmYzgg-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-774335cb98cso1890768685a.2 for ; Fri, 29 Sep 2023 08:21:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696000892; x=1696605692; 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=Srps9/miEO3+CN1q/KpFAnp803g2edVr46HlFLZsxKsWbUicg1Pw/OSKk//aZB5l7W lck8amLZup2y/XhmwLomdNcmlGyTp4GWcybcWnyKRnn7V9mQnu7MCRlYtUN5WWa2d2s9 6ZxlZn87Uc5Cbi6LOBmbMyvgTWtebVvTdQlEEuj+1BxDyQ447bYisK7obJgp5TKzJU4c mwkFITDqkSTC0PQAUBP9NV5Wf33XUYlSF60kZP5+yXA2wpLcUfIHEhydzRPCj3gVyvEe nP62248ygykNlaE4Qe5WYOkBLI9eMfqCiKQz49LrExlqPNHTt4cR89s7P06Juwh+1AUq EQJA== X-Gm-Message-State: AOJu0YwmgBkviSc9I2ZfGzZGh+uAGw9WoDIfcDID6/bfisl9OwgTES/X l7HWbmWqQFh9Z5YviU2I3o77eaZjoYvON6PJedjFfooVJOgO/Dx2VEGdvbE9rMwK/YYyU5vKpS5 YuvyRltOswEymSxaAqcE6g8w= X-Received: by 2002:ac8:5892:0:b0:412:1899:76d0 with SMTP id t18-20020ac85892000000b00412189976d0mr5347711qta.63.1696000892716; Fri, 29 Sep 2023 08:21:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGA4UgDS1c2uv6+SMZwT1kU2C6jc6BualUKTCmwz6tpPUY3Nmvkik5hsl9BfJAOnURocaa8g== X-Received: by 2002:ac8:5892:0:b0:412:1899:76d0 with SMTP id t18-20020ac85892000000b00412189976d0mr5347689qta.63.1696000892501; Fri, 29 Sep 2023 08:21:32 -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 bq14-20020a05622a1c0e00b00419801b1094sm287053qtb.13.2023.09.29.08.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 08:21:32 -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 v2 3/4] fpga: add a platform driver to the FPGA Bridge test suite Date: Fri, 29 Sep 2023 17:20:56 +0200 Message-ID: <20230929152057.85047-4-marpagan@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230929152057.85047-1-marpagan@redhat.com> References: <20230929152057.85047-1-marpagan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/fpg= a-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 =20 +#include "fpga-test-helpers.h" + struct bridge_stats { bool enable; }; @@ -53,7 +55,7 @@ static struct bridge_ctx *register_test_bridge(struct kun= it *test) ctx =3D kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); =20 - ctx->pdev =3D platform_device_register_simple("bridge_pdev", PLATFORM_DEV= ID_AUTO, NULL, 0); + ctx->pdev =3D platform_device_register_simple(TEST_PDEV_NAME, PLATFORM_DE= VID_AUTO, NULL, 0); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->pdev); =20 ctx->bridge =3D 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); } =20 +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 =3D register_test_bridge(test); @@ -165,6 +179,8 @@ static struct kunit_case fpga_bridge_test_cases[] =3D { =20 static struct kunit_suite fpga_bridge_suite =3D { .name =3D "fpga_bridge", + .suite_init =3D fpga_bridge_test_suite_init, + .suite_exit =3D fpga_bridge_test_suite_exit, .init =3D fpga_bridge_test_init, .exit =3D fpga_bridge_test_exit, .test_cases =3D fpga_bridge_test_cases, --=20 2.41.0 From nobody Fri Feb 13 05:22:45 2026 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 D1325E71D4F for ; Fri, 29 Sep 2023 15:22:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233683AbjI2PWk (ORCPT ); Fri, 29 Sep 2023 11:22:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233647AbjI2PWd (ORCPT ); Fri, 29 Sep 2023 11:22:33 -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 356D01AE for ; Fri, 29 Sep 2023 08:21:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696000905; 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=CCP+LNWcuUxPspuhkm3z/pccUJFLnv4ybLoHBPorBBoxATx1n4DzDrDviAOzboKWsSsDUQ r0/3a5qM43qDTxMn2HADU+SvLkoXS9zIwpK8+uoSOIEAeKtCHk3UmNEa4b8g1yV18vXrsZ JFuQbmQkFqmC9aK/E1PnmBZPQjVs1vA= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-128-IRYcF7uRMPO9KGexSBqlog-1; Fri, 29 Sep 2023 11:21:44 -0400 X-MC-Unique: IRYcF7uRMPO9KGexSBqlog-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-65b0249818dso181670056d6.1 for ; Fri, 29 Sep 2023 08:21:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696000903; x=1696605703; 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=hcevS+HV4J7G7kOXpIPJiiYhzoeJ6IUmOSQaeyp6ACPWjL6SuYnybfOkYALvzSuR+2 ypDlnhKug/CtyrlvlZ8dtjwE+ex30j4QliIMet4YGc3TZtqx2qNPPR6VoEc/5gnX6ZWJ LDpZZX6+T0YjhfibXRQkJOiHbKDL3y3X0RRERnqZX3z+Zmi3gWPs2ONiCjlGnTlrRr+Y RmodCxn/CgK+7trvNU/CgGqL1pJwyhXnacuC2GmodKtuEUQJxqnqO8RaOQAmSdMpzkvj ITrVixMnl2EIl2Ogi+xwXF/kgxt2EHnvmzQnxSAoONIb024IWhf4ADT0+wCRPJvb09Cm qTFg== X-Gm-Message-State: AOJu0YxKeTeFob1UgjnziWPakYAWDqN8ZuE2PHCkVE6W/0YxhBEIgFpX OU4yfkCglJepS7Q7UDSydoGzk/5Tft0fQkVcz4eRPk8WBH9e0U/mhWnCM5dPUjP2YVlVoQ7yn5/ 1sadwm0tRn7LKo5IPM6i1LuM= X-Received: by 2002:ac8:5e0d:0:b0:412:1e4c:e858 with SMTP id h13-20020ac85e0d000000b004121e4ce858mr5611985qtx.36.1696000903601; Fri, 29 Sep 2023 08:21:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFn58PBLwTq+THIqS9k7CeHslslS8Zkx9jdCHCLUBpRCxKtjNqsvILp9zhdNCpI8CYEa32WgQ== X-Received: by 2002:ac8:5e0d:0:b0:412:1e4c:e858 with SMTP id h13-20020ac85e0d000000b004121e4ce858mr5611964qtx.36.1696000903357; Fri, 29 Sep 2023 08:21:43 -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 bq14-20020a05622a1c0e00b00419801b1094sm287053qtb.13.2023.09.29.08.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 08:21:43 -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 v2 4/4] fpga: add a platform driver to the FPGA Region test suite Date: Fri, 29 Sep 2023 17:20:57 +0200 Message-ID: <20230929152057.85047-5-marpagan@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230929152057.85047-1-marpagan@redhat.com> References: <20230929152057.85047-1-marpagan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/fpg= a-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 =20 +#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); } =20 +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 =3D kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); =20 - ctx->mgr_pdev =3D platform_device_register_simple("mgr_pdev", PLATFORM_DE= VID_AUTO, NULL, 0); + ctx->mgr_pdev =3D platform_device_register_simple(TEST_PDEV_NAME, PLATFOR= M_DEVID_AUTO, + NULL, 0); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->mgr_pdev); =20 ctx->mgr =3D devm_fpga_mgr_register(&ctx->mgr_pdev->dev, "Fake FPGA Manag= er", &fake_mgr_ops, &ctx->mgr_stats); KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(ctx->mgr)); =20 - ctx->bridge_pdev =3D platform_device_register_simple("bridge_pdev", PLATF= ORM_DEVID_AUTO, + ctx->bridge_pdev =3D platform_device_register_simple(TEST_PDEV_NAME, PLAT= FORM_DEVID_AUTO, NULL, 0); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->bridge_pdev); =20 @@ -163,7 +178,7 @@ static int fpga_region_test_init(struct kunit *test) =20 ctx->bridge_stats.enable =3D true; =20 - ctx->region_pdev =3D platform_device_register_simple("region_pdev", PLATF= ORM_DEVID_AUTO, + ctx->region_pdev =3D platform_device_register_simple(TEST_PDEV_NAME, PLAT= FORM_DEVID_AUTO, NULL, 0); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->region_pdev); =20 @@ -195,12 +210,13 @@ static void fpga_region_test_exit(struct kunit *test) static struct kunit_case fpga_region_test_cases[] =3D { KUNIT_CASE(fpga_region_test_class_find), KUNIT_CASE(fpga_region_test_program_fpga), - {} }; =20 static struct kunit_suite fpga_region_suite =3D { - .name =3D "fpga_mgr", + .name =3D "fpga_region", + .suite_init =3D fpga_region_test_suite_init, + .suite_exit =3D fpga_region_test_suite_exit, .init =3D fpga_region_test_init, .exit =3D fpga_region_test_exit, .test_cases =3D fpga_region_test_cases, --=20 2.41.0