From nobody Sun Feb 8 21:35:16 2026 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05CCF26E646 for ; Tue, 18 Feb 2025 16:04:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739894661; cv=none; b=Uw/TNY1VkXZVbBDHGznqYDZ8E88wM6cQ4xc9vBfgqgJAdz5NHjbab+sYnjImx00/UsiEzPMB4qH49AHSvJAgeCRR/7QiZmCl4cc6XPe4srshUNmjSQmuJNjdw6/8shPrbafEoHU425PEnMTZna0cdD4ObEZo0ci4F+P+O17ADp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739894661; c=relaxed/simple; bh=hC2PNDnSvlx8tVpCvUE09c63PWr8yW9nO5xzmsySDoU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XBNtvcB89MEMhunPEd0pw6a1WTZCdmhQcx+rZl548JfI0muPmXkn0T9AM+w6XmY2HiOBdmwJ/EM3PwUCvlSScDQNj2yelijoI4lPte5D4/rDSPpFBChOXpB8xUmjqcoGPV7TFBumFOl0cfXULQfukK7MoSCuJOYwSUBU1tIYQr8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=AyzUTy3N; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="AyzUTy3N" Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 347423FA53 for ; Tue, 18 Feb 2025 16:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1739894650; bh=AHMqJnxK4/Dnt8c9QVgTRTY4Zs2e90yXoYYPy4GoEkA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AyzUTy3NeDK3Hom+XVhFehrU9W6fWI9zzMgKsh+l5yJDMt3ZsWoRin46YdWiyVCQm jBVewDT7Lc8Dbi7xZCx9Ogrbminszqcp0Df/zZjDMm389qSF54hi6xJx9gjA2oJYJi zj8KGWO2CVjukUp5iGLl+zaGlg86jeOe/cFAsrH/P1OlUBBe0szt06VFN6ubbUwsF4 KkiA5tZSWuh+OrHDyPn58WfwX4QeSDa106AW6mmseSh/JUkExlK2AHdrzqf0bpikvi 0nZSU181dLybguWOGUSIcpdLDo7hyPprw1HqiItCgCVJ9JolCP2X/zR3tRFD09N48Y yhXWfX9cJg/9A== Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-22101839788so77607335ad.3 for ; Tue, 18 Feb 2025 08:04:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739894648; x=1740499448; 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=AHMqJnxK4/Dnt8c9QVgTRTY4Zs2e90yXoYYPy4GoEkA=; b=l9LCXF/0nzA/B2y3zUf01dOjuoxr3gv0t1PXmQF0flhlFpsLDvhan6QxjXoPoIqCzv p5YC00txxF5c2EztJdi2R2BxS41oflKoNNfqsC2SWpyOt5OGe88uEqEUdOEZ3mk8f8do P/wYIAqrAvcs76zlromMuVC8Zz1bagC4yg4jBj5g2pi8VNoc0j7cYao5wf4RfEWbKaZN JuyekUFG0lMRHWzDRuNEgmbmMcj7akA00vHyQdTalV4tdhDa19eApj8BXl+a8pgs4eNZ t/5xQvxR8A/tDv6SBtk+0IA7CHnzatqBdzFj7zz4pCJXq9k//jxW8zmUmPZBqbnJCD1y 459w== X-Forwarded-Encrypted: i=1; AJvYcCVlufy80qvYJb81MCjoktLly8GYjVeDW3n+DUSNoV5zdSCYXkIxiA5ZcIffz1u+OqVzlN5GQRKMTax0zQo=@vger.kernel.org X-Gm-Message-State: AOJu0YxDWYtuJRK7nNqGdL8hiEhKyjxnpVer9zhhkXpeDdd/mhikus14 EdhwRNuS5DrEALjWxrcXsoQg7hxDgNWXX8UWwWuAHRK8DXoG9AkS3axU7Hviw8CXObDbkE48nyL BkUiRYBOgHe3VRRcUywFB/X70hBJUFHvSWkJhBnqno5laabjK3n6bujit7fzWRcUjoZdmQcpC0N 82tQ== X-Gm-Gg: ASbGncshV4/ktG4q2zyCvzQmKZzLiD2cACkz6jRpZQk4MzZRp4fttIEd5xl/dXgfUvD juXDeu9LLR3HRWMUbr+b3GdpVSovB0TYF6TxiIn1l2wUEhgCe6wmDUo8XX0YgNzalOVN64XDywH lw+/yH4ODGpfpiB2NJ7JkVReDi/UcuiNJXnicFMhIpxxMIrZhaCfowaLMUL1cEy2FkM4N5NmsJu pdsPVvvCtN7dQrLSi9EAaULkKIY6i9+1tWoQAirTFUsMq5/ERu6Co4Sbm8v6o+AC9HsPYbVHq4h 96c0jzZTVHTq6ZsqOjdUSnQ= X-Received: by 2002:a05:6a21:3995:b0:1ee:c390:58ad with SMTP id adf61e73a8af0-1eec3905cf2mr9166246637.34.1739894647613; Tue, 18 Feb 2025 08:04:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWmjYTvj6cKvC3gQEh96rnDqB1rMAwKafJdc7LFPp9QKU7MUBHctRmJpmMjmoPftsnIJh8sg== X-Received: by 2002:a05:6a21:3995:b0:1ee:c390:58ad with SMTP id adf61e73a8af0-1eec3905cf2mr9166188637.34.1739894647261; Tue, 18 Feb 2025 08:04:07 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:ad3a:e902:d78b:b8fa]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ae01c768020sm3662177a12.73.2025.02.18.08.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2025 08:04:06 -0800 (PST) From: Koichiro Den To: linux-gpio@vger.kernel.org Cc: brgl@bgdev.pl, geert+renesas@glider.be, linus.walleij@linaro.org, maciej.borzecki@canonical.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] gpio: introduce utilities for synchronous fake device creation Date: Wed, 19 Feb 2025 01:03:31 +0900 Message-ID: <20250218160333.605829-2-koichiro.den@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250218160333.605829-1-koichiro.den@canonical.com> References: <20250218160333.605829-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Both gpio-sim and gpio-virtuser share a mechanism to instantiate a platform device, wait for probe completion, and retrieve the probe success or error status synchronously. With gpio-aggregator planned to adopt this approach for its configfs interface, it's time to factor out the common code. Add dev-sync-probe.[ch] to house helper functions used by all such implementations. No functional change. Signed-off-by: Koichiro Den --- drivers/gpio/Kconfig | 7 +++ drivers/gpio/Makefile | 3 ++ drivers/gpio/dev-sync-probe.c | 96 +++++++++++++++++++++++++++++++++++ drivers/gpio/dev-sync-probe.h | 25 +++++++++ 4 files changed, 131 insertions(+) create mode 100644 drivers/gpio/dev-sync-probe.c create mode 100644 drivers/gpio/dev-sync-probe.h diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 56c1f30ac195..2e4c5f0a94f7 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1863,6 +1863,13 @@ config GPIO_MPSSE =20 endmenu =20 +# This symbol is selected by drivers that need synchronous fake device cre= ation +config DEV_SYNC_PROBE + tristate "Utilities for synchronous fake device creation" + help + Common helper functions for drivers that need synchronous fake + device creation. + menu "Virtual GPIO drivers" =20 config GPIO_AGGREGATOR diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index af3ba4d81b58..af130882ffee 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -19,6 +19,9 @@ obj-$(CONFIG_GPIO_GENERIC) +=3D gpio-generic.o # directly supported by gpio-generic gpio-generic-$(CONFIG_GPIO_GENERIC) +=3D gpio-mmio.o =20 +# Utilities for drivers that need synchronous fake device creation +obj-$(CONFIG_DEV_SYNC_PROBE) +=3D dev-sync-probe.o + obj-$(CONFIG_GPIO_104_DIO_48E) +=3D gpio-104-dio-48e.o obj-$(CONFIG_GPIO_104_IDI_48) +=3D gpio-104-idi-48.o obj-$(CONFIG_GPIO_104_IDIO_16) +=3D gpio-104-idio-16.o diff --git a/drivers/gpio/dev-sync-probe.c b/drivers/gpio/dev-sync-probe.c new file mode 100644 index 000000000000..82c8d7ae9fa7 --- /dev/null +++ b/drivers/gpio/dev-sync-probe.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Common code for drivers creating fake platform devices. + * + * Provides synchronous device creation: waits for probe completion and + * returns the probe success or error status to the device creator. + * + * Copyright (C) 2025 Bartosz Golaszewski + */ + +#include +#include + +#include "dev-sync-probe.h" + +static int dev_sync_probe_notifier_call(struct notifier_block *nb, + unsigned long action, + void *data) +{ + struct dev_sync_probe_data *pdata; + struct device *dev =3D data; + + pdata =3D container_of(nb, struct dev_sync_probe_data, bus_notifier); + if (!device_match_name(dev, pdata->name)) + return NOTIFY_DONE; + + switch (action) { + case BUS_NOTIFY_BOUND_DRIVER: + pdata->driver_bound =3D true; + break; + case BUS_NOTIFY_DRIVER_NOT_BOUND: + pdata->driver_bound =3D false; + break; + default: + return NOTIFY_DONE; + } + + complete(&pdata->probe_completion); + return NOTIFY_OK; +} + +void dev_sync_probe_init(struct dev_sync_probe_data *data) +{ + memset(data, 0, sizeof(*data)); + init_completion(&data->probe_completion); + data->bus_notifier.notifier_call =3D dev_sync_probe_notifier_call; +} +EXPORT_SYMBOL_GPL(dev_sync_probe_init); + +int dev_sync_probe_register(struct dev_sync_probe_data *data, + struct platform_device_info *pdevinfo) +{ + struct platform_device *pdev; + char *name; + + name =3D kasprintf(GFP_KERNEL, "%s.%u", pdevinfo->name, pdevinfo->id); + if (!name) + return -ENOMEM; + + data->driver_bound =3D false; + data->name =3D name; + reinit_completion(&data->probe_completion); + bus_register_notifier(&platform_bus_type, &data->bus_notifier); + + pdev =3D platform_device_register_full(pdevinfo); + if (IS_ERR(pdev)) { + bus_unregister_notifier(&platform_bus_type, &data->bus_notifier); + kfree(data->name); + return PTR_ERR(pdev); + } + + wait_for_completion(&data->probe_completion); + bus_unregister_notifier(&platform_bus_type, &data->bus_notifier); + + if (!data->driver_bound) { + platform_device_unregister(pdev); + kfree(data->name); + return -ENXIO; + } + + data->pdev =3D pdev; + return 0; +} +EXPORT_SYMBOL_GPL(dev_sync_probe_register); + +void dev_sync_probe_unregister(struct dev_sync_probe_data *data) +{ + platform_device_unregister(data->pdev); + kfree(data->name); + data->pdev =3D NULL; +} +EXPORT_SYMBOL_GPL(dev_sync_probe_unregister); + +MODULE_AUTHOR("Bartosz Golaszewski "); +MODULE_DESCRIPTION("Utilities for synchronous fake device creation"); +MODULE_LICENSE("GPL"); diff --git a/drivers/gpio/dev-sync-probe.h b/drivers/gpio/dev-sync-probe.h new file mode 100644 index 000000000000..4b3d52b70519 --- /dev/null +++ b/drivers/gpio/dev-sync-probe.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef DEV_SYNC_PROBE_H +#define DEV_SYNC_PROBE_H + +#include +#include +#include + +struct dev_sync_probe_data { + struct platform_device *pdev; + const char *name; + + /* Synchronize with probe */ + struct notifier_block bus_notifier; + struct completion probe_completion; + bool driver_bound; +}; + +void dev_sync_probe_init(struct dev_sync_probe_data *data); +int dev_sync_probe_register(struct dev_sync_probe_data *data, + struct platform_device_info *pdevinfo); +void dev_sync_probe_unregister(struct dev_sync_probe_data *data); + +#endif /* DEV_SYNC_PROBE_H */ --=20 2.45.2 From nobody Sun Feb 8 21:35:16 2026 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E01B1459F7 for ; Tue, 18 Feb 2025 16:04:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739894657; cv=none; b=iwow+Z0WZBVo4lhRLPO+Pi8FLk6oMvRAjNW+qh+wtAf2/JuqxJj5xP4ysOYDMwUrxrqU06Xj3C7I15t8+x/Eniat45TiVZcKGzFBylQUTIf35wFbW6Y0aIrd6L0kiYGBSAhnWXhygO+YgXq91u2hobN3+DeUZqu1L6axWHZJbfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739894657; c=relaxed/simple; bh=sdZ6VzRRB5ZPauONLm1Y6ciUkGYRdBApYYUeFYnndrY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YPKr+hZxMwmz8ucFD9zehelD42rBTHWZHOfEmElmS/WLx3EKJKAxc/yXXbR1G+w/+pCqhaD8z1dJFUBYUHqFoVD7R6djn6X56afiyhWswgQbV7EGJFWOamcFn6TkcJ5j0fGTLUrT0sto5oyzOc4UWEWaebkNoi8Mx15XL0nFkvQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=mfsA4PEy; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="mfsA4PEy" Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 0956C3F16B for ; Tue, 18 Feb 2025 16:04:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1739894652; bh=RjN5AreZarUYbQVP0Uc0k3mb1KoxJf6GB7t5AILSk3M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mfsA4PEyvTH8tEAkzjOjKopK7o4sjBQtF9IP0tUTrqAhDLzNMRD0YPCmTmlX5yiZU jeMiP+J3rt/Qw/Bn86ZySJdf2ww990rerXOUMDmsnat5ezD1OsZq3lWmuZmkU82wih bLaod7STdkv2vwSN3f9yX4fzm683ZkqfKkDTcGQxrs9W0p0Mjmjg3rT9K+OG7ivCnk 7ITLHF4smm6d3++t+GegJfM6UPALKjVY7ft6urxxzeltZRG6LqXwPQ8HewtszLNQA/ Bd6W/6falHXIXqXaRl+uHObct9FHoBS2/RA2AY7Aui54M0zBGIKIhCVG6Rg9lCbGZs KirfT5opfhu4w== Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-220d6c10a17so102611465ad.0 for ; Tue, 18 Feb 2025 08:04:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739894650; x=1740499450; 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=RjN5AreZarUYbQVP0Uc0k3mb1KoxJf6GB7t5AILSk3M=; b=B7S76euEBrsD4lzw3PQUGtvILd82aZ6ekDWiI4LGu451Vn+N2qKgkL/Qv2jq+ANuzB mx8y519MBmT4YXkOlD/JPt+4WnsByIyvr6J/scOL6PCYqeDPTPLG7AMsZ2TX49PWZBfS urLXnG29TDhSNOQr8ZWO8U/NR4R0BhOp+OTqBstyT50qdo/GWwZWUDrh59A9gFGIT45g u9J551+BJNHNmPgYiUqN1BDjBWkZkq4vvtYtwK7ktmzYMCP5jdHITntknz8N7rKW59mC T/rUdxcMdIH/0Dpc5yDcktRBFjKVEz8eCqG7zXjmEEKIa3s7uvcixz8QQv88d31zfcyQ lICA== X-Forwarded-Encrypted: i=1; AJvYcCUEcf7hY6DkbKH5ILOuXHhzb16So+RkBiuXL0O30MiTxs8U59HoBWLfAn52RAyDcXrk3b6yI+XW/twLiuc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8kKZEFnYdepb/rOttjgtiYRlTipeX5yOxfqW5XfeZdgrKZJnK feiz6HM79Bj2Tx8hPAvZD+Nk5VWctT0q97h2BPG0QbJr/KbLffE6bA8JUasAKyF8rGOqbwhkBWw BfaU+ZpMEafAeVX98KnxIPTr5/P9WT/z10ol2a4znBM7naKhjlNNJ48AJ5mClVmMY3LR8zC8joQ OWng== X-Gm-Gg: ASbGnctnNSihXpX4JCsxAkLkDoSJuDhjCv6t6nkSRSgN/1gwRPriAMm20S0eQuccd2W Ww3bvptK+TB7LLPH+bHki48O+RrI8R+EbQpMKWScmd2lx6Xboj/l/9BMhAofDpXsrT0NpWp9csp l3uPGDK9zcITPhyBTl+4wpDMJMcz/DEuUfw5xehIZz/vxk4QNk3p8FJJMlVmMbTIAyL+BD+s40e qWyMfZ3RZr2n7NbKiLsZpNb9/RUkmhdBi1kaPydjlaJmXw6bUSAqMBW/LgKmfPGM29eaaZ9YmNv cfoIyd3lVPk2K5RXbSrp/Ys= X-Received: by 2002:a05:6a21:6daa:b0:1e0:cc01:43da with SMTP id adf61e73a8af0-1eed3795347mr546832637.0.1739894650611; Tue, 18 Feb 2025 08:04:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlr8j/FIMrYjFZKCpEiD3ian13qv9GhgmhOTyegL8NA0OLFd302bU08nHMhlRVPDaC/ZBWew== X-Received: by 2002:a05:6a21:6daa:b0:1e0:cc01:43da with SMTP id adf61e73a8af0-1eed3795347mr546798637.0.1739894650131; Tue, 18 Feb 2025 08:04:10 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:ad3a:e902:d78b:b8fa]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ae01c768020sm3662177a12.73.2025.02.18.08.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2025 08:04:09 -0800 (PST) From: Koichiro Den To: linux-gpio@vger.kernel.org Cc: brgl@bgdev.pl, geert+renesas@glider.be, linus.walleij@linaro.org, maciej.borzecki@canonical.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] gpio: sim: convert to use dev-sync-probe utilities Date: Wed, 19 Feb 2025 01:03:32 +0900 Message-ID: <20250218160333.605829-3-koichiro.den@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250218160333.605829-1-koichiro.den@canonical.com> References: <20250218160333.605829-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update gpio-sim to use the new dev-sync-probe helper functions for synchronized platform device creation, reducing code duplication. No functional change. Signed-off-by: Koichiro Den --- drivers/gpio/Kconfig | 2 + drivers/gpio/gpio-sim.c | 84 ++++++----------------------------------- 2 files changed, 14 insertions(+), 72 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 2e4c5f0a94f7..ba06f052b9ea 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1866,6 +1866,7 @@ endmenu # This symbol is selected by drivers that need synchronous fake device cre= ation config DEV_SYNC_PROBE tristate "Utilities for synchronous fake device creation" + depends on GPIO_SIM help Common helper functions for drivers that need synchronous fake device creation. @@ -1916,6 +1917,7 @@ config GPIO_SIM tristate "GPIO Simulator Module" select IRQ_SIM select CONFIGFS_FS + select DEV_SYNC_PROBE help This enables the GPIO simulator - a configfs-based GPIO testing driver. diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c index a086087ada17..d1cdea450937 100644 --- a/drivers/gpio/gpio-sim.c +++ b/drivers/gpio/gpio-sim.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -37,6 +36,8 @@ #include #include =20 +#include "dev-sync-probe.h" + #define GPIO_SIM_NGPIO_MAX 1024 #define GPIO_SIM_PROP_MAX 4 /* Max 3 properties + sentinel. */ #define GPIO_SIM_NUM_ATTRS 3 /* value, pull and sentinel */ @@ -541,14 +542,9 @@ static struct platform_driver gpio_sim_driver =3D { }; =20 struct gpio_sim_device { + struct dev_sync_probe_data data; struct config_group group; =20 - /* - * If pdev is NULL, the device is 'pending' (waiting for configuration). - * Once the pointer is assigned, the device has been created and the - * item is 'live'. - */ - struct platform_device *pdev; int id; =20 /* @@ -562,46 +558,11 @@ struct gpio_sim_device { */ struct mutex lock; =20 - /* - * This is used to synchronously wait for the driver's probe to complete - * and notify the user-space about any errors. - */ - struct notifier_block bus_notifier; - struct completion probe_completion; - bool driver_bound; - struct gpiod_hog *hogs; =20 struct list_head bank_list; }; =20 -/* This is called with dev->lock already taken. */ -static int gpio_sim_bus_notifier_call(struct notifier_block *nb, - unsigned long action, void *data) -{ - struct gpio_sim_device *simdev =3D container_of(nb, - struct gpio_sim_device, - bus_notifier); - struct device *dev =3D data; - char devname[32]; - - snprintf(devname, sizeof(devname), "gpio-sim.%u", simdev->id); - - if (!device_match_name(dev, devname)) - return NOTIFY_DONE; - - if (action =3D=3D BUS_NOTIFY_BOUND_DRIVER) - simdev->driver_bound =3D true; - else if (action =3D=3D BUS_NOTIFY_DRIVER_NOT_BOUND) - simdev->driver_bound =3D false; - else - return NOTIFY_DONE; - - complete(&simdev->probe_completion); - - return NOTIFY_OK; -} - static struct gpio_sim_device *to_gpio_sim_device(struct config_item *item) { struct config_group *group =3D to_config_group(item); @@ -708,7 +669,7 @@ static bool gpio_sim_device_is_live(struct gpio_sim_dev= ice *dev) { lockdep_assert_held(&dev->lock); =20 - return !!dev->pdev; + return !!dev->data.pdev; } =20 static char *gpio_sim_strdup_trimmed(const char *str, size_t count) @@ -730,7 +691,7 @@ static ssize_t gpio_sim_device_config_dev_name_show(str= uct config_item *item, =20 guard(mutex)(&dev->lock); =20 - pdev =3D dev->pdev; + pdev =3D dev->data.pdev; if (pdev) return sprintf(page, "%s\n", dev_name(&pdev->dev)); =20 @@ -939,7 +900,6 @@ static int gpio_sim_device_activate(struct gpio_sim_dev= ice *dev) { struct platform_device_info pdevinfo; struct fwnode_handle *swnode; - struct platform_device *pdev; struct gpio_sim_bank *bank; int ret; =20 @@ -981,31 +941,13 @@ static int gpio_sim_device_activate(struct gpio_sim_d= evice *dev) pdevinfo.fwnode =3D swnode; pdevinfo.id =3D dev->id; =20 - reinit_completion(&dev->probe_completion); - dev->driver_bound =3D false; - bus_register_notifier(&platform_bus_type, &dev->bus_notifier); - - pdev =3D platform_device_register_full(&pdevinfo); - if (IS_ERR(pdev)) { - bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); - gpio_sim_remove_hogs(dev); - gpio_sim_remove_swnode_recursive(swnode); - return PTR_ERR(pdev); - } - - wait_for_completion(&dev->probe_completion); - bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); - - if (!dev->driver_bound) { - /* Probe failed, check kernel log. */ - platform_device_unregister(pdev); + ret =3D dev_sync_probe_register(&dev->data, &pdevinfo); + if (ret) { gpio_sim_remove_hogs(dev); gpio_sim_remove_swnode_recursive(swnode); - return -ENXIO; + return ret; } =20 - dev->pdev =3D pdev; - return 0; } =20 @@ -1015,11 +957,10 @@ static void gpio_sim_device_deactivate(struct gpio_s= im_device *dev) =20 lockdep_assert_held(&dev->lock); =20 - swnode =3D dev_fwnode(&dev->pdev->dev); - platform_device_unregister(dev->pdev); + swnode =3D dev_fwnode(&dev->data.pdev->dev); + dev_sync_probe_unregister(&dev->data); gpio_sim_remove_hogs(dev); gpio_sim_remove_swnode_recursive(swnode); - dev->pdev =3D NULL; } =20 static void @@ -1117,7 +1058,7 @@ static ssize_t gpio_sim_bank_config_chip_name_show(st= ruct config_item *item, guard(mutex)(&dev->lock); =20 if (gpio_sim_device_is_live(dev)) - return device_for_each_child(&dev->pdev->dev, &ctx, + return device_for_each_child(&dev->data.pdev->dev, &ctx, gpio_sim_emit_chip_name); =20 return sprintf(page, "none\n"); @@ -1558,8 +1499,7 @@ gpio_sim_config_make_device_group(struct config_group= *group, const char *name) mutex_init(&dev->lock); INIT_LIST_HEAD(&dev->bank_list); =20 - dev->bus_notifier.notifier_call =3D gpio_sim_bus_notifier_call; - init_completion(&dev->probe_completion); + dev_sync_probe_init(&dev->data); =20 return &no_free_ptr(dev)->group; } --=20 2.45.2 From nobody Sun Feb 8 21:35:16 2026 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D0C626B2D3 for ; Tue, 18 Feb 2025 16:04:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739894658; cv=none; b=eRipSkE6jdEgOuBYdYx8q5GuhMl/ZEXCvTbjuSGjE3wZKk9u8pMdI1VFLiXL26fX0SRFBpRfUuKiwPyq69g7vNhNxd9H3FPDcUKOheCQ6isDG608sWivoaCglmU19Ywi/v8MaV17NRFT6+k/VMrurjyD3qJth1XCEe8+AzNmSkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739894658; c=relaxed/simple; bh=4eJWuiu8iMylG68gF/vH9qt791ZdSmlwPSbKjxx5PNI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=avItXwS1JLi0X1hrwKnbWAmYO8djF10D3wfN23MQoLNOzWHFtFERrKooYXmPcfDaqawikfoKV+wNxoD8u0wx6KQt5RWDNmOMuhGZTGvpTzr6iG5SufKS2aUX6dFnq0pRlXQrV0BXr4tWv1IHzD9762Lqh4jQyffUYO4ovB+LBY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=HQUCZWR/; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="HQUCZWR/" Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 7E5CD3F869 for ; Tue, 18 Feb 2025 16:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1739894655; bh=hXMs8HBNi/hnowMwXyt+GhCst9ecZCs2bYJfUqZe+sI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HQUCZWR/Fl7J2/I18HW+5W3IXf/RVPNX+tYHfrOqv+YUHNF7WYjPStQ5lukOrNEq+ gNubeYim3xXcf771oQl22IcsaW3APp1RFfOMtuIV5r2C4tgUSezND/FPc3ThwqPgmT y5dKTZIOMnk1sZR8DcK9sBIN9aobdFJ9yeSjRsp1+enlAdrA6QJN00cPuuEPgG95IK XwhXYcqPNPhDqpJG/lxlwU7Z+kr3Shw4F6vcLyOJPozao/DqAptEl2qiLqeJS4XVEP U9QXIjR4CKfCN07Pgq+S7d8uBhiKn2DxIpukFVmJ0bk1BHyQvA4mjraHbOP/yYJ2XX oKEnvLH/bAy7g== Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-220c86e46ebso84219525ad.0 for ; Tue, 18 Feb 2025 08:04:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739894654; x=1740499454; 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=hXMs8HBNi/hnowMwXyt+GhCst9ecZCs2bYJfUqZe+sI=; b=hCRNbCxyGs1Pfp5TJ7kTIecssZU3/KnkNuFOMhgMRHhtlPECtd6Pk44yCUBHrdpk2j 2A406PV4csdAClPrwH2QwDOcbD1ISGqz8c0wJLn6zcIseIrPZoUEe1gXgMMhx9uHvo2H R9+1haz33Jz5lOI/5WFF9WpD0l7ye6g2yYzFl4mA0YpZArv+EgSp0q4UVEb4vQ5E7ey5 bGvxCTuYbAp711hAUQ3HPPXR85PPCkU3Mks6oZ2J4sHB5c6/IkJcTa3GvTuEB2M1fzTz uzwvL0q5loqk7OGmQwaWCiBNIs6myzKI/4afJY7Ooxq2y9ZcezcmkrNpZzo9Xf8fVwAU /zZA== X-Forwarded-Encrypted: i=1; AJvYcCUEx+sRlajyZcjpzdwJoS2wdCuJa2kuWf8pDOMuHQDyKd4MqZzNXDnjijuEnkQ4NDrBFvjtIPteDHg+BrM=@vger.kernel.org X-Gm-Message-State: AOJu0YxFQvvfBTetymqtBpLSNKc90bvQZPgYchQM7yhRfRoYPEEE6ZpC +0UMNFoDXl4dB0i2n0RDaAC15k6C1hTPaRzEWEI6Ujig5Jbb6Tqn9JfjeQNiY7UOprXo/O3Jrp3 ymGul/WD/o2FvgSIIripDzjtOOFqvJ/n6qol35YRofUxCF11wD7bCbNCFTscKItXJ+W/v6YzVpj PYoQ== X-Gm-Gg: ASbGnct0Lws2d8B4wWwHUKdHnI71FJtZohQUZvHgNyAcxPmMFbJkuLKX/ZPSC4qcew3 Yk0RDSWnN1mudEK6cfAAhPBAr6GkJe1xQ9scKkU/rUAEoHaH317bgU/UyEymj+W2TOu6CT/awkL sfR6cUhbGHCEGQtpgBFDvqFkHAAcydvgvfhrrBfoLozJoIWZ5BMPgPBjOKfuRdl/n9+f3KAopvT ia5QgTDk46f+LZEPSRTCB2UZ0j9Eq1c8fObw3mtU5+fnwbdPUsH1KnkQjdE83bRd48ycfkTLeqr sOvDnaBCxWi4pMSzGtFGVaE= X-Received: by 2002:a17:902:f612:b0:21f:9c7:2d2e with SMTP id d9443c01a7336-221040bdb68mr245123185ad.40.1739894653514; Tue, 18 Feb 2025 08:04:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IH2TbTWW3u0CYVTQ9OQPM/nQJvb6h3vq+eHaom1mbDtD51GpaWKMh3d5FIgowV2tRA1OUtNOw== X-Received: by 2002:a17:902:f612:b0:21f:9c7:2d2e with SMTP id d9443c01a7336-221040bdb68mr245122685ad.40.1739894652947; Tue, 18 Feb 2025 08:04:12 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:ad3a:e902:d78b:b8fa]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ae01c768020sm3662177a12.73.2025.02.18.08.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2025 08:04:12 -0800 (PST) From: Koichiro Den To: linux-gpio@vger.kernel.org Cc: brgl@bgdev.pl, geert+renesas@glider.be, linus.walleij@linaro.org, maciej.borzecki@canonical.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] gpio: virtuser: convert to use dev-sync-probe utilities Date: Wed, 19 Feb 2025 01:03:33 +0900 Message-ID: <20250218160333.605829-4-koichiro.den@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250218160333.605829-1-koichiro.den@canonical.com> References: <20250218160333.605829-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update gpio-virtuser to use the new dev-sync-probe helper functions for synchronized platform device creation, reducing code duplication. No functional change. Signed-off-by: Koichiro Den --- drivers/gpio/Kconfig | 3 +- drivers/gpio/gpio-virtuser.c | 73 +++++------------------------------- 2 files changed, 12 insertions(+), 64 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index ba06f052b9ea..b3049993a449 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1866,7 +1866,7 @@ endmenu # This symbol is selected by drivers that need synchronous fake device cre= ation config DEV_SYNC_PROBE tristate "Utilities for synchronous fake device creation" - depends on GPIO_SIM + depends on GPIO_SIM || GPIO_VIRTUSER help Common helper functions for drivers that need synchronous fake device creation. @@ -1946,6 +1946,7 @@ config GPIO_VIRTUSER select DEBUG_FS select CONFIGFS_FS select IRQ_WORK + select DEV_SYNC_PROBE help Say Y here to enable the configurable, configfs-based virtual GPIO consumer testing driver. diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c index e89f299f2140..a48627352337 100644 --- a/drivers/gpio/gpio-virtuser.c +++ b/drivers/gpio/gpio-virtuser.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -37,6 +36,8 @@ #include #include =20 +#include "dev-sync-probe.h" + #define GPIO_VIRTUSER_NAME_BUF_LEN 32 =20 static DEFINE_IDA(gpio_virtuser_ida); @@ -973,49 +974,17 @@ static struct platform_driver gpio_virtuser_driver = =3D { }; =20 struct gpio_virtuser_device { + struct dev_sync_probe_data data; struct config_group group; =20 - struct platform_device *pdev; int id; struct mutex lock; =20 - struct notifier_block bus_notifier; - struct completion probe_completion; - bool driver_bound; - struct gpiod_lookup_table *lookup_table; =20 struct list_head lookup_list; }; =20 -static int gpio_virtuser_bus_notifier_call(struct notifier_block *nb, - unsigned long action, void *data) -{ - struct gpio_virtuser_device *vdev; - struct device *dev =3D data; - char devname[32]; - - vdev =3D container_of(nb, struct gpio_virtuser_device, bus_notifier); - snprintf(devname, sizeof(devname), "gpio-virtuser.%d", vdev->id); - - if (!device_match_name(dev, devname)) - return NOTIFY_DONE; - - switch (action) { - case BUS_NOTIFY_BOUND_DRIVER: - vdev->driver_bound =3D true; - break; - case BUS_NOTIFY_DRIVER_NOT_BOUND: - vdev->driver_bound =3D false; - break; - default: - return NOTIFY_DONE; - } - - complete(&vdev->probe_completion); - return NOTIFY_OK; -} - static struct gpio_virtuser_device * to_gpio_virtuser_device(struct config_item *item) { @@ -1029,7 +998,7 @@ gpio_virtuser_device_is_live(struct gpio_virtuser_devi= ce *dev) { lockdep_assert_held(&dev->lock); =20 - return !!dev->pdev; + return !!dev->data.pdev; } =20 struct gpio_virtuser_lookup { @@ -1369,7 +1338,7 @@ gpio_virtuser_device_config_dev_name_show(struct conf= ig_item *item, =20 guard(mutex)(&dev->lock); =20 - pdev =3D dev->pdev; + pdev =3D dev->data.pdev; if (pdev) return sprintf(page, "%s\n", dev_name(&pdev->dev)); =20 @@ -1478,7 +1447,6 @@ gpio_virtuser_device_activate(struct gpio_virtuser_de= vice *dev) { struct platform_device_info pdevinfo; struct fwnode_handle *swnode; - struct platform_device *pdev; int ret; =20 lockdep_assert_held(&dev->lock); @@ -1499,31 +1467,12 @@ gpio_virtuser_device_activate(struct gpio_virtuser_= device *dev) if (ret) goto err_remove_swnode; =20 - reinit_completion(&dev->probe_completion); - dev->driver_bound =3D false; - bus_register_notifier(&platform_bus_type, &dev->bus_notifier); - - pdev =3D platform_device_register_full(&pdevinfo); - if (IS_ERR(pdev)) { - ret =3D PTR_ERR(pdev); - bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); + ret =3D dev_sync_probe_register(&dev->data, &pdevinfo); + if (ret) goto err_remove_lookup_table; - } - - wait_for_completion(&dev->probe_completion); - bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); - - if (!dev->driver_bound) { - ret =3D -ENXIO; - goto err_unregister_pdev; - } - - dev->pdev =3D pdev; =20 return 0; =20 -err_unregister_pdev: - platform_device_unregister(pdev); err_remove_lookup_table: gpio_virtuser_remove_lookup_table(dev); err_remove_swnode: @@ -1539,11 +1488,10 @@ gpio_virtuser_device_deactivate(struct gpio_virtuse= r_device *dev) =20 lockdep_assert_held(&dev->lock); =20 - swnode =3D dev_fwnode(&dev->pdev->dev); - platform_device_unregister(dev->pdev); + swnode =3D dev_fwnode(&dev->data.pdev->dev); + dev_sync_probe_unregister(&dev->data); gpio_virtuser_remove_lookup_table(dev); fwnode_remove_software_node(swnode); - dev->pdev =3D NULL; } =20 static void @@ -1772,8 +1720,7 @@ gpio_virtuser_config_make_device_group(struct config_= group *group, &gpio_virtuser_device_config_group_type); mutex_init(&dev->lock); INIT_LIST_HEAD(&dev->lookup_list); - dev->bus_notifier.notifier_call =3D gpio_virtuser_bus_notifier_call; - init_completion(&dev->probe_completion); + dev_sync_probe_init(&dev->data); =20 return &no_free_ptr(dev)->group; } --=20 2.45.2