From patchwork Fri Sep 29 15:20:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Pagani X-Patchwork-Id: 13404528 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 377AFE71D54 for ; Fri, 29 Sep 2023 15:23:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233488AbjI2PWE (ORCPT ); Fri, 29 Sep 2023 11:22:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233537AbjI2PWD (ORCPT ); Fri, 29 Sep 2023 11:22:03 -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 19331193 for ; Fri, 29 Sep 2023 08:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696000880; 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=JxQGKg6vjIeJGB55T2GQRB1uB0pBhwS/ecFS1ZDrcr4w9QIGzmYqXY1dzFFWS6CEHYcuDp dk/JcSFTyo0F899xl6BV2PNqTI3pvfTbWsJJI4yg9cjgKuwZ8f/xChsOqc41/spM8pw9dc nGKOEJ/Rm8Nflg/ewO03NiDoI4AQ0hg= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-v5MivpcaOrGMmC33-X7d4Q-1; Fri, 29 Sep 2023 11:21:18 -0400 X-MC-Unique: v5MivpcaOrGMmC33-X7d4Q-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-418099ca1c2so188316941cf.0 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=xQ7P5VNhx9t+35s8XOWYFMbXyybn+vaQMvaNG1v+4YbHHUONkEBuvr3PeGVrCHsf+y Bc09JBGjJRQKjhF/kitXR3AOvIpEaVOZryjjMkKbFvgBPtMy75SHG45g5VtRBs05grgh QonYcw+pmx+Fa0WPw4hlBrMFMy7rUyO1rG933/7wYIOnn+xeQMqEF7e2h/YVYLzBuRF1 q2LarRKUQjWeLzTUQ8VuEVt53uQSMzau1DxdKLteiIrsbKJnlOZau6xl3a/wrN6xSJvm L1z+OONNAmZHvJnSdY/seCLicxYQoDvTBFWn3Jl0rXelxZwr42HuqpXa4myPPUbvFdxY cjGg== X-Gm-Message-State: AOJu0Yw0eoxmnPkTKTqzIroBd0QWIBkyfwuiPsMvjy+2BWFwRnwwXWGQ SVHO2MBTbhPnQxJTD0o76mJbEONfOsAxEC0Pw3QrHubLEdHVjbMaLlQXGoICENCmO1dRoA10eWI ZRTFgufr2WBrU40lnvgMRVYMXtbb2 X-Received: by 2002:a05:622a:118e:b0:418:11ab:1c00 with SMTP id m14-20020a05622a118e00b0041811ab1c00mr5502850qtk.49.1696000878155; 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 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org 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/fpga-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 = { \ + .driver = { \ + .name = __dev_name, \ + }, \ +} + +#endif /* _FPGA_KUNIT_HELPERS_H */ From patchwork Fri Sep 29 15:20:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Pagani X-Patchwork-Id: 13404530 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 D1414E71D53 for ; Fri, 29 Sep 2023 15:24:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233650AbjI2PWU (ORCPT ); Fri, 29 Sep 2023 11:22:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233614AbjI2PWO (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 37D3FD6 for ; Fri, 29 Sep 2023 08:21:28 -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-f198.google.com (mail-vk1-f198.google.com [209.85.221.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-przBmACXM2m_D7A7yEqldw-1; Fri, 29 Sep 2023 11:21:26 -0400 X-MC-Unique: przBmACXM2m_D7A7yEqldw-1 Received: by mail-vk1-f198.google.com with SMTP id 71dfb90a1353d-49093c3acacso8104712e0c.0 for ; Fri, 29 Sep 2023 08:21:26 -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=qi2fKTE2oWA8pwdZ+FsWFlu4uGOjvxg9UnoBwDjPxBa0+HJvKmuF8n0EtVuaoaMZ52 GZyauJq/1xsvuBFqDFfoOf0i6Mcg2TQqQ78Q0KsgSXZjA8maiQPJFcafsuLpPwSnDqfS sahxlJ2GlBsp8M6uA9ZLvaGqUq5HNXbeIy83o4kHKWB4YR6TsWSPdf4P2lTvHM3L+iwp tUCGeu1VyOmoUVOhXi+dPix1iw6/waqUC/7xY75E4GqWV4/55fgcTIaUTW2mKY8Wdai9 tPcLW9W+vPdxRVAV0ZRVAjG8Db9JDgxr86t+cS5Mfiq/TlCcfd6rtfeXdk6kCMfw1TJa 1HfA== X-Gm-Message-State: AOJu0YzFN+iii/fN2X1eNa3NAFgP4gwbmY16YuqReCPVtDY7Rlr+nLIs a0bVMQHP2/LmND/5YD5U/OQWRUHo1Zcj+K5B8p9ZMs1RNPtEmr54qvwZZIWqcF0vp0eXvBUYJS8 ZrmaiONPSYm/K14uYmFRS X-Received: by 2002:a05:6122:32cd:b0:49c:37a1:2358 with SMTP id ck13-20020a05612232cd00b0049c37a12358mr4322986vkb.14.1696000885109; 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 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 Fri Sep 29 15:20:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Pagani X-Patchwork-Id: 13404532 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 524BEE71D4F for ; Fri, 29 Sep 2023 15:24:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233618AbjI2PXK (ORCPT ); Fri, 29 Sep 2023 11:23:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233585AbjI2PW0 (ORCPT ); Fri, 29 Sep 2023 11:22:26 -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 31CD1F9 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-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-651-fCz-QdkZPA292ILbpQa6zg-1; Fri, 29 Sep 2023 11:21:33 -0400 X-MC-Unique: fCz-QdkZPA292ILbpQa6zg-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-418198baf49so153155471cf.1 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=XWgBDAjXuNI/WjZGIf2p60LIAQr/GLAKsM2JTHo9Irw6HA3yW3BHy3yFG4yqStC2S+ 0tmHPwLuDJKcg2w+9saloYvCUqWXxNkRaCBqLf9qJebvKz8RRex3bmRjOwMbDVg41RgF iqPF7W2ZrK9yP4xeKQgYe4UDKcXu2scXgrRL43nNHaUKPydSDZo7bAE/J4k+t4z/ppSl LPz+TGVXxmUX4175HxSviCfj9u6jAUzpt3FLCfcTYb0SjUgSRFjDJ6+eI9bn8Uel0qTA G4r5uCJ8PozZ7hwN/pZoUHc//4g+0YmqjT4eEqbl/cgE9U2yDrdPbKOp2B9RE0FYprrg 1mnQ== X-Gm-Message-State: AOJu0YxjAUqoHnqbN6zINdagzCy16Hbp985IbXMl+U/j9hUtkMNqZxF0 TKfqDXrLXsdiO9ch6G9Jr3gQUbUzWJoXzgEc6Fkr0IkXxc1tO5FAPw/H6/tf9mQ0BOOr15PGi7n Eg9pyB0lIHBUCPSkBIijq X-Received: by 2002:ac8:5892:0:b0:412:1899:76d0 with SMTP id t18-20020ac85892000000b00412189976d0mr5347708qta.63.1696000892713; 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 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 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: 13404531 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 414D4E71D4F for ; Fri, 29 Sep 2023 15:24:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233648AbjI2PWj (ORCPT ); Fri, 29 Sep 2023 11:22:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233613AbjI2PWf (ORCPT ); Fri, 29 Sep 2023 11:22: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 F2F781AC for ; Fri, 29 Sep 2023 08:21:45 -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-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-423-1KV1VA5iOCmfmiI7dm2kQw-1; Fri, 29 Sep 2023 11:21:44 -0400 X-MC-Unique: 1KV1VA5iOCmfmiI7dm2kQw-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-65afb74699eso193314646d6.3 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=GSGaf2wvAUC+EhLcjcVSMbsUAUdedP9SyCbOeILCC3lxt7pHikScgLC8D0RckBdls9 4p8gevXS9fQe0DGGyN/nd5oQMfy/yJQmvbrFR4Fck4dMv94iYfltWmlSKYGSF3AZzGAR oz3k7gCL5cXFjcLulQ5UKOTYDAl16Jmx14Oj0hQN9BnfoNVyJbhxJeQ+NwBW5EePAR8E Fc80IeSbQXN87u5Ik3Zs86UQahbbVwmost98/yZOcDCZYsv3/pxkZQ805dMwTWlsXhdh ZW+GET5R0wsp4MINds+NnHycFkApBqu9LRhqzNF/m+TI15RLoQhdS4A+CNg55cqM8TmG fuNg== X-Gm-Message-State: AOJu0YwGLSX+iMm6JgDoNuhOE7tYVQfws3qhNBSLU84fSy+vkYdVe8ga 18rxkpSZ2n9XL4NsoSb/BfZsEWFAWCQ33QWbOBCEX2rTxqs2Or0QQRN/z32EN0sxK77S54fwL1l koW30FiSwI3itijZkrjlI X-Received: by 2002:ac8:5e0d:0:b0:412:1e4c:e858 with SMTP id h13-20020ac85e0d000000b004121e4ce858mr5611982qtx.36.1696000903595; 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 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,