From nobody Mon Feb 9 03:19:20 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 8231F18E025 for ; Fri, 21 Feb 2025 13:35:15 +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=1740144918; cv=none; b=crHaSo2i5RG8abMQ/uqiyDuhuicvephWgJwV+joh5CnZVok9CmCMdu6wHF+Zt0n2U1F7tAK9A9l4o26bzXxlI2NDal0KQFWaCJRQBi/KQizjTmggH38ya3AMyBYjZPm7FO8jAjV34eqmCswx+RdcXtS2iNOj01BzBXc63bs9jdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740144918; c=relaxed/simple; bh=69CvHWZCFYdgSTEbn1gjw1hCDAGPbz7reY7F+bDUKeg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V+mwuI+v/ME0xLwv76LUlWD9hOEiCNtFbPwWxJxOnqJqmdwOJ6iFqZBPzPK6j+SEEkNOWL/RaqVA7smLVfDQVMBQpnpzvxXvBKjEzrAq7QhRvYf+CMZMWxQ1jkpqaOlixqIEtKl6NalVmyjd2EdUgCnlqc03QSA5fgsC/h5K9nM= 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=Qghw0Sxn; 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="Qghw0Sxn" Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (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 CA29F41233 for ; Fri, 21 Feb 2025 13:35:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1740144913; bh=xQDKR8FhSx54xF1plKDryRTd9+jWjE/ZJaV1ShM5yWg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qghw0SxnMGt8QBC3JW9JY3x+XS3y47QbEslo7IHNjdZlGBLI8ZeXpNLHcVN3ZbO6C xl8FrToV3Ax3r8zuhHd6/YQptmSyLDw6W7+75lA4yPdWdIRLv6B8lUA3bxbC6wI1Hq YZPX6DdNTLhYnomV2IsVZ9fFh5SAsj9Ze0hmLx92Hs84Kgq1R9Vw4b3QnegP7H11O5 YlDrPQlWX0/CZ1pSCAucORmpF80awBapF23JEfF47s3zQeFbyoaf1tfMgmZ4X1vzT8 SD3kETcFwDRubHlumKMO9DNmh5xCotrBLbJzJ4sNywZIwJOYaBqHou6CmijdfYo1HK E2VKugbFBknKg== Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-2fce2954a10so3878563a91.1 for ; Fri, 21 Feb 2025 05:35:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740144912; x=1740749712; 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=xQDKR8FhSx54xF1plKDryRTd9+jWjE/ZJaV1ShM5yWg=; b=AhguDR8nMGpNPOe8JkxNOYlRemX+1eN8RyB7PSSI6Y4nDY4He9Ch0TT2+kNVTAipzZ CAGvTEZNMQraN7cDK+aEAn9mFlZFys8lUfmy59Eh1wLdJYWgtBoxk+H9Lc2WHX8QG4gC 0Zo2xegxX8PSDCokOTOh5kcCREP4qO9PQVCkF+D9zUubKIX+evst5AK7LgXApMHlhwde OLHpoqoN1zzikfbhwZ+CKFOPl/UF0YW7RB1nIV2es5tB7kxqRlLN4paNielapT/+YGhC Tu+KfdIIrMRH9nG/1yyB+gzuPtxiC+ihxGRiMxUkMvTRwsR0BBA4I4ZCl3EVQygu2GUE 1FJQ== X-Forwarded-Encrypted: i=1; AJvYcCXWv+Cnsmxd5XUw5lhfK/+n0JNaiqqjZRmBLBKQ+94TygetiIWdN2LeI/lgpI2Ix3ux3KCQL591D1h+ZaA=@vger.kernel.org X-Gm-Message-State: AOJu0YxJ9WYOTrSZuvQUAOdCUBCOnQ6jMXWLqFprnstpDINp7M7ChQK0 FEa9ZBVfmX0hBqugW1PUnmb/lhxWckUFQuj4HdIFBrLVLHZGyjDaVfbmYxOEAGm6Dc2RT2Jmte7 kRelKWX5vDtNUVvdRHWS8DOoHwOWobfXGbP8Pq7CVZ+zrpgoV/dhla+fzhtNLSNTneQTqZYJc59 tcXA== X-Gm-Gg: ASbGncvsbtGs4RljSUW+KHwDuW+TL3qoOTYUWvOcMqODpZUcFOq3rI/3cQh8yRt2W4r TqmELcNALLbodjMeW8NokaZxHOtNovNyTT3x1GxohPnbH7YAQsouvZpSj6USoNMwwMmszJthWwI o6JIoqe/ialsM+tWvPCI6nXGvbDrzIMjxClL2AsN0lStF91Enlu6aPqV2I7OAavGAuq2ZV7sBuL VoWQm+pYCZxk2xBVt1aN1YfiT2ZQhdWcGp86eW3zW+uNPSAKzwd1fovLMz1ObezOoFg2zbnqvlj Yl45T6rz7Z1NApOW X-Received: by 2002:a05:6a00:98f:b0:732:1eb2:7bf3 with SMTP id d2e1a72fcca58-73426d9f1abmr5620403b3a.21.1740144912382; Fri, 21 Feb 2025 05:35:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnNW6ktOwXAyFRQS/Z2lJ766Nk+fIdyEK6MLtv9HEvRdCBl0h57AH5PdWHmcGb/gkiaQ+5Nw== X-Received: by 2002:a05:6a00:98f:b0:732:1eb2:7bf3 with SMTP id d2e1a72fcca58-73426d9f1abmr5620358b3a.21.1740144912074; Fri, 21 Feb 2025 05:35:12 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:2777:7867:71cd:dd56]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7325d65619bsm12565459b3a.113.2025.02.21.05.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 05:35:11 -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 v3 1/3] gpio: introduce utilities for synchronous fake device creation Date: Fri, 21 Feb 2025 22:34:59 +0900 Message-ID: <20250221133501.2203897-2-koichiro.den@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250221133501.2203897-1-koichiro.den@canonical.com> References: <20250221133501.2203897-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 | 3 ++ drivers/gpio/Makefile | 3 ++ drivers/gpio/dev-sync-probe.c | 97 +++++++++++++++++++++++++++++++++++ drivers/gpio/dev-sync-probe.h | 25 +++++++++ 4 files changed, 128 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..e15405add317 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1947,3 +1947,6 @@ config GPIO_VIRTUSER endmenu =20 endif + +config DEV_SYNC_PROBE + tristate 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..9ea733b863b2 --- /dev/null +++ b/drivers/gpio/dev-sync-probe.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * 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) 2021 Bartosz Golaszewski + * Copyright (C) 2025 Koichiro Den + */ + +#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.%d", 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_AUTHOR("Koichiro Den "); +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 Mon Feb 9 03:19:20 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 8D39120AF84 for ; Fri, 21 Feb 2025 13:35:18 +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=1740144921; cv=none; b=PBub3lIRvz3RKLo+e1lESRLfAJdmivM8k+pGHAQ+p+TE4KdGPdb1VKN41L1Zsh0WodiEoXofdDimAy2GA7BeIHEZ45kLsQJTITcTWXRXeNTHa3O7NTSYuPIPgs9b4m//6Uku53CIloTF5FfiT3+ohV8h2fuIPqc3LSXeIf2YpW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740144921; c=relaxed/simple; bh=IcOH5SAseQKzkHpmHpSjfAE9mkd9Arcd9z68k2xbqrk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LJ6/qkZxNUHnUhj7J6T4T4Do6BQE7B1p6B3k34qenpyiuUoyOMiROjn6e80ivFUEgoWUQ4Vr4lFXcggdo0hvCbKE3MtO2/z2T5EQIS7hxALE+1UDJ0TEzn5PhlzRzNincdTYRKuUCHn71eD3ybPHYbXTdDmQBhFz69CgbyfV9v4= 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=Y1/b85TE; 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="Y1/b85TE" Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (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 DDA0F41962 for ; Fri, 21 Feb 2025 13:35:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1740144916; bh=YUp6LYQRCspZvbFalfM4lFVMvYXlGzGvaMoc9xWJpOo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y1/b85TE0U7hszL0IIQtMYG0YoNvlP/gWPK0BpCd6DwFWVxvbyprp8p/bZYoTI7Tu 5FD9lYc84IQzgbfOnProZSHtXM8zgAqr9j/embF50N4bXC4bX5mu5Hgf70OmHc2OB/ ONPSOlkIjz5oulgyfn4zP2KXKqZhep4ueXGmzq8UQidFVFT0S/tInLIPZ5Sim4HLQp 79ohlBF6Mkk8D/GUBku5/ByTG5m4pOjnCQXzHnr318GI0qBi6N+iwD9pKpsjPyEa/U XBzJG3cYC5TfUQW6y0RLNqubFdxt5iIlZsOW1aSiLq/h5TudcU90VM/yfd1Flv/jDF cwqmHvx6frrIA== Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-2fc1eadf5a8so4749876a91.3 for ; Fri, 21 Feb 2025 05:35:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740144915; x=1740749715; 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=YUp6LYQRCspZvbFalfM4lFVMvYXlGzGvaMoc9xWJpOo=; b=Rq/ZTEIfd87SSjxx/enX8RxLSZdjNgq5s4oPVqyQzTGwIm9zy5MgRik3aUcOXnzu2b Y5/CHp2JBCf8L75MlCbnQYhE0TnhZtRivyBGUcyWbwHw7FmJe+59RV7aLMFNGKRkEt0a 0e2dWRnwS7MD4u6IxpML26y6DlhMFibrHvc3WKlgFdyLlttbV4vPYVH6ghHjrHaqSOOg udxIsOX3ecqmKgIe0fxr1M15khg4FwhNFfyHfBORQNw5WNag4Reba/wObIsT/gQ1IGeH qhxJv8m9vJWXNM3nq0PWD/4uKKYv7L+c74HwCZJeSDAeX7IiRuKbS923iY3WStrrh0b3 591g== X-Forwarded-Encrypted: i=1; AJvYcCXPeAM89+a2NQloXJuFh2GlM5amPONx2XdG3wgcLBfHBU1q1mKPYYuU8QW4AIz9PhCbf/WCK5ws75XDtag=@vger.kernel.org X-Gm-Message-State: AOJu0YysUJDjM6fV1Dqu6ah1soI1p6R6qp+EmLEOB30+CDhOBfaeEKWg Hm6YOZOaZUirRPtzzZMXx7VRGfUP/m+QiXAVHv7T4l8CW8gfLXPNvZb7TKPa8in3FzdOmTVHmk0 Ov1G1+JSC2xObt7q05K7VpZ+0EymX12SI0JJOvK0/8tiEqvuEoqtvTL2BNuqpLD+pe86Ri7H9Wg 7U4A== X-Gm-Gg: ASbGncskaKl9N86f8MXKs3A/DnHxsCIMRzhiEdQeWkrUP80z+jFNLDEb+wrG3WnsYFf EWXMhPjLEpVKzUyqgg5PQYexrP3MTBPKznbo1mbBoJznap2RkOVa0Qj7M9yx2tNGUix+11lBS4c nWWWiE0UalRCdxjNn8TXODl0kucHmcpbA7ob+SpbJN8gRYM96ruagTiRDYjnre3uvdMJYJBZhqu cSR7AHlQjZPI5t7qZCl+VDGkoEW8pW+XoufafxU5P7VoOF/0k2NTizjkOQKQ6SMDFpsmQITicby WLXzqVGeOORwkQ3G X-Received: by 2002:a05:6a00:238b:b0:732:6248:8f5f with SMTP id d2e1a72fcca58-73426c857f0mr4943455b3a.5.1740144915292; Fri, 21 Feb 2025 05:35:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IGi1Gsb9VWYRvml0tMN8HhdWYXhcZeJKbfQe1KvSFbipBH1mXtylhLvYgpNx+o4hjB/fsJHog== X-Received: by 2002:a05:6a00:238b:b0:732:6248:8f5f with SMTP id d2e1a72fcca58-73426c857f0mr4943402b3a.5.1740144914763; Fri, 21 Feb 2025 05:35:14 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:2777:7867:71cd:dd56]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7325d65619bsm12565459b3a.113.2025.02.21.05.35.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 05:35:14 -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 v3 2/3] gpio: sim: convert to use dev-sync-probe utilities Date: Fri, 21 Feb 2025 22:35:00 +0900 Message-ID: <20250221133501.2203897-3-koichiro.den@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250221133501.2203897-1-koichiro.den@canonical.com> References: <20250221133501.2203897-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 | 1 + drivers/gpio/gpio-sim.c | 84 ++++++----------------------------------- 2 files changed, 13 insertions(+), 72 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index e15405add317..297ad8f78f38 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1909,6 +1909,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..2c0729a62fc2 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 probe_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->probe_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->probe_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->probe_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->probe_data.pdev->dev); + dev_sync_probe_unregister(&dev->probe_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->probe_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->probe_data); =20 return &no_free_ptr(dev)->group; } --=20 2.45.2 From nobody Mon Feb 9 03:19:20 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 1B8D520DD54 for ; Fri, 21 Feb 2025 13:35:20 +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=1740144923; cv=none; b=i7iFXMqJC0TFr0j6/olT6cVydFvYh5fxIPtL4ooGZrMNEOGdGZolYMZwCgrz5rJ5A12Y5uwRVLJ163chb+1poqiH9FHCi0ezrlgONY5a8HtFcd95fjEuzOGoRWehXsaBJV/bcra4sjHM6hRjToGDhQrX5XO+5ikhD28tXZ6YC5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740144923; c=relaxed/simple; bh=2sKNu9pu9EQxq0VJYOxo3RJcm9UNmjRT0MW3Pa1AWpA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FM5I97pNyKsxNPS9dk4Plhz2co0lNySijqYt2z1C6EwPJl4HMYF6Lo1Tvz1dNs+O4OXnDMSEqk+gRXpY9dCfXQez1liO63Jjpwm4H7gqs/aQ5UUGxG2zNVhh7MjXhgAal+WzAtEOsBFVSVK5FO34xwyS3sMTiORbax6G9gee6YM= 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=mb01lJQd; 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="mb01lJQd" Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (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 63EC141231 for ; Fri, 21 Feb 2025 13:35:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1740144919; bh=BkjT7/jJ++3VQmpRa1vg24+85VM0dA6Mj+g/I8mTwrc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mb01lJQdjHVfWVk76EAm1PcZhYTYPLzlyE/KGXFHRvTTVBDBL7n8BiC10f0ROH1HN CA8+9fBBOwofoq4K0xAvZVS3ZkKFTg4cG8Hc391E/PrIYgVL+hElviF77Tl9MG4Vpl Kh6Ke4c6n1m41teNf1dB1PNhlg0jm20O1xjbE5HYKWrKF5K+wKmnfDF2/4iz0tL8oV eTxfdD6KTZKkU1uinvJb7SDXhCOgt2Jtdxzv1R5TAaJ6gxCZMLlSNPJYB616yMtN/Y 3A7+TRh51NPEU4nlZY0dXv4v+pALJIN3g9IVVKzzI/ae6oSIUIvbPKgGUPK/GBORlE 3LgKScMm4I1HQ== Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-2fc1a4c150bso4321084a91.2 for ; Fri, 21 Feb 2025 05:35:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740144918; x=1740749718; 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=BkjT7/jJ++3VQmpRa1vg24+85VM0dA6Mj+g/I8mTwrc=; b=CbdHSddoAAIhNvCN1iuqLMd6TjzCoGVOWhKLYtnmyCeLC2A/MxUAzsJOD+Z1KJQWTr rQgWHe43sgeq0my20fixcbI/a7GKUJDA22nmNqxce8xwOB9e0AGY13UUb+56I4wyPhX2 59FzINFdHVJg+ntlofITu+ufUfw7O4w/3j7Q9Fr+K943SopUB3RRjwvOL/czGnruqEVY IYTSsVR+GWygZ4C9r+xLeEc2z733fUIEI3H/6SAofCEHaxZPCGwGCRAUe3gBdN8pA6kL d24fk3Vz7yZKA9FlH++bq8DNQI15ILSe6RvRcz7s06EbY0G71lpUz8jBFQqGqNTKeDvv KLCg== X-Forwarded-Encrypted: i=1; AJvYcCU+2Z1rmL6Mvzth5LPJATLWcm9QSzuYTfJL1r+jPUcHZ1lwhc+k3reDHYx2DHGmEQ8ItIBNTm810ORhxeA=@vger.kernel.org X-Gm-Message-State: AOJu0Yz04XTpY3eJyQuUSscWf9kik9Jy+eQ1DCoQ7lsgThO+X0pgwYiy XR6AEQu/yFpuRe6sziEFRGNSv/3InztxTg6uSlOaSK/JnUoVBjtEGxYmiKcuUGX2A32OB+zRvx1 SM2fpbm6597aBMLdnSma80PHDhfdtnWVx38lFUKuJscoFewOBgIUF8t1mVIg8la3CrtBQEQWySE gv0A== X-Gm-Gg: ASbGncvcgQRTNcnwO1MRO0POlFnln430UBuuWqTLSms8qaYFNBC2OfFmzsnHChpTQG5 SvfofSxUOG1t6gHjZYcS8UsuqhE/w4LRjy91crvwzR5ftJxmvVB8RXFOJgqJXL1WoQ5A3JI4Fdu Dc+OC28sOAp0Ocy38Q0yH5+M0tAfbZutBKGOoRaZY6ZHthBDSZe8tyzGyMj1xau40a5RLvjZv8Q OoFnu9OmbVA5y+xiDgI9Z1jzacOeQS2eh7cqKUNrjNVcnYaADMGCiDa9tn50aC81va13dENTG0L 17uLr2tTrDmC6o9Q X-Received: by 2002:a05:6a00:234c:b0:730:95f1:53ca with SMTP id d2e1a72fcca58-73426cb13f2mr4531978b3a.10.1740144917966; Fri, 21 Feb 2025 05:35:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IFq/r+LR01XwfOEzHEFA7rnHpUVwfkJMQ41uekwZKt7/CGhMgvh25td+6Y1WGU1qj2IhAbDxw== X-Received: by 2002:a05:6a00:234c:b0:730:95f1:53ca with SMTP id d2e1a72fcca58-73426cb13f2mr4531945b3a.10.1740144917641; Fri, 21 Feb 2025 05:35:17 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:2777:7867:71cd:dd56]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7325d65619bsm12565459b3a.113.2025.02.21.05.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 05:35:17 -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 v3 3/3] gpio: virtuser: convert to use dev-sync-probe utilities Date: Fri, 21 Feb 2025 22:35:01 +0900 Message-ID: <20250221133501.2203897-4-koichiro.den@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250221133501.2203897-1-koichiro.den@canonical.com> References: <20250221133501.2203897-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 | 1 + drivers/gpio/gpio-virtuser.c | 73 +++++------------------------------- 2 files changed, 11 insertions(+), 63 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 297ad8f78f38..59c48c632197 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1938,6 +1938,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..13407fd4f0eb 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 probe_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->probe_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->probe_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->probe_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->probe_data.pdev->dev); + dev_sync_probe_unregister(&dev->probe_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->probe_data); =20 return &no_free_ptr(dev)->group; } --=20 2.45.2