From patchwork Fri Sep 29 15:20:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Pagani X-Patchwork-Id: 146702 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp4222871vqu; Fri, 29 Sep 2023 11:16:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYThyGjGgCwKqzJYMX3XWnAbRw0flfecW4/a0WA5VLl/36hRMji/ZhtObg4KxqCxCQr/8y X-Received: by 2002:aca:d03:0:b0:3af:6584:9844 with SMTP id 3-20020aca0d03000000b003af65849844mr4547304oin.11.1696011360559; Fri, 29 Sep 2023 11:16:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696011360; cv=none; d=google.com; s=arc-20160816; b=S0laQFSlt3IeLvWUh22+cUjKJsjCJwW2OfYpJJa4i0usdEH/qYDEUTI6A81B9CZAJ+ LnQJ366OdHqbnHRJdm2O0yLSfDCwvY5VK+F79lclWcvPe9FuhNjUW0n7MiOwIYedStM0 5xzPvqab136UI2+XRhoBg8CrOfFlZ3PjIc38s+JuiIRgcEGr/pLGO1bBpBm0X0QRw8eK +NiROEhbobpiOckHHRk2/tk2WFRY0OFWX+Atwyh0QJwfgAdaKp50zAALwMwwBUhPWHGn PAbXBT2quN7mEqizHBWMvPtohoDWFXvDjRjfN4nZ40VLkKe9/YRTqtj6iIRgK8XYBKmb Un5A== 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=4eFMXkTSJCSP/LuqcR7rWb5lOePf6Wh6Ne6wvaIuhIA=; fh=SVLtJx2RN624E9ZvR+iL8AVfiRfKB4Yg6A8iu4u1uGc=; b=cJIcIMET3Z5JR5bAolDY+54zqhRGPslJqRKaay4ORO9B42FXHp6v5f9zy7aWLgL9yz aFgh2ewT7srR7XPyUGZO6gZ/eBtHYCsTmEvHX4iuv8NgtMMu2tJn5mG7QBroUBJ1UZBT bPYVDFeqlOuelDcXzMTHg7pW1vxPp4nqFykPcsgMeAOhiAByMBj/ZqcRkxSwVrIXr5jS 3YObmsnftcvBngI4jOJMsB4g+4QNPdslM9q/hDJ9m75Ur9g0rg7CaUIXtfvlMb/MRkvy r9Du+XFDuRQhXMufD2Hlfn0kl+zXC/LqmzEIMvo+EOsDG7aLFSb1N5ts++o0R9azwMl3 CEuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CCP+LNWc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id g18-20020a631112000000b00578b9064636si21395910pgl.242.2023.09.29.11.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 11:16:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CCP+LNWc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 565AC82C7B68; Fri, 29 Sep 2023 08:23:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233645AbjI2PWj (ORCPT + 20 others); Fri, 29 Sep 2023 11:22:39 -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-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 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 29 Sep 2023 08:23:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778396808433721445 X-GMAIL-MSGID: 1778396808433721445 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,