From nobody Wed Dec 17 20:55:19 2025 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 53BB6C05052 for ; Wed, 16 Aug 2023 12:21:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245090AbjHPMVD (ORCPT ); Wed, 16 Aug 2023 08:21:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245076AbjHPMUk (ORCPT ); Wed, 16 Aug 2023 08:20:40 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A306E109 for ; Wed, 16 Aug 2023 05:20:38 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id 5b1f17b1804b1-3fe5695b180so58726865e9.2 for ; Wed, 16 Aug 2023 05:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1692188437; x=1692793237; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dBA1IVl8UDrUaAnJphV0hWGX9hyQzKWTZG3aW+04r/w=; b=uMRrmYNn8OhxPbzEV75US9J4Qp1kutfTE6aCNbx3JPT8CgSYkIreOHTMZoTuI5E5K2 DJsFU3qL0dW2325cH96CCoG1sT6euM3YvFl7WpN/VOK1qNRXyrczMNVu1fTlia4xI5zA i1B7qrZQN3sGfET4pinIppZaDWQ4T5lAp5/39j2/hNY4GOndSb/nlr8anxQvZGVxPQ7T CepXRxPuOkmtqwGJBTF972YXnn9VhjWRXOs/msMFpVywbDgfTVSbFy636vLJjyToh+aC Vgk3/zzLy0c+RMbnZGMh9a6bqaEW4c9K+yM16WJcWZcixZJyiYyTlcNRhBvjxADi61RT HBRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692188437; x=1692793237; 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=dBA1IVl8UDrUaAnJphV0hWGX9hyQzKWTZG3aW+04r/w=; b=Dmxtc3BTvxuXBvZDgiibdkl/6riXHEK0VlukhsCYBuvCwIFD2mPqjDc0MLLLmWYMkM CYu0djPJa1IRBdhpbDbGbv6p3Gyeh+5kqjRyquZRLNlnlzntBCMuz0j+Z4nxK/u2lCIa 1yz6hxzfc2C8Zwpcc2NFTknz9RWyG/daA1zUV6aSYZZGyPC0yKelAGmLEhsFyUDPYevp AkBbe8cHb74nNmiGuxqzUIlBEYgfb6PYO4TG5w3pnDBRnSJ+5SNKdIZQnxWWvou74Gh+ HW6OHvLR2AkcjjgzdnJqkShDI6aZujP94p5tX3oRJ7ZH0G6qCAVG9h6KraYJ/ZXcCpG3 P21g== X-Gm-Message-State: AOJu0Yz5V8DvGeDATPnlBhl6Ojn+WbAE/upI2Y+Vi07Okto/VM6TkhSn spVB70F+bF0Zt0tMSmdHzoyqDw== X-Google-Smtp-Source: AGHT+IG1i8Q4sLfL31T9MsIoX7SkF8QEPazR8Ad7Rpp4u1ezh5QqceyHDr+yieA/tOxrDBu6ETL2lQ== X-Received: by 2002:a05:600c:215:b0:3fc:a8:dc3c with SMTP id 21-20020a05600c021500b003fc00a8dc3cmr1215136wmi.37.1692188436544; Wed, 16 Aug 2023 05:20:36 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:55ba:c083:817:86f]) by smtp.gmail.com with ESMTPSA id e6-20020adffd06000000b003196b1bb528sm14566112wrr.64.2023.08.16.05.20.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 05:20:36 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 1/5] gpio: cdev: ignore notifications other than line status changes Date: Wed, 16 Aug 2023 14:20:28 +0200 Message-Id: <20230816122032.15548-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230816122032.15548-1-brgl@bgdev.pl> References: <20230816122032.15548-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Bartosz Golaszewski In preparation for extending the role of the GPIO device's blocking notifier, make sure the callback used by the character device's file descriptor data checks the action argument and only reacts to one of the line state change values. Also: relax the kerneldoc describing the notifier as it will have more responsibilities soon. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 35 +++++++++++++++++++++++------------ drivers/gpio/gpiolib.h | 3 +-- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 0a33971c964c..062521e1a9e0 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2502,22 +2502,33 @@ static int lineinfo_changed_notify(struct notifier_= block *nb, { struct gpio_chardev_data *cdev =3D to_gpio_chardev_data(nb); struct gpio_v2_line_info_changed chg; - struct gpio_desc *desc =3D data; + struct gpio_desc *desc; int ret; =20 - if (!test_bit(gpio_chip_hwgpio(desc), cdev->watched_lines)) - return NOTIFY_DONE; + switch (action) { + case GPIO_V2_LINE_CHANGED_REQUESTED: + case GPIO_V2_LINE_CHANGED_RELEASED: + case GPIO_V2_LINE_CHANGED_CONFIG: + desc =3D data; =20 - memset(&chg, 0, sizeof(chg)); - chg.event_type =3D action; - chg.timestamp_ns =3D ktime_get_ns(); - gpio_desc_to_lineinfo(desc, &chg.info); + if (!test_bit(gpio_chip_hwgpio(desc), cdev->watched_lines)) + return NOTIFY_DONE; =20 - ret =3D kfifo_in_spinlocked(&cdev->events, &chg, 1, &cdev->wait.lock); - if (ret) - wake_up_poll(&cdev->wait, EPOLLIN); - else - pr_debug_ratelimited("lineinfo event FIFO is full - event dropped\n"); + memset(&chg, 0, sizeof(chg)); + chg.event_type =3D action; + chg.timestamp_ns =3D ktime_get_ns(); + gpio_desc_to_lineinfo(desc, &chg.info); + + ret =3D kfifo_in_spinlocked(&cdev->events, &chg, 1, + &cdev->wait.lock); + if (ret) + wake_up_poll(&cdev->wait, EPOLLIN); + else + pr_debug_ratelimited("lineinfo event FIFO is full - event dropped\n"); + break; + default: + return NOTIFY_DONE; + } =20 return NOTIFY_OK; } diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index cca81375f127..de7b3b60f7ca 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -38,8 +38,7 @@ * or name of the IP component in a System on Chip. * @data: per-instance data assigned by the driver * @list: links gpio_device:s together for traversal - * @notifier: used to notify subscribers about lines being requested, rele= ased - * or reconfigured + * @notifier: used to notify subscribers about gpio_device events * @sem: protects the structure from a NULL-pointer dereference of @chip by * user-space operations when the device gets unregistered during * a hot-unplug event --=20 2.39.2 From nobody Wed Dec 17 20:55:19 2025 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 7537EC04FE2 for ; Wed, 16 Aug 2023 12:21:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245108AbjHPMVG (ORCPT ); Wed, 16 Aug 2023 08:21:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245078AbjHPMUk (ORCPT ); Wed, 16 Aug 2023 08:20:40 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BDDB26AB for ; Wed, 16 Aug 2023 05:20:39 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3fe426b8583so65326065e9.2 for ; Wed, 16 Aug 2023 05:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1692188438; x=1692793238; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Trnt4Pw2hw6B7q451s8X3BgS42qMamduwaoaH3QQYrE=; b=ulS9QVaSFuNvBOqE7Xubi/r/LMXRdE02Lqy2ZbQH4oDNKyILIHn2fhDWOi+gqi7r+U W0JdLscK/cnETb9nWSYYYeVGioW8YfPlgdOu7B0WfeNUdXqU5tSHp8KSXawPPEY1ycNj P8Oqk4hvRGwxcrTWI3b1pY0Vnb6BcBUgrE7pD6XLOc/ZnHLrs3lcNwc+fGDBMSjnxoyv 30Ju+pEKnaUGarxLYPNjcxWkxK+DHq6yiQBYAu0Ui2evDDTMia2W8XcJ458mW/Kzya+w E6U4f8oQaYTAuors24+dgK4BP7s0HxJ64RCatn3qFS6nnQFfNaa9XuAR5Nu16ri2C0Za Reyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692188438; x=1692793238; 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=Trnt4Pw2hw6B7q451s8X3BgS42qMamduwaoaH3QQYrE=; b=HyJV6zvQYlR4a+nAvCG5W9wFyYjDIBPnqLeqomw21DCCuHbhR0rBj+24am9otBpPhn lUo6Y/E/42A4sf2oDLwsW3ybu09RrMkwviicY8DzTNxZBFr34xZmCr4u+NX/2s20p29G /+zARAVWwZNjfG+COjUoWfvMgl6Kqps4Fj7T8pbLwU4GZh2RsyrVjCERHjGdn63VVHjM j90xANpjsLETa090fjtZV+KkurbjjyQkGvaWLmIAAUiceBOGNn+sqGUcta14IOqgiuob n3fbBWx1f5AU78yQeE9FRyMUnb7WaWZRRkzdxWpvIqoZ6j7cv1eonnVRXPRFl8YEQ5XS U95w== X-Gm-Message-State: AOJu0YxfH6FEyCtrZ66P5kD7W2VIoIRTtzZ7AWOydFEBqfcRhhNmDPa0 Ir2t+5ABhhwA6iHoqJwZkOHarb8N6k3G0rymF1Jv9Q== X-Google-Smtp-Source: AGHT+IF5bC76eebhPqmm3ah8vcookk4hc3A2nk+zD/7O6fCoclca0m3Og5OKvb7VpbIFS/iJnd+wtw== X-Received: by 2002:a7b:c044:0:b0:3fe:2b76:3d7 with SMTP id u4-20020a7bc044000000b003fe2b7603d7mr1266689wmc.10.1692188437483; Wed, 16 Aug 2023 05:20:37 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:55ba:c083:817:86f]) by smtp.gmail.com with ESMTPSA id e6-20020adffd06000000b003196b1bb528sm14566112wrr.64.2023.08.16.05.20.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 05:20:37 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 2/5] gpio: cdev: rename the notifier block and notify callback Date: Wed, 16 Aug 2023 14:20:29 +0200 Message-Id: <20230816122032.15548-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230816122032.15548-1-brgl@bgdev.pl> References: <20230816122032.15548-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Bartosz Golaszewski Rename the notifier block in struct gpio_chardev_data and its callback to a more generic name as it will soon gain more functionality than only handling line state changes. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 062521e1a9e0..660d2e057451 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2319,7 +2319,7 @@ struct gpio_chardev_data { struct gpio_device *gdev; wait_queue_head_t wait; DECLARE_KFIFO(events, struct gpio_v2_line_info_changed, 32); - struct notifier_block lineinfo_changed_nb; + struct notifier_block nb; unsigned long *watched_lines; #ifdef CONFIG_GPIO_CDEV_V1 atomic_t watch_abi_version; @@ -2494,11 +2494,11 @@ static long gpio_ioctl_compat(struct file *file, un= signed int cmd, static struct gpio_chardev_data * to_gpio_chardev_data(struct notifier_block *nb) { - return container_of(nb, struct gpio_chardev_data, lineinfo_changed_nb); + return container_of(nb, struct gpio_chardev_data, nb); } =20 -static int lineinfo_changed_notify(struct notifier_block *nb, - unsigned long action, void *data) +static int gpio_chardev_notify(struct notifier_block *nb, unsigned long ac= tion, + void *data) { struct gpio_chardev_data *cdev =3D to_gpio_chardev_data(nb); struct gpio_v2_line_info_changed chg; @@ -2681,9 +2681,8 @@ static int gpio_chrdev_open(struct inode *inode, stru= ct file *file) INIT_KFIFO(cdev->events); cdev->gdev =3D gpio_device_get(gdev); =20 - cdev->lineinfo_changed_nb.notifier_call =3D lineinfo_changed_notify; - ret =3D blocking_notifier_chain_register(&gdev->notifier, - &cdev->lineinfo_changed_nb); + cdev->nb.notifier_call =3D gpio_chardev_notify; + ret =3D blocking_notifier_chain_register(&gdev->notifier, &cdev->nb); if (ret) goto out_free_bitmap; =20 @@ -2698,8 +2697,7 @@ static int gpio_chrdev_open(struct inode *inode, stru= ct file *file) return ret; =20 out_unregister_notifier: - blocking_notifier_chain_unregister(&gdev->notifier, - &cdev->lineinfo_changed_nb); + blocking_notifier_chain_unregister(&gdev->notifier, &cdev->nb); out_free_bitmap: gpio_device_put(gdev); bitmap_free(cdev->watched_lines); @@ -2722,8 +2720,7 @@ static int gpio_chrdev_release(struct inode *inode, s= truct file *file) struct gpio_device *gdev =3D cdev->gdev; =20 bitmap_free(cdev->watched_lines); - blocking_notifier_chain_unregister(&gdev->notifier, - &cdev->lineinfo_changed_nb); + blocking_notifier_chain_unregister(&gdev->notifier, &cdev->nb); gpio_device_put(gdev); kfree(cdev); =20 --=20 2.39.2 From nobody Wed Dec 17 20:55:19 2025 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 95A2FC07E8A for ; Wed, 16 Aug 2023 12:21:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245096AbjHPMVF (ORCPT ); Wed, 16 Aug 2023 08:21:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245079AbjHPMUl (ORCPT ); Wed, 16 Aug 2023 08:20:41 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB5AF26B1 for ; Wed, 16 Aug 2023 05:20:39 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3fe24dd8898so60776365e9.2 for ; Wed, 16 Aug 2023 05:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1692188438; x=1692793238; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yc+T77NE6nVI9PLsQkqlrr/xBBkFkUhqwF3/jEMdIPg=; b=Y/ihd289nZXKIxyoTl17TgP7aQSTwe8RkeUix/vGZxejIeeD90O9aXAMaaLoZqpaac HcZ3xiPoE4uRN+essCNgN7+tZIC4MiyUOtgfNI97sNNRZfgXpT5njdMiVV0TGx1WstN1 8AKMqMaxGU9X1Yq6k6O9ZJ8qCTJZ3o10pQJreea0WqsGGa961/VRl+sBoliccF5IYjeW 7HV4F1MuA93c7rN4giB5MK3p7phz/qWBDDwbjIw5SpjHXyLcILimvFY2GDaeLWExD9KH /zH56Ir3WIiJCNzq+y1XfixOQWbt3WuyPadBKM8djazEi/FhNDxOa2X0dC1JTuIPBTLo Nv6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692188438; x=1692793238; 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=yc+T77NE6nVI9PLsQkqlrr/xBBkFkUhqwF3/jEMdIPg=; b=fEFmQ+upPLxqMKPTTywevGSBwDx1y+6HaAFYhUsapmx/Kct81K+y1kT+TIaanIHmli nlV2ZuyWYA2fK+WoQbti7xooSt82tHUvmuyQ6RtNPTfMGx0HBfJhEIML4Bd8upWd2Eqx 5SlUnz+e1ET2tTwhj6+gdBvJYuQodJHS334UWRU0X+9bDm5kjWQG4HbOafDlyhTuismr ZzcDlOfpzLtZ0ARKLOYyWxzjt1eDRyvlAEBxbqFAGNSBW8lYWgm8ew3HmLN3coHhN09/ 8s/iAzWDuLAAmAQ09oIcbIVzYndqsN9CGE5RKZgRnPl7uQXieWyO70D06H+ZObdPomeA XIvg== X-Gm-Message-State: AOJu0YzYsHqNcDybgfQthM/l0xm/8ZNpUE218dKk2ujkeoNQj0uGsllm cMlI6qW4+SIrWOxyGQcYfEGVLA== X-Google-Smtp-Source: AGHT+IFEJKQoq2tV1RnY7W0jsL0DzfdsoPDjKqgbbV9zKHFRDerYe1M182sG4pkSRUTPPLCYg90rtw== X-Received: by 2002:a05:600c:1c17:b0:3fe:485f:ed1b with SMTP id j23-20020a05600c1c1700b003fe485fed1bmr1241928wms.28.1692188438347; Wed, 16 Aug 2023 05:20:38 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:55ba:c083:817:86f]) by smtp.gmail.com with ESMTPSA id e6-20020adffd06000000b003196b1bb528sm14566112wrr.64.2023.08.16.05.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 05:20:37 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 3/5] gpio: cdev: wake up chardev poll() on device unbind Date: Wed, 16 Aug 2023 14:20:30 +0200 Message-Id: <20230816122032.15548-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230816122032.15548-1-brgl@bgdev.pl> References: <20230816122032.15548-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Bartosz Golaszewski Emit a new notifier event right after the character device was unregistered and receive it in the notifier owned by the descriptor associated with the character device file. Upon reception, wake up the wait queue so that the user-space be forced out of poll() and need to go into a new system call which will then fail due to the chip being gone. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 660d2e057451..eb8c0cb71da4 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -32,6 +32,12 @@ #include "gpiolib.h" #include "gpiolib-cdev.h" =20 +/* + * Let's use a higher value for gpio_device notifications to not conflict = with + * UAPI defines that can also serve as notifier action arguments. + */ +#define GPIO_CDEV_UNREGISTERED 1000 + /* * Array sizes must ensure 64-bit alignment and not create holes in the * struct packing. @@ -2526,6 +2532,9 @@ static int gpio_chardev_notify(struct notifier_block = *nb, unsigned long action, else pr_debug_ratelimited("lineinfo event FIFO is full - event dropped\n"); break; + case GPIO_CDEV_UNREGISTERED: + wake_up_poll(&cdev->wait, EPOLLIN | EPOLLERR); + break; default: return NOTIFY_DONE; } @@ -2761,4 +2770,6 @@ int gpiolib_cdev_register(struct gpio_device *gdev, d= ev_t devt) void gpiolib_cdev_unregister(struct gpio_device *gdev) { cdev_device_del(&gdev->chrdev, &gdev->dev); + blocking_notifier_call_chain(&gdev->notifier, + GPIO_CDEV_UNREGISTERED, NULL); } --=20 2.39.2 From nobody Wed Dec 17 20:55:19 2025 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 B5E7CC0729B for ; Wed, 16 Aug 2023 12:21:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245122AbjHPMVH (ORCPT ); Wed, 16 Aug 2023 08:21:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245081AbjHPMUm (ORCPT ); Wed, 16 Aug 2023 08:20:42 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDB922136 for ; Wed, 16 Aug 2023 05:20:40 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2b9a828c920so98384041fa.1 for ; Wed, 16 Aug 2023 05:20:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1692188439; x=1692793239; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Am7bI6bfSitSW1lki/Nh1/0VtCPZ62yUJw5gPNa+qeo=; b=w0B7/+FuLacJhBAv6aShs3+zb2UZ8ABq2mnih8O4abteYETwWx5tR4GeIUJwHSS7pI NAXRnsgA3EtFmLbrgxFb8l1u2uBWAFgOR183W0dacaSWX325Vh8KcUBZDpRiB1vNZdMH 5FbSjSyWs5UT5iqI4HJYe9YQ5dAKCKDaVa7CLesL4faIioCl4Dk2+C+RtLcwvHHQ/DDh 41R/Dng25t16C+1szjVA4rC3ReVPaO08GO/TTWGkNDwopLH3oW4JnjIZwCseW4zmowW4 am1D1LJ7aYnmrL0BB48IOJjgYLxmjY6z6Wi/oUfGGSurA3NMHn2OqhLCwVindZ7R5Lcv bcTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692188439; x=1692793239; 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=Am7bI6bfSitSW1lki/Nh1/0VtCPZ62yUJw5gPNa+qeo=; b=glT/7L038X5F6WDkyEoMALhg2ufR1gSu9AnC6J1cnwXfbYxVBzpBXSAYdR4X17Bdc/ HDy2RrBuSBx9OdaWUHf5Rggsw5TLh0oe2QO5IiyP72NjqOT71qxF0pMUSOjkkULSc8mf 7t4D2Zyqvw8yEl5iDdfk7wMNGGKBzaOpVFb/YpP1eI3p7yxu3q/gsYeGDhGmJrHbLcnb nn+5+VyNcJ9xg0K3VYKDkjRymqet4XxKNK3e4PD317AeOJAx9xC/Dh9It96PPelMBQmc j6KdXbgPfjyj/4PO7QokOVx9WijgZMQuvfjaiYfOtQ2Ujyb92+N3QH6T2CcXMhtNqRzC 6Bjw== X-Gm-Message-State: AOJu0Yx0jeQbo8nxu0rRyuAqR7pDr6vcfHXOJ1dx2QGG0x2LDPj/vKyN 05zR9udqBgzfix37BYuZgKv+GMknfXLtUylWHDCoWw== X-Google-Smtp-Source: AGHT+IENColA7BIp/lKtNBrXBzmg8CdpZ/MoVKtFHesq7ljpKBW2+rbY2oBTtgZjc3gsboJdLLhpTA== X-Received: by 2002:a2e:9ac6:0:b0:2b6:a6e7:5afa with SMTP id p6-20020a2e9ac6000000b002b6a6e75afamr1498211ljj.12.1692188439174; Wed, 16 Aug 2023 05:20:39 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:55ba:c083:817:86f]) by smtp.gmail.com with ESMTPSA id e6-20020adffd06000000b003196b1bb528sm14566112wrr.64.2023.08.16.05.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 05:20:38 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 4/5] gpio: cdev: wake up linereq poll() on device unbind Date: Wed, 16 Aug 2023 14:20:31 +0200 Message-Id: <20230816122032.15548-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230816122032.15548-1-brgl@bgdev.pl> References: <20230816122032.15548-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Bartosz Golaszewski Extend struct linereq with a notifier block and use it to receive the GPIO device unregister event. Upon reception, wake up the wait queue so that the user-space be forced out of poll() and need to go into a new system call which will then fail due to the chip being gone. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index eb8c0cb71da4..0b21ea04fa52 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -563,6 +563,7 @@ struct line { * @wait: wait queue that handles blocking reads of events * @event_buffer_size: the number of elements allocated in @events * @events: KFIFO for the GPIO events + * @nb: notifier block for receiving gpio_device notifications * @seqno: the sequence number for edge events generated on all lines in * this line request. Note that this is not used when @num_lines is 1, as * the line_seqno is then the same and is cheaper to calculate. @@ -577,11 +578,17 @@ struct linereq { wait_queue_head_t wait; u32 event_buffer_size; DECLARE_KFIFO_PTR(events, struct gpio_v2_line_event); + struct notifier_block nb; atomic_t seqno; struct mutex config_mutex; struct line lines[]; }; =20 +static struct linereq *to_linereq(struct notifier_block *nb) +{ + return container_of(nb, struct linereq, nb); +} + #define GPIO_V2_LINE_BIAS_FLAGS \ (GPIO_V2_LINE_FLAG_BIAS_PULL_UP | \ GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN | \ @@ -1573,6 +1580,10 @@ static void linereq_free(struct linereq *lr) { unsigned int i; =20 + if (lr->nb.notifier_call) + blocking_notifier_chain_unregister(&lr->gdev->notifier, + &lr->nb); + for (i =3D 0; i < lr->num_lines; i++) { if (lr->lines[i].desc) { edge_detector_stop(&lr->lines[i]); @@ -1623,6 +1634,22 @@ static const struct file_operations line_fileops =3D= { #endif }; =20 +static int linereq_notify(struct notifier_block *nb, unsigned long action, + void *data) +{ + struct linereq *lr =3D to_linereq(nb); + + switch (action) { + case GPIO_CDEV_UNREGISTERED: + wake_up_poll(&lr->wait, EPOLLIN | EPOLLERR); + break; + default: + return NOTIFY_DONE; + } + + return NOTIFY_OK; +} + static int linereq_create(struct gpio_device *gdev, void __user *ip) { struct gpio_v2_line_request ulr; @@ -1733,6 +1760,11 @@ static int linereq_create(struct gpio_device *gdev, = void __user *ip) offset); } =20 + lr->nb.notifier_call =3D linereq_notify; + ret =3D blocking_notifier_chain_register(&gdev->notifier, &lr->nb); + if (ret) + goto out_free_linereq; + fd =3D get_unused_fd_flags(O_RDONLY | O_CLOEXEC); if (fd < 0) { ret =3D fd; --=20 2.39.2 From nobody Wed Dec 17 20:55:19 2025 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 D8C20C07E8C for ; Wed, 16 Aug 2023 12:21:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245133AbjHPMVI (ORCPT ); Wed, 16 Aug 2023 08:21:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245083AbjHPMUm (ORCPT ); Wed, 16 Aug 2023 08:20:42 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A202626A9 for ; Wed, 16 Aug 2023 05:20:41 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fe1d462762so59809085e9.0 for ; Wed, 16 Aug 2023 05:20:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1692188440; x=1692793240; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dP05q+RMOmNQ4Gl3VVSG0OrbP/ydNsWsk2YHlDd9aGg=; b=34QaAQx3vESmEiokl+YyNZrO0ncceSOT4XSxS0lcblrN+BAodcHQU1H2gh+RX91BhJ aD7f1IE/5OfXZ0S3X0l1ZqhjxW5OroxThQt5F2ue3iVsUt1jBs0YAPYrS8SDa5n+UogO PFfKDGsH2Ht8j5A6xDDPEp9/BOIqoLFMR+UQD2AVlqoRbJ6w0jNFv0STGrjDsff+KC02 7jAEU/SXhZzjU/tRTeSIh/p9WV4ncvfa+chMbxPsKYdshIdK6vFxuXqg2suKmDSbgUwz cQElJ3lI11PWBYyqD2PcfGBIvujXpFmfMdikcgwBgFzGo0uD/R7DYvFdlUHqzexvTNyO I7mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692188440; x=1692793240; 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=dP05q+RMOmNQ4Gl3VVSG0OrbP/ydNsWsk2YHlDd9aGg=; b=Ht2hIE/e4k9DJ1qqTJ+RhFh56DYnSgf4CdPzshtclBWG/a3zu6AZNzkf1Mi0cj6jkw IvE8B1tan84DsI00S9K6IghLDIxW4vH4EvnCjDjcq8W1YG7lqkJkb1dGICJ/o20VrBB4 nXW8n+1EeLhOnQsk/QCoQYk6LJPNBk+50eIJEtV9OLYJoTqhcLi/m+K+FcrTT16qa0aY z7poD3w+YAAY/JTQXPTsqOqME3MXMtWNqktuHzHGw/kVsX0Tn28loZbDGxk2FCUxnKcy yFpU1csiAaw9vxhM8pCQoqYyifVHdWREIIO6Y0yaNdQKCdvAxsoWXQu2Q70I3iY8+C+q JsFg== X-Gm-Message-State: AOJu0YzLK5PKkTGXmURS0wNEqy/j+k3/B+ldSRXP3/NiAEy/tqsZ4h1D 1rAoAXQxfiXPXJIGmT3LV8XUCw== X-Google-Smtp-Source: AGHT+IEV+ik5O//GvPEkYWy5rfWG/+BGwXrQ9jf7vpe8YseN9XyYNkJC6rCwpUPFnzdZtXteJF79cQ== X-Received: by 2002:a7b:cd8c:0:b0:3fa:9767:c816 with SMTP id y12-20020a7bcd8c000000b003fa9767c816mr1446313wmj.39.1692188440111; Wed, 16 Aug 2023 05:20:40 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:55ba:c083:817:86f]) by smtp.gmail.com with ESMTPSA id e6-20020adffd06000000b003196b1bb528sm14566112wrr.64.2023.08.16.05.20.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 05:20:39 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 5/5] gpio: cdev: wake up lineevent poll() on device unbind Date: Wed, 16 Aug 2023 14:20:32 +0200 Message-Id: <20230816122032.15548-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230816122032.15548-1-brgl@bgdev.pl> References: <20230816122032.15548-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Bartosz Golaszewski Extend struct lineevent_data with a notifier block and use it to receive the GPIO device unregister event. Upon reception, wake up the wait queue so that the user-space be forced out of poll() and need to go into a new system call which will then fail due to the chip being gone. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 0b21ea04fa52..bb6a011f7857 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -1830,9 +1830,15 @@ struct lineevent_state { int irq; wait_queue_head_t wait; DECLARE_KFIFO(events, struct gpioevent_data, 16); + struct notifier_block nb; u64 timestamp; }; =20 +static struct lineevent_state *to_lineevent_state(struct notifier_block *n= b) +{ + return container_of(nb, struct lineevent_state, nb); +} + #define GPIOEVENT_REQUEST_VALID_FLAGS \ (GPIOEVENT_REQUEST_RISING_EDGE | \ GPIOEVENT_REQUEST_FALLING_EDGE) @@ -1947,6 +1953,9 @@ static ssize_t lineevent_read(struct file *file, char= __user *buf, =20 static void lineevent_free(struct lineevent_state *le) { + if (le->nb.notifier_call) + blocking_notifier_chain_unregister(&le->gdev->notifier, + &le->nb); if (le->irq) free_irq(le->irq, le); if (le->desc) @@ -2084,6 +2093,22 @@ static irqreturn_t lineevent_irq_handler(int irq, vo= id *p) return IRQ_WAKE_THREAD; } =20 +static int lineevent_notify(struct notifier_block *nb, unsigned long actio= n, + void *data) +{ + struct lineevent_state *le =3D to_lineevent_state(nb); + + switch (action) { + case GPIO_CDEV_UNREGISTERED: + wake_up_poll(&le->wait, EPOLLIN | EPOLLERR); + break; + default: + return NOTIFY_DONE; + } + + return NOTIFY_OK; +} + static int lineevent_create(struct gpio_device *gdev, void __user *ip) { struct gpioevent_request eventreq; @@ -2175,6 +2200,11 @@ static int lineevent_create(struct gpio_device *gdev= , void __user *ip) INIT_KFIFO(le->events); init_waitqueue_head(&le->wait); =20 + le->nb.notifier_call =3D lineevent_notify; + ret =3D blocking_notifier_chain_register(&gdev->notifier, &le->nb); + if (ret) + goto out_free_le; + /* Request a thread to read the events */ ret =3D request_threaded_irq(irq, lineevent_irq_handler, --=20 2.39.2