get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/1.1/patches/2228935/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2228935,
    "url": "http://patchwork.ozlabs.org/api/1.1/patches/2228935/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/linux-gpio/patch/20260427135841.96266-3-tzungbi@kernel.org/",
    "project": {
        "id": 42,
        "url": "http://patchwork.ozlabs.org/api/1.1/projects/42/?format=api",
        "name": "Linux GPIO development",
        "link_name": "linux-gpio",
        "list_id": "linux-gpio.vger.kernel.org",
        "list_email": "linux-gpio@vger.kernel.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20260427135841.96266-3-tzungbi@kernel.org>",
    "date": "2026-04-27T13:58:34",
    "name": "[v9,2/9] revocable: Add KUnit test cases",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "6e5d916f08335041742006fd33b6b218e96d3ad2",
    "submitter": {
        "id": 83557,
        "url": "http://patchwork.ozlabs.org/api/1.1/people/83557/?format=api",
        "name": "Tzung-Bi Shih",
        "email": "tzungbi@kernel.org"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/linux-gpio/patch/20260427135841.96266-3-tzungbi@kernel.org/mbox/",
    "series": [
        {
            "id": 501655,
            "url": "http://patchwork.ozlabs.org/api/1.1/series/501655/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/linux-gpio/list/?series=501655",
            "date": "2026-04-27T13:58:32",
            "name": "drivers/base: Introduce revocable",
            "version": 9,
            "mbox": "http://patchwork.ozlabs.org/series/501655/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2228935/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2228935/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "\n <linux-gpio+bounces-35575-incoming=patchwork.ozlabs.org@vger.kernel.org>",
        "X-Original-To": [
            "incoming@patchwork.ozlabs.org",
            "linux-gpio@vger.kernel.org"
        ],
        "Delivered-To": "patchwork-incoming@legolas.ozlabs.org",
        "Authentication-Results": [
            "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=WkZ44c4S;\n\tdkim-atps=neutral",
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-gpio+bounces-35575-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)",
            "smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=\"WkZ44c4S\"",
            "smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"
        ],
        "Received": [
            "from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g44zB6B2rz1yHX\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 00:03:18 +1000 (AEST)",
            "from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 3019230793DD\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 27 Apr 2026 13:59:38 +0000 (UTC)",
            "from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id A37A93D093B;\n\tMon, 27 Apr 2026 13:59:37 +0000 (UTC)",
            "from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 620C23CF696;\n\tMon, 27 Apr 2026 13:59:37 +0000 (UTC)",
            "by smtp.kernel.org (Postfix) with ESMTPSA id 7EE95C2BCB7;\n\tMon, 27 Apr 2026 13:59:33 +0000 (UTC)"
        ],
        "ARC-Seal": "i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777298377; cv=none;\n b=egN1vVjcvK+jH1jV7Zc7yaWxL+eNcyoQc+PY+MNmcmWc8b3ZjQmQufU/HxUegZnWpPDEg6IWQQKcjE20AuFliD/MROsk7uROEjed95xz8R1JdyedXxa1Lhg6MKFsQtb+5dMjg+mde6/gAJVAZrsnbtHV/lE5s8i5d++ky+D0hZk=",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777298377; c=relaxed/simple;\n\tbh=OUP8eamDpx1YV8sVjT9efSUhKDq46Hm3PUn8Yl3OXnk=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=fu+qgpK+IL6EcDrY4Wp+2qozf0lL+M7B1Dac8S4hO/M83V9ya44U5AHfksMSu8jaIrnuu7FV3c66BdLVbH2MJkn7tGRaBJSz7wYmKUdL7KUS8UOvKvp5ZRbVYz4kDANg1/SSRNTHbs+LbvvAcPKEWUtNvVoOzCM1w9tEAJGhXVQ=",
        "ARC-Authentication-Results": "i=1; smtp.subspace.kernel.org;\n dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=WkZ44c4S; arc=none smtp.client-ip=10.30.226.201",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1777298377;\n\tbh=OUP8eamDpx1YV8sVjT9efSUhKDq46Hm3PUn8Yl3OXnk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=WkZ44c4S0BgE0gSz/qInB9oWvUV9zgrBE72to2ACthPbGgNj7HwnQZk/gxq+vSuEB\n\t R01+GJP+m2geelG1NaFP/Y0JfPz4R3INZcU6J1/fBonk3ep1KEKy3f2/X5YJnBoUtH\n\t Nj34779JXrAAS8t96z3UnIC9tF8sGv6IMChtMltEEyWJlGGKqRCnSCp4dBzdHDGgtb\n\t wPf+Tc/Xt5zUIA2HBEcLdtpDsa/czWA5Es1hy/yO6Z/CpCVnKKm6G3iL8/YOp5dzCq\n\t oK67c/kBrY2WVWtboMHYek6Gb4aPJ3FtjCW3K/xDy7MySuiGNH3ltZ7QLqZPR3X/Rr\n\t YmAzl2EtWGqzA==",
        "From": "Tzung-Bi Shih <tzungbi@kernel.org>",
        "To": "Arnd Bergmann <arnd@arndb.de>,\n\tGreg Kroah-Hartman <gregkh@linuxfoundation.org>,\n\tBartosz Golaszewski <brgl@kernel.org>,\n\tLinus Walleij <linusw@kernel.org>",
        "Cc": "Benson Leung <bleung@chromium.org>,\n\ttzungbi@kernel.org,\n\tlinux-kernel@vger.kernel.org,\n\tchrome-platform@lists.linux.dev,\n\tdriver-core@lists.linux.dev,\n\tlinux-doc@vger.kernel.org,\n\tlinux-gpio@vger.kernel.org,\n\t\"Rafael J. Wysocki\" <rafael@kernel.org>,\n\tDanilo Krummrich <dakr@kernel.org>,\n\tJonathan Corbet <corbet@lwn.net>,\n\tShuah Khan <shuah@kernel.org>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tWolfram Sang <wsa+renesas@sang-engineering.com>,\n\tJason Gunthorpe <jgg@nvidia.com>,\n\tJohan Hovold <johan@kernel.org>,\n\t\"Paul E . McKenney\" <paulmck@kernel.org>,\n\tDan Williams <dan.j.williams@intel.com>",
        "Subject": "[PATCH v9 2/9] revocable: Add KUnit test cases",
        "Date": "Mon, 27 Apr 2026 21:58:34 +0800",
        "Message-ID": "<20260427135841.96266-3-tzungbi@kernel.org>",
        "X-Mailer": "git-send-email 2.51.0",
        "In-Reply-To": "<20260427135841.96266-1-tzungbi@kernel.org>",
        "References": "<20260427135841.96266-1-tzungbi@kernel.org>",
        "Precedence": "bulk",
        "X-Mailing-List": "linux-gpio@vger.kernel.org",
        "List-Id": "<linux-gpio.vger.kernel.org>",
        "List-Subscribe": "<mailto:linux-gpio+subscribe@vger.kernel.org>",
        "List-Unsubscribe": "<mailto:linux-gpio+unsubscribe@vger.kernel.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit"
    },
    "content": "Add KUnit test cases for the revocable API.\n\nThe test cases cover the following scenarios:\n\n- Basic: Verifies that a consumer can successfully access the resource.\n- Revocation: Verifies that after the provider revokes the resource,\n  the consumer correctly receives a NULL pointer on a subsequent access.\n- Try Access Macro: Same as \"Revocation\" but uses the macro level\n  helpers.\n- Concurrent Access: Verifies multiple threads can access the resource.\n\nSigned-off-by: Tzung-Bi Shih <tzungbi@kernel.org>\n---\nv9:\n- Add test cases for embedded resource provider.\n\nv8: https://lore.kernel.org/all/20260213092307.858908-3-tzungbi@kernel.org\n- Squash:\n  - c259cd7ea3c9 revocable: fix missing module license and description\n  - a243f7fb11fe revocable: Add KUnit test for provider lifetime races\n  - 988357628c2c revocable: Add KUnit test for concurrent access\n- Change accordingly due to its dependency \"revocable: Revocable resource\n  management\" changes.\n\nv7: https://lore.kernel.org/all/20260116080235.350305-3-tzungbi@kernel.org\n- \"2025\" -> \"2026\" in copyright.\n- Rename the test name \"macro\" -> \"try_access_macro\".\n\nv6: https://lore.kernel.org/all/20251106152330.11733-3-tzungbi@kernel.org\n- Rename REVOCABLE_TRY_ACCESS_WITH() -> REVOCABLE_TRY_ACCESS_SCOPED().\n- Add tests for new REVOCABLE_TRY_ACCESS_WITH().\n\nv5: https://lore.kernel.org/all/20251016054204.1523139-3-tzungbi@kernel.org\n- No changes.\n\nv4: https://lore.kernel.org/all/20250923075302.591026-3-tzungbi@kernel.org\n- REVOCABLE() -> REVOCABLE_TRY_ACCESS_WITH().\n- revocable_release() -> revocable_withdraw_access().\n\nv3: https://lore.kernel.org/all/20250912081718.3827390-3-tzungbi@kernel.org\n- No changes.\n\nv2: https://lore.kernel.org/all/20250820081645.847919-3-tzungbi@kernel.org\n- New in the series.\n\nA way to run the test:\n$ ./tools/testing/kunit/kunit.py run \\\n        --kconfig_add CONFIG_REVOCABLE_KUNIT_TEST=y \\\n        revocable_test\nOr\n$ ./tools/testing/kunit/kunit.py run \\\n        --kconfig_add CONFIG_REVOCABLE_KUNIT_TEST=y \\\n        --kconfig_add CONFIG_PROVE_LOCKING=y \\\n        --kconfig_add CONFIG_DEBUG_KERNEL=y \\\n        --kconfig_add CONFIG_DEBUG_INFO=y \\\n        --kconfig_add CONFIG_DEBUG_INFO_DWARF5=y \\\n        --kconfig_add CONFIG_KASAN=y \\\n        --kconfig_add CONFIG_DETECT_HUNG_TASK=y \\\n        --kconfig_add CONFIG_DEFAULT_HUNG_TASK_TIMEOUT=\"10\" \\\n        --arch=x86_64 \\\n        --make_options=\"C=1 W=1\" \\\n        revocable_test\n\n---\n MAINTAINERS                   |   1 +\n drivers/base/Kconfig          |   5 +\n drivers/base/Makefile         |   3 +\n drivers/base/revocable_test.c | 461 ++++++++++++++++++++++++++++++++++\n 4 files changed, 470 insertions(+)\n create mode 100644 drivers/base/revocable_test.c",
    "diff": "diff --git a/MAINTAINERS b/MAINTAINERS\nindex 6ec3a7cb5e6b..14aa035ef431 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -22831,6 +22831,7 @@ L:\tdriver-core@lists.linux.dev\n S:\tMaintained\n T:\tgit git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git\n F:\tdrivers/base/revocable.c\n+F:\tdrivers/base/revocable_test.c\n F:\tinclude/linux/revocable.h\n \n RFKILL\ndiff --git a/drivers/base/Kconfig b/drivers/base/Kconfig\nindex f7d385cbd3ba..921f7e812ba5 100644\n--- a/drivers/base/Kconfig\n+++ b/drivers/base/Kconfig\n@@ -259,3 +259,8 @@ config FW_DEVLINK_SYNC_STATE_TIMEOUT\n \t  work on.\n \n endmenu\n+\n+config REVOCABLE_KUNIT_TEST\n+\ttristate \"KUnit tests for revocable\" if !KUNIT_ALL_TESTS\n+\tdepends on KUNIT\n+\tdefault KUNIT_ALL_TESTS\ndiff --git a/drivers/base/Makefile b/drivers/base/Makefile\nindex bdf854694e39..5fd19abbc83e 100644\n--- a/drivers/base/Makefile\n+++ b/drivers/base/Makefile\n@@ -35,3 +35,6 @@ ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG\n # define_trace.h needs to know how to find our header\n CFLAGS_trace.o\t\t:= -I$(src)\n obj-$(CONFIG_TRACING)\t+= trace.o\n+\n+# KUnit test cases\n+obj-$(CONFIG_REVOCABLE_KUNIT_TEST)\t+= revocable_test.o\ndiff --git a/drivers/base/revocable_test.c b/drivers/base/revocable_test.c\nnew file mode 100644\nindex 000000000000..bdab05dfafda\n--- /dev/null\n+++ b/drivers/base/revocable_test.c\n@@ -0,0 +1,461 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * Copyright 2026 Google LLC\n+ *\n+ * KUnit tests for the revocable API.\n+ *\n+ * The test cases cover the following scenarios:\n+ *\n+ * - Basic: Verifies that a consumer can successfully access the resource.\n+ *\n+ * - Revocation: Verifies that after the provider revokes the resource,\n+ *   the consumer correctly receives a NULL pointer on a subsequent access.\n+ *\n+ * - Try Access Macro: Same as \"Revocation\" but uses the macro level\n+ *   helpers.\n+ *\n+ * - Concurrent Access: Verifies multiple threads can access the resource.\n+ */\n+\n+#include <kunit/test.h>\n+#include <linux/completion.h>\n+#include <linux/delay.h>\n+#include <linux/kthread.h>\n+#include <linux/refcount.h>\n+#include <linux/revocable.h>\n+\n+static int get_refcount(struct revocable *rev)\n+{\n+\treturn refcount_read(&rev->kref.refcount);\n+}\n+\n+static void revocable_test_basic(struct kunit *test)\n+{\n+\tstruct revocable *rev;\n+\tstruct revocable_consumer rc;\n+\tvoid *real_res = (void *)0x12345678, *res;\n+\n+\trev = revocable_alloc(real_res);\n+\tKUNIT_ASSERT_NOT_NULL(test, rev);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\tKUNIT_EXPECT_EQ(test, rev->alloc_type, REVOCABLE_DYNAMIC);\n+\n+\trevocable_init(rev, &rc);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 3);\n+\n+\tres = revocable_try_access(&rc);\n+\tKUNIT_EXPECT_PTR_EQ(test, res, real_res);\n+\trevocable_withdraw_access(&rc);\n+\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 3);\n+\trevocable_deinit(&rc);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\trevocable_revoke(rev);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 1);\n+\trevocable_put(rev);\n+}\n+\n+static void revocable_embed_test_basic(struct kunit *test)\n+{\n+\tstruct revocable rev;\n+\tstruct revocable_consumer rc;\n+\tvoid *real_res = (void *)0x12345678, *res;\n+\n+\trevocable_embed_init(&rev, real_res);\n+\tKUNIT_EXPECT_EQ(test, rev.alloc_type, REVOCABLE_EMBEDDED);\n+\n+\trevocable_init(&rev, &rc);\n+\n+\tres = revocable_try_access(&rc);\n+\tKUNIT_EXPECT_PTR_EQ(test, res, real_res);\n+\trevocable_withdraw_access(&rc);\n+\n+\trevocable_embed_destroy(&rev);\n+}\n+\n+static void revocable_test_revocation(struct kunit *test)\n+{\n+\tstruct revocable *rev;\n+\tstruct revocable_consumer rc;\n+\tvoid *real_res = (void *)0x12345678, *res;\n+\n+\trev = revocable_alloc(real_res);\n+\tKUNIT_ASSERT_NOT_NULL(test, rev);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\tKUNIT_EXPECT_EQ(test, rev->alloc_type, REVOCABLE_DYNAMIC);\n+\n+\trevocable_init(rev, &rc);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 3);\n+\n+\tres = revocable_try_access(&rc);\n+\tKUNIT_EXPECT_PTR_EQ(test, res, real_res);\n+\trevocable_withdraw_access(&rc);\n+\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 3);\n+\trevocable_revoke(rev);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\n+\tres = revocable_try_access(&rc);\n+\tKUNIT_EXPECT_PTR_EQ(test, res, NULL);\n+\trevocable_withdraw_access(&rc);\n+\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\trevocable_deinit(&rc);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 1);\n+\trevocable_put(rev);\n+}\n+\n+static void revocable_embed_test_revocation(struct kunit *test)\n+{\n+\tstruct revocable rev;\n+\tstruct revocable_consumer rc;\n+\tvoid *real_res = (void *)0x12345678, *res;\n+\n+\trevocable_embed_init(&rev, real_res);\n+\tKUNIT_EXPECT_EQ(test, rev.alloc_type, REVOCABLE_EMBEDDED);\n+\n+\trevocable_init(&rev, &rc);\n+\n+\tres = revocable_try_access(&rc);\n+\tKUNIT_EXPECT_PTR_EQ(test, res, real_res);\n+\trevocable_withdraw_access(&rc);\n+\n+\trevocable_revoke(&rev);\n+\n+\tres = revocable_try_access(&rc);\n+\tKUNIT_EXPECT_PTR_EQ(test, res, NULL);\n+\trevocable_withdraw_access(&rc);\n+\n+\trevocable_embed_destroy(&rev);\n+}\n+\n+static void revocable_test_try_access_macro1(struct kunit *test)\n+{\n+\tstruct revocable *rev;\n+\tvoid *real_res = (void *)0x12345678, *res;\n+\n+\trev = revocable_alloc(real_res);\n+\tKUNIT_ASSERT_NOT_NULL(test, rev);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\tKUNIT_EXPECT_EQ(test, rev->alloc_type, REVOCABLE_DYNAMIC);\n+\n+\t{\n+\t\trevocable_try_access_with(rev, res);\n+\t\tKUNIT_EXPECT_PTR_EQ(test, res, real_res);\n+\t\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 3);\n+\t}\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\n+\trevocable_revoke(rev);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 1);\n+\n+\t{\n+\t\trevocable_try_access_with(rev, res);\n+\t\tKUNIT_EXPECT_PTR_EQ(test, res, NULL);\n+\t\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\t}\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 1);\n+\n+\trevocable_put(rev);\n+}\n+\n+static int call_revocable_try_access_or_return_err(struct revocable *rev)\n+{\n+\tvoid *res;\n+\n+\trevocable_try_access_or_return_err(rev, res, -ENXIO);\n+\treturn 0;\n+}\n+\n+static int call_revocable_try_access_or_return(struct revocable *rev)\n+{\n+\tvoid *res;\n+\n+\trevocable_try_access_or_return(rev, res);\n+\treturn 0;\n+}\n+\n+static void call_revocable_try_access_or_return_void(struct kunit *test,\n+\t\t\t\t\t\t     struct revocable *rev)\n+{\n+\tvoid *res;\n+\n+\trevocable_try_access_or_return_void(rev, res);\n+\tKUNIT_FAIL(test, \"unreachable\");\n+}\n+\n+static void revocable_test_try_access_macro2(struct kunit *test)\n+{\n+\tstruct revocable *rev;\n+\tvoid *real_res = (void *)0x12345678, *res;\n+\tint ret;\n+\n+\trev = revocable_alloc(real_res);\n+\tKUNIT_ASSERT_NOT_NULL(test, rev);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\tKUNIT_EXPECT_EQ(test, rev->alloc_type, REVOCABLE_DYNAMIC);\n+\n+\t{\n+\t\trevocable_try_access_with(rev, res);\n+\t\tKUNIT_EXPECT_PTR_EQ(test, res, real_res);\n+\t\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 3);\n+\t}\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\n+\trevocable_revoke(rev);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 1);\n+\n+\tret = call_revocable_try_access_or_return_err(rev);\n+\tKUNIT_EXPECT_EQ(test, ret, -ENXIO);\n+\n+\tret = call_revocable_try_access_or_return(rev);\n+\tKUNIT_EXPECT_EQ(test, ret, -ENODEV);\n+\n+\tcall_revocable_try_access_or_return_void(test, rev);\n+\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 1);\n+\trevocable_put(rev);\n+}\n+\n+static void revocable_test_try_access_macro3(struct kunit *test)\n+{\n+\tstruct revocable *rev;\n+\tvoid *real_res = (void *)0x12345678, *res;\n+\tbool accessed;\n+\n+\trev = revocable_alloc(real_res);\n+\tKUNIT_ASSERT_NOT_NULL(test, rev);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\tKUNIT_EXPECT_EQ(test, rev->alloc_type, REVOCABLE_DYNAMIC);\n+\n+\taccessed = false;\n+\trevocable_try_access_with_scoped(rev, res) {\n+\t\tKUNIT_EXPECT_PTR_EQ(test, res, real_res);\n+\t\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 3);\n+\t\taccessed = true;\n+\t}\n+\tKUNIT_EXPECT_TRUE(test, accessed);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\n+\trevocable_revoke(rev);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 1);\n+\n+\taccessed = false;\n+\trevocable_try_access_with_scoped(rev, res) {\n+\t\tKUNIT_EXPECT_PTR_EQ(test, res, NULL);\n+\t\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\t\taccessed = true;\n+\t}\n+\tKUNIT_EXPECT_TRUE(test, accessed);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 1);\n+\n+\trevocable_put(rev);\n+}\n+\n+static int call_revocable_try_access_or_return_err_scoped(struct revocable *rev)\n+{\n+\tvoid *res;\n+\n+\trevocable_try_access_or_return_err_scoped(rev, res, -ENXIO) {}\n+\treturn 0;\n+}\n+\n+static int call_revocable_try_access_or_return_scoped(struct revocable *rev)\n+{\n+\tvoid *res;\n+\n+\trevocable_try_access_or_return_scoped(rev, res) {}\n+\treturn 0;\n+}\n+\n+static void call_revocable_try_access_or_return_void_scoped(struct kunit *test,\n+\t\t\t\t\t\t\t    struct revocable *rev)\n+{\n+\tvoid *res;\n+\n+\trevocable_try_access_or_return_void_scoped(rev, res) {}\n+\tKUNIT_FAIL(test, \"unreachable\");\n+}\n+\n+static void revocable_test_try_access_macro4(struct kunit *test)\n+{\n+\tstruct revocable *rev;\n+\tvoid *real_res = (void *)0x12345678, *res;\n+\tbool accessed;\n+\tint ret;\n+\n+\trev = revocable_alloc(real_res);\n+\tKUNIT_ASSERT_NOT_NULL(test, rev);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\tKUNIT_EXPECT_EQ(test, rev->alloc_type, REVOCABLE_DYNAMIC);\n+\n+\taccessed = false;\n+\trevocable_try_access_with_scoped(rev, res) {\n+\t\tKUNIT_EXPECT_PTR_EQ(test, res, real_res);\n+\t\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 3);\n+\t\taccessed = true;\n+\t}\n+\tKUNIT_EXPECT_TRUE(test, accessed);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\n+\trevocable_revoke(rev);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 1);\n+\n+\tret = call_revocable_try_access_or_return_err_scoped(rev);\n+\tKUNIT_EXPECT_EQ(test, ret, -ENXIO);\n+\n+\tret = call_revocable_try_access_or_return_scoped(rev);\n+\tKUNIT_EXPECT_EQ(test, ret, -ENODEV);\n+\n+\tcall_revocable_try_access_or_return_void_scoped(test, rev);\n+\n+\taccessed = false;\n+\trevocable_try_access_or_skip_scoped(rev, res)\n+\t\taccessed = true;\n+\tKUNIT_EXPECT_FALSE(test, accessed);\n+\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 1);\n+\trevocable_put(rev);\n+}\n+\n+struct test_concurrent_access_context {\n+\tstruct completion started, enter;\n+\tstruct task_struct *thread;\n+\n+\tunion {\n+\t\t/* Used by test provider. */\n+\t\tstruct revocable *rev;\n+\n+\t\t/* Used by test consumer. */\n+\t\tstruct {\n+\t\t\tstruct completion exit;\n+\t\t\tstruct revocable_consumer rc;\n+\t\t\tstruct kunit *test;\n+\t\t\tvoid *expected_res;\n+\t\t};\n+\t};\n+};\n+\n+static int test_concurrent_access_provider(void *data)\n+{\n+\tstruct test_concurrent_access_context *ctx = data;\n+\n+\tcomplete(&ctx->started);\n+\n+\twait_for_completion(&ctx->enter);\n+\trevocable_revoke(ctx->rev);\n+\n+\treturn 0;\n+}\n+\n+static int test_concurrent_access_consumer(void *data)\n+{\n+\tstruct test_concurrent_access_context *ctx = data;\n+\tvoid *res;\n+\n+\tcomplete(&ctx->started);\n+\n+\twait_for_completion(&ctx->enter);\n+\tres = revocable_try_access(&ctx->rc);\n+\tKUNIT_EXPECT_PTR_EQ(ctx->test, res, ctx->expected_res);\n+\n+\twait_for_completion(&ctx->exit);\n+\trevocable_withdraw_access(&ctx->rc);\n+\n+\treturn 0;\n+}\n+\n+static void revocable_test_concurrent_access(struct kunit *test)\n+{\n+\tstruct revocable *rev;\n+\tvoid *real_res = (void *)0x12345678;\n+\tstruct test_concurrent_access_context *ctx;\n+\tint i;\n+\n+\trev = revocable_alloc(real_res);\n+\tKUNIT_ASSERT_NOT_NULL(test, rev);\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2);\n+\tKUNIT_EXPECT_EQ(test, rev->alloc_type, REVOCABLE_DYNAMIC);\n+\n+\tctx = kunit_kmalloc_array(test, 3, sizeof(*ctx), GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_NULL(test, ctx);\n+\n+\tfor (i = 0; i < 3; ++i) {\n+\t\tctx[i].test = test;\n+\t\tinit_completion(&ctx[i].started);\n+\t\tinit_completion(&ctx[i].enter);\n+\n+\t\tif (i == 0) {\n+\t\t\t/* Transfer the ownership of provider reference too. */\n+\t\t\tctx[i].rev = rev;\n+\t\t\tctx[i].thread = kthread_run(\n+\t\t\t\ttest_concurrent_access_provider, ctx + i,\n+\t\t\t\t\"revocable_%d\", i);\n+\t\t} else {\n+\t\t\tinit_completion(&ctx[i].exit);\n+\t\t\trevocable_init(rev, &ctx[i].rc);\n+\t\t\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 2 + i);\n+\n+\t\t\tctx[i].thread = kthread_run(\n+\t\t\t\ttest_concurrent_access_consumer, ctx + i,\n+\t\t\t\t\"revocable_consumer_%d\", i);\n+\t\t}\n+\t\tKUNIT_ASSERT_FALSE(test, IS_ERR(ctx[i].thread));\n+\n+\t\twait_for_completion(&ctx[i].started);\n+\t}\n+\n+\tctx[1].expected_res = real_res;\n+\t/* consumer1 enters read-side critical section. */\n+\tcomplete(&ctx[1].enter);\n+\tmsleep(100);\n+\n+\t/* provider0 revokes the resource. */\n+\tcomplete(&ctx[0].enter);\n+\tmsleep(100);\n+\t/* provider0 can't exit.  It's waiting for the grace period. */\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 4);\n+\n+\tctx[2].expected_res = NULL;\n+\t/* consumer2 enters read-side critical section. */\n+\tcomplete(&ctx[2].enter);\n+\tmsleep(100);\n+\n+\t/* consumer{1,2} exit read-side critical section. */\n+\tfor (i = 1; i < 3; ++i) {\n+\t\tcomplete(&ctx[i].exit);\n+\t\tkthread_stop(ctx[i].thread);\n+\t\trevocable_deinit(&ctx[i].rc);\n+\t}\n+\n+\tkthread_stop(ctx[0].thread);\n+\t/* provider0 exits as all readers exit their critical section. */\n+\tKUNIT_EXPECT_EQ(test, get_refcount(rev), 1);\n+\n+\t/* Drop the caller reference. */\n+\trevocable_put(rev);\n+}\n+\n+static struct kunit_case revocable_test_cases[] = {\n+\tKUNIT_CASE(revocable_test_basic),\n+\tKUNIT_CASE(revocable_embed_test_basic),\n+\tKUNIT_CASE(revocable_test_revocation),\n+\tKUNIT_CASE(revocable_embed_test_revocation),\n+\tKUNIT_CASE(revocable_test_try_access_macro1),\n+\tKUNIT_CASE(revocable_test_try_access_macro2),\n+\tKUNIT_CASE(revocable_test_try_access_macro3),\n+\tKUNIT_CASE(revocable_test_try_access_macro4),\n+\tKUNIT_CASE(revocable_test_concurrent_access),\n+\t{}\n+};\n+\n+static struct kunit_suite revocable_test_suite = {\n+\t.name = \"revocable_test\",\n+\t.test_cases = revocable_test_cases,\n+};\n+\n+kunit_test_suite(revocable_test_suite);\n+\n+MODULE_LICENSE(\"GPL\");\n+MODULE_AUTHOR(\"Tzung-Bi Shih <tzungbi@kernel.org>\");\n+MODULE_DESCRIPTION(\"KUnit tests for the revocable API\");\n",
    "prefixes": [
        "v9",
        "2/9"
    ]
}