From nobody Wed Dec 17 17:43:13 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 6DD76C531DA for ; Thu, 17 Aug 2023 18:51:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354577AbjHQSug (ORCPT ); Thu, 17 Aug 2023 14:50:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354557AbjHQSuL (ORCPT ); Thu, 17 Aug 2023 14:50:11 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AEC62D57 for ; Thu, 17 Aug 2023 11:50:09 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fe4cdb727cso1901285e9.0 for ; Thu, 17 Aug 2023 11:50:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1692298208; x=1692903008; 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=PekFEtrOYZxrIpSwnRFffcXubMgkAQwr8swW+ILwpfg=; b=IjBKcNqkZ4YPS5JZ5HtdtiCT+pNDh3PfOoIW246n5IIh3ntKzN+YMtsxh9uZNa40dL 5mc+RvqNedtLOpH9L7GKIoinBm1cpn3eVhJT4jKoNXRcLHfeZGjIvHwAjY6SaCFaOrSD NKmYpgXIYcWZyW4j6zQSQFrEzC55PXEB5z3l8vUAFs3LBd7hi8wC9ukxYzhVuEv7gZtR OfzYyMDrPf66xEkwWOwpXFcELPyN2HSecFY08JwCb71g+rkuNnH4nGxJmfo6gVEhze/s J5hWz2yNuhFGXtbw2M/Z9JsQaikVsBfkRJCzX8pua5spNz7payeSjz2kESdpRWaBKZy+ tNQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692298208; x=1692903008; 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=PekFEtrOYZxrIpSwnRFffcXubMgkAQwr8swW+ILwpfg=; b=BA9TX7+hoWvOGKM47UIrTdT8+t0dnpt0rUTA3TNTKLuTgzhz4IkDOHkIvge+yzbi16 Gr2T/9HbkCHrF4xUjWT8IY2d6Rz5TFmNpIbxsLgPPQajY6yFbR0Fi8cYtyCRy16lM7j/ yK5TdJAU4hew9cVnYDJvlYOY2EcNRyZS8uqCOGDBJJ4m+pxLl+14FQA4NQpObBzxVVFw vjKtbofWdLVysk4hKBjctdQhSkFzfWjXbv9ulLq1jLol7k+ZNm/S6Fg35eTc1ygaSI3d qlrsCELzGqOTmb1DHNtUcz5+c5FDsm3HwfU49haUNUfXV5gibXC5Et/yClACeZtWxeKB tpYg== X-Gm-Message-State: AOJu0YwMSJZlu2OTPEmpbUMJYuFHmPtz3A8PNe6y3xSCpPdWDu8U6JeP E0CoZPKTtp9HBb0/PU8pke6uPA== X-Google-Smtp-Source: AGHT+IH5WbcaWSn5QIWPOiMc7sNvzhoPyDrUanyCOyoTBOzTeoJvf4Crgt8aMBUGe/OhxLfXVTplQw== X-Received: by 2002:a05:600c:2805:b0:3fc:3f31:4233 with SMTP id m5-20020a05600c280500b003fc3f314233mr401739wmb.38.1692298207922; Thu, 17 Aug 2023 11:50:07 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:2f99:c690:b4da:e3d2]) by smtp.gmail.com with ESMTPSA id a23-20020a05600c225700b003fe1cdbc33dsm3963020wmm.9.2023.08.17.11.50.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:50:07 -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 v2 1/6] gpiolib: rename the gpio_device notifier Date: Thu, 17 Aug 2023 20:49:53 +0200 Message-Id: <20230817184958.25349-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230817184958.25349-1-brgl@bgdev.pl> References: <20230817184958.25349-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 Change the generic "notifier" name to "line_state_notifier" in order to reflect its purpose in preparation for adding a second notifier which will be used to notify wait queues about device unregistering. Signed-off-by: Bartosz Golaszewski Reviewed-by: Kent Gibson Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 16 ++++++++-------- drivers/gpio/gpiolib.c | 6 +++--- drivers/gpio/gpiolib.h | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 0a33971c964c..9ee8604f32e1 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -230,7 +230,7 @@ static long linehandle_set_config(struct linehandle_sta= te *lh, return ret; } =20 - blocking_notifier_call_chain(&desc->gdev->notifier, + blocking_notifier_call_chain(&desc->gdev->line_state_notifier, GPIO_V2_LINE_CHANGED_CONFIG, desc); } @@ -414,7 +414,7 @@ static int linehandle_create(struct gpio_device *gdev, = void __user *ip) goto out_free_lh; } =20 - blocking_notifier_call_chain(&desc->gdev->notifier, + blocking_notifier_call_chain(&desc->gdev->line_state_notifier, GPIO_V2_LINE_CHANGED_REQUESTED, desc); =20 dev_dbg(&gdev->dev, "registered chardev handle for line %d\n", @@ -1407,7 +1407,7 @@ static long linereq_set_config_unlocked(struct linere= q *lr, =20 WRITE_ONCE(line->edflags, edflags); =20 - blocking_notifier_call_chain(&desc->gdev->notifier, + blocking_notifier_call_chain(&desc->gdev->line_state_notifier, GPIO_V2_LINE_CHANGED_CONFIG, desc); } @@ -1720,7 +1720,7 @@ static int linereq_create(struct gpio_device *gdev, v= oid __user *ip) =20 lr->lines[i].edflags =3D edflags; =20 - blocking_notifier_call_chain(&desc->gdev->notifier, + blocking_notifier_call_chain(&desc->gdev->line_state_notifier, GPIO_V2_LINE_CHANGED_REQUESTED, desc); =20 dev_dbg(&gdev->dev, "registered chardev handle for line %d\n", @@ -2117,7 +2117,7 @@ static int lineevent_create(struct gpio_device *gdev,= void __user *ip) if (ret) goto out_free_le; =20 - blocking_notifier_call_chain(&desc->gdev->notifier, + blocking_notifier_call_chain(&desc->gdev->line_state_notifier, GPIO_V2_LINE_CHANGED_REQUESTED, desc); =20 irq =3D gpiod_to_irq(desc); @@ -2671,7 +2671,7 @@ static int gpio_chrdev_open(struct inode *inode, stru= ct file *file) 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, + ret =3D blocking_notifier_chain_register(&gdev->line_state_notifier, &cdev->lineinfo_changed_nb); if (ret) goto out_free_bitmap; @@ -2687,7 +2687,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, + blocking_notifier_chain_unregister(&gdev->line_state_notifier, &cdev->lineinfo_changed_nb); out_free_bitmap: gpio_device_put(gdev); @@ -2711,7 +2711,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, + blocking_notifier_chain_unregister(&gdev->line_state_notifier, &cdev->lineinfo_changed_nb); gpio_device_put(gdev); kfree(cdev); diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 76e0c38026c3..769ca2333b7a 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -841,7 +841,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, vo= id *data, =20 spin_unlock_irqrestore(&gpio_lock, flags); =20 - BLOCKING_INIT_NOTIFIER_HEAD(&gdev->notifier); + BLOCKING_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier); init_rwsem(&gdev->sem); =20 #ifdef CONFIG_PINCTRL @@ -2159,7 +2159,7 @@ static bool gpiod_free_commit(struct gpio_desc *desc) } =20 spin_unlock_irqrestore(&gpio_lock, flags); - blocking_notifier_call_chain(&desc->gdev->notifier, + blocking_notifier_call_chain(&desc->gdev->line_state_notifier, GPIOLINE_CHANGED_RELEASED, desc); =20 return ret; @@ -3995,7 +3995,7 @@ static struct gpio_desc *gpiod_find_and_request(struc= t device *consumer, return ERR_PTR(ret); } =20 - blocking_notifier_call_chain(&desc->gdev->notifier, + blocking_notifier_call_chain(&desc->gdev->line_state_notifier, GPIOLINE_CHANGED_REQUESTED, desc); =20 return desc; diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index cca81375f127..7dd06ef45d44 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -38,8 +38,8 @@ * 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 + * @line_state_notifier: used to notify subscribers about lines being + * requested, released or reconfigured * @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 @@ -63,7 +63,7 @@ struct gpio_device { const char *label; void *data; struct list_head list; - struct blocking_notifier_head notifier; + struct blocking_notifier_head line_state_notifier; struct rw_semaphore sem; =20 #ifdef CONFIG_PINCTRL --=20 2.39.2 From nobody Wed Dec 17 17:43:13 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 80220C5320E for ; Thu, 17 Aug 2023 18:51:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354593AbjHQSui (ORCPT ); Thu, 17 Aug 2023 14:50:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354562AbjHQSuL (ORCPT ); Thu, 17 Aug 2023 14:50:11 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73AFA2722 for ; Thu, 17 Aug 2023 11:50:10 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-31972944f30so169229f8f.0 for ; Thu, 17 Aug 2023 11:50:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1692298209; x=1692903009; 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=riK4Feuyj+OGhp7MokzsSI/2yP1pTtbOuk4mfbbtbPw=; b=GYmAo95/yqQGLVSyVjKRwIFLiHGmN/HvQaopOx3Zyen0W1qjJicWjcjwPtC6SRsdA9 9imZtBAZ2y2CiD96YEsDa07jw/c8hcQ1lwcsYvis/iT6ik/maqHhmR1fB6Ht5S/eXqoS BhKmSDnVCYw8My56A5GJKP5Ju9N0C45JuUMUiQha3dbR6DYgO3OowhiDj4qYvQelmdtI mg6WardO138zRvWcN6mAV9HFuFrWl36hVk8ERqXDwPRhhdvDoYLNKz36Lx24XyaFxZQR 7DNOsAjFbxZcIwawaaawn676J/wWZugMrH/PfcuxFEI6YYuEKmX+oYMBF2nmFgo/sEAw kW6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692298209; x=1692903009; 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=riK4Feuyj+OGhp7MokzsSI/2yP1pTtbOuk4mfbbtbPw=; b=jryPLEeblu0m8gTh94hSXDOaVhPOj6osPbrJkLSlPWPAAxl3ksMzBA9SB3bPwdtD7c og+PVnsKl5B5TiCvVqBFlptTanzImaMM4FGJaNHpOuYgrQOIX6mRt8sUiGgpeDdshRJq TbGS9As7ODOfdVkoaszGPzglfJv2OlddRmtKNO43S2wXHSOX9pGFwqHqQM09NuJQJSf1 srpLMHwK7MOuQ7HkdVIoPeXQiPzpIBmMj9mZUQeJ6krwlRc+VBQLnBQ6Mroe0WYsSmh1 I6NN9d6MWKPC4+u47zH2NukqUEc2oae4PbwNLf7amcs4ZUR9fprnDv4w1ECDZEj/BHTL MqoQ== X-Gm-Message-State: AOJu0YzZrMS1kQoayF/6WhUvluXmBgoxeLhi6JGjVVuv2IAp97OeO1EU Pdo+arGlpz2R0Wdhj7C43BjdqQ== X-Google-Smtp-Source: AGHT+IGE+FFRY9TRM7DM9qhp9z3k+C9jq9pUq2xe0IvfLZkq+YM8DF0s93s6bX8yLNEyt103aRFndQ== X-Received: by 2002:a05:6000:d:b0:31a:d8c0:cb8b with SMTP id h13-20020a056000000d00b0031ad8c0cb8bmr283557wrx.25.1692298208887; Thu, 17 Aug 2023 11:50:08 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:2f99:c690:b4da:e3d2]) by smtp.gmail.com with ESMTPSA id a23-20020a05600c225700b003fe1cdbc33dsm3963020wmm.9.2023.08.17.11.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:50:08 -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 v2 2/6] gpio: cdev: open-code to_gpio_chardev_data() Date: Thu, 17 Aug 2023 20:49:54 +0200 Message-Id: <20230817184958.25349-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230817184958.25349-1-brgl@bgdev.pl> References: <20230817184958.25349-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 This function is a wrapper around container_of(). It's used only once and we will have a second notifier soon, so instead of having two flavors of this helper, let's just open-code where needed. Signed-off-by: Bartosz Golaszewski Reviewed-by: Kent Gibson Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 9ee8604f32e1..df30d17f9e29 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2491,16 +2491,12 @@ static long gpio_ioctl_compat(struct file *file, un= signed int cmd, } #endif =20 -static struct gpio_chardev_data * -to_gpio_chardev_data(struct notifier_block *nb) -{ - return container_of(nb, struct gpio_chardev_data, lineinfo_changed_nb); -} - static int lineinfo_changed_notify(struct notifier_block *nb, unsigned long action, void *data) { - struct gpio_chardev_data *cdev =3D to_gpio_chardev_data(nb); + struct gpio_chardev_data *cdev =3D container_of(nb, + struct gpio_chardev_data, + lineinfo_changed_nb); struct gpio_v2_line_info_changed chg; struct gpio_desc *desc =3D data; int ret; --=20 2.39.2 From nobody Wed Dec 17 17:43:13 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 46794C52D72 for ; Thu, 17 Aug 2023 18:51:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354586AbjHQSuh (ORCPT ); Thu, 17 Aug 2023 14:50:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354568AbjHQSuM (ORCPT ); Thu, 17 Aug 2023 14:50:12 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 556C52D57 for ; Thu, 17 Aug 2023 11:50:11 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fe9c20f449so1629565e9.3 for ; Thu, 17 Aug 2023 11:50:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1692298210; x=1692903010; 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=0xjFbKJBDBiBFY+aycvUJbh13JjRxLaBnyPofJylkh8=; b=oLsg3/sOQZMmhARANNVu9DA/4a1GJa2yVTbOqFkstZ+qh3hMta52sfZC32MJZffNLo PzGgRckYbKjsqQ2UJ+R0vUsswARErk0XLgdSvMiFbwMDIWL0+onda9b8l/DILKvGxZZh welcaKpIimSIXHVPvLywgiYataXRNy+D4JVoa9JCD4jTQxIbE5vWtR+79MBVZpHr3wog uylZ/PoVr/6d7TwfLCMgOZ/N+j0J3ka57S9lZWCIjeEAv0MkQlVCcEzD2HXxDFfAqT53 WrefbmfiGPnNxebLwMj3UIwRnAoonhlNwxjgEtqKGaC73ppj+fW+LAbhsAnmllvkWFHi QluQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692298210; x=1692903010; 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=0xjFbKJBDBiBFY+aycvUJbh13JjRxLaBnyPofJylkh8=; b=BrDhp0PMmUa4ORGrN7g5KsIE6mMeiiOk/by9rWkzsxSiLVwjOmFxKYY4OH1Yh26/cL 9pXCB0lOic07xBl/bJQx+oPX//y/FTXRS2aSzNZy+pbgOe13lmC7EyZZjGtTooaPTHr4 j8r9goD2sMdVWVOJq0wLmf7iA0+fTUFZvlycVhhvCFCnuvgPqxNpaSRO3LICiqXRPElk tQ6gFeNDnm9YywaLpxytEUPAxz2ndQlEsDWA0gZU20ZWsRo1GoYQmW0D+zbJhyE6ffuQ w08CW0yHL8FJHSpAk6WMIueYXAeib5CfOuFrZBpZyMQmveNWmqJM4gGbHm/ivz1nrBOS 10Mg== X-Gm-Message-State: AOJu0YzsOnrxfh/EmDxKmgcSRtQWeRJnYeq/cYW/lC7GO05Cek/CZDTF DvYf9iKlbs/JWViTJDBvz6mBAQ== X-Google-Smtp-Source: AGHT+IFnKrGwy2wg7vBEDHiNNdtTnpnDVZuMTc5dfF3B5Kr/iaOuiSby3ZWQkJE9UxwLAvPQ3n7jeA== X-Received: by 2002:a05:600c:2299:b0:3fe:ba7:f200 with SMTP id 25-20020a05600c229900b003fe0ba7f200mr481524wmf.20.1692298209949; Thu, 17 Aug 2023 11:50:09 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:2f99:c690:b4da:e3d2]) by smtp.gmail.com with ESMTPSA id a23-20020a05600c225700b003fe1cdbc33dsm3963020wmm.9.2023.08.17.11.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:50:09 -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 v2 3/6] gpiolib: add a second blocking notifier to struct gpio_device Date: Thu, 17 Aug 2023 20:49:55 +0200 Message-Id: <20230817184958.25349-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230817184958.25349-1-brgl@bgdev.pl> References: <20230817184958.25349-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 Add a new blocking notifier to struct gpio_device and use it to notify subscribers about the GPIO device being unregistered from the device model. Signed-off-by: Bartosz Golaszewski Reviewed-by: Kent Gibson Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 1 + drivers/gpio/gpiolib.c | 1 + drivers/gpio/gpiolib.h | 3 +++ 3 files changed, 5 insertions(+) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index df30d17f9e29..f95e1b110311 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2749,4 +2749,5 @@ 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->device_notifier, 0, NULL); } diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 769ca2333b7a..0737952882cd 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -842,6 +842,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, vo= id *data, spin_unlock_irqrestore(&gpio_lock, flags); =20 BLOCKING_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier); + BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier); init_rwsem(&gdev->sem); =20 #ifdef CONFIG_PINCTRL diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 7dd06ef45d44..54012605b4a4 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -40,6 +40,8 @@ * @list: links gpio_device:s together for traversal * @line_state_notifier: used to notify subscribers about lines being * requested, released or reconfigured + * @device_notifier: used to notify character device wait queues about the= GPIO + * device being unregistered * @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 @@ -64,6 +66,7 @@ struct gpio_device { void *data; struct list_head list; struct blocking_notifier_head line_state_notifier; + struct blocking_notifier_head device_notifier; struct rw_semaphore sem; =20 #ifdef CONFIG_PINCTRL --=20 2.39.2 From nobody Wed Dec 17 17:43:13 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 9135AC531DF for ; Thu, 17 Aug 2023 18:51:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354599AbjHQSuj (ORCPT ); Thu, 17 Aug 2023 14:50:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354575AbjHQSuN (ORCPT ); Thu, 17 Aug 2023 14:50:13 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C9122D59 for ; Thu, 17 Aug 2023 11:50:12 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fe5c0e5747so976245e9.0 for ; Thu, 17 Aug 2023 11:50:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1692298211; x=1692903011; 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=JYFslBVonJ+xiQFMq+cvoNQKoDryt0Y6N5Sk/97C38o=; b=H4ktycTgIZUk7z2Gv89YRYyucNJ1IKuZffteIKLC/IMYqqwXqzGNdXGIaj8xvicGL5 19Z/uPS7iSkbzOhUOR4mpSgchdA3K7KBWGhJVmC3jkUfRIgx7Hwr68xMhdtPsieaOV+c KKWMliSmzBEatMkL6XxyrIeOkHjFbGIYUa74L0qzm5mhEZVClnhELo6srFHmzOp3Rbyk 9jVyShbxI5w83mRPsAurj4QX6FHFMjMj7CI8wB0JrE74BPag1IPew31mgONGRmQhZL51 wP+zktd3YGdmjHE56JomwwgXrrsgcIsfzCf9M6CqRhJpxX+1MtOmv4os92G4fvjujFrr U71A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692298211; x=1692903011; 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=JYFslBVonJ+xiQFMq+cvoNQKoDryt0Y6N5Sk/97C38o=; b=fqzj8c5RhG6FmSxYmdvifqyezEWT/Lf5Dc5ihSZgYOnbfJeUmvQa2y0uOF1w/Yjnjo DMZUYAteWNslYQVGJ+dQWPs+ul6S733Mpb47UXsGsVsrIJ0UhtCc/U88lejEEyBLykov R4eBeQSxtOv3YLIO5gKDpOBJE0Crp0RmT1K2KoVkBiw1CWFpatTFe7t7JR1K0nxkho8K XcE75nodQEonCiCoykGovADtv7li0btL1PNZP48n2xxXQRPAmNWyebq2+vs8uKLUUNri MWX19K8ShSslIym48WTj4dJp/yVcffAAjfAR1VmS++VV2S1Wv6c4tWuk0Z/pIPHVuR1D GMqw== X-Gm-Message-State: AOJu0YwC9HovYjRik79aEiaGBGnEpWqyl3fsHUw1oxwU2PiYn27x7Iy0 uHsLsSGNUAZxPvyyEaHTBr3TZA== X-Google-Smtp-Source: AGHT+IHfvoii3PIDV2LNoeGZYozUdevK9jCGsdAl7Uk1OZnf+6niJhlgMte797oeM4DVqnbpikVZHQ== X-Received: by 2002:a05:600c:294b:b0:3fd:2e87:aa28 with SMTP id n11-20020a05600c294b00b003fd2e87aa28mr186799wmd.15.1692298210890; Thu, 17 Aug 2023 11:50:10 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:2f99:c690:b4da:e3d2]) by smtp.gmail.com with ESMTPSA id a23-20020a05600c225700b003fe1cdbc33dsm3963020wmm.9.2023.08.17.11.50.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:50:10 -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 v2 4/6] gpio: cdev: wake up chardev poll() on device unbind Date: Thu, 17 Aug 2023 20:49:56 +0200 Message-Id: <20230817184958.25349-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230817184958.25349-1-brgl@bgdev.pl> References: <20230817184958.25349-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 Add a notifier block to the gpio_chardev_data structure and register it with the gpio_device's device notifier. Upon reception of an event, 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: Kent Gibson Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index f95e1b110311..8b081c9b8d27 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2320,6 +2320,7 @@ struct gpio_chardev_data { wait_queue_head_t wait; DECLARE_KFIFO(events, struct gpio_v2_line_info_changed, 32); struct notifier_block lineinfo_changed_nb; + struct notifier_block device_unregistered_nb; unsigned long *watched_lines; #ifdef CONFIG_GPIO_CDEV_V1 atomic_t watch_abi_version; @@ -2518,6 +2519,18 @@ static int lineinfo_changed_notify(struct notifier_b= lock *nb, return NOTIFY_OK; } =20 +static int gpio_device_unregistered_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct gpio_chardev_data *cdev =3D container_of(nb, + struct gpio_chardev_data, + device_unregistered_nb); + + wake_up_poll(&cdev->wait, EPOLLIN | EPOLLERR); + + return NOTIFY_OK; +} + static __poll_t lineinfo_watch_poll_unlocked(struct file *file, struct poll_table_struct *pollt) { @@ -2672,17 +2685,27 @@ static int gpio_chrdev_open(struct inode *inode, st= ruct file *file) if (ret) goto out_free_bitmap; =20 + cdev->device_unregistered_nb.notifier_call =3D + gpio_device_unregistered_notify; + ret =3D blocking_notifier_chain_register(&gdev->device_notifier, + &cdev->device_unregistered_nb); + if (ret) + goto out_unregister_line_notifier; + file->private_data =3D cdev; =20 ret =3D nonseekable_open(inode, file); if (ret) - goto out_unregister_notifier; + goto out_unregister_device_notifier; =20 up_read(&gdev->sem); =20 return ret; =20 -out_unregister_notifier: +out_unregister_device_notifier: + blocking_notifier_chain_unregister(&gdev->device_notifier, + &cdev->device_unregistered_nb); +out_unregister_line_notifier: blocking_notifier_chain_unregister(&gdev->line_state_notifier, &cdev->lineinfo_changed_nb); out_free_bitmap: @@ -2707,6 +2730,8 @@ 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->device_notifier, + &cdev->device_unregistered_nb); blocking_notifier_chain_unregister(&gdev->line_state_notifier, &cdev->lineinfo_changed_nb); gpio_device_put(gdev); --=20 2.39.2 From nobody Wed Dec 17 17:43:13 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 2BD3FC52CDA for ; Thu, 17 Aug 2023 19:01:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352612AbjHQTBZ (ORCPT ); Thu, 17 Aug 2023 15:01:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354583AbjHQSuO (ORCPT ); Thu, 17 Aug 2023 14:50:14 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C2482D64 for ; Thu, 17 Aug 2023 11:50:13 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3fe5c0e5747so976325e9.0 for ; Thu, 17 Aug 2023 11:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1692298212; x=1692903012; 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=8kVt4UaEckj/OVSUq+AY8VPPJo4yqLEpGjl9otmnnyg=; b=ie4buCgMtbVu3kOFSWsnDYS8jBNS8e9g6vpCbKP8e2rDg8wTzklwY+VbgFsx6vX4t8 hvfnQ6lGuYHl+lGuCTDTGYcLX/2wpO37OGyve7s6L9Ugpo6otpVQMYU9NvAwiJdax9Vc OW3/fPEk85VbPhcks0aLcjac9Z/PGLIvpmsZzZa/pM1w6cpDLjoiYpa3wF6TwJ2N66aD 3Yb4oZGITDyZz2ABoD3ryiSA7oVw9nX/eqDlDb8VQtA5MnPXewjJVr0nRtv6sa9fs0mm EpaGVKrO+LXshyF4B9GnK4rSxP3H28CheAt3lHtPh3wIXmLrGKs6m7IUrlLgXHDfh9pg kxbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692298212; x=1692903012; 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=8kVt4UaEckj/OVSUq+AY8VPPJo4yqLEpGjl9otmnnyg=; b=OILBB1RJEEyL8yfDZ0OhlvVEeiDn7q+i83n0I0+eGa39/y1Wh9dP+k6M38ckTiNw1g UZWUT8MH6pqlhVc3SIBJwOCFbM/U8w10ij+0mVxS/uzphPOoUKWTzmSXjQllfEb8ce3w d+9mDbKOFMdsj069IAWd/79aejCbhy9x2Qe6LWy4PHJJlTGRI9FsZMoKKLUwi98tFrSw SdXdK7yLEiPIqiGNoWJDb0M9FIfBbDv38NF1IflOyaTKwMZWQ4I/3V5EW7bmJAmm1EpU jvLxHPJNx1kca8RBn2DHsuCU2mrkdmNdAYbAW80cnUG7ztLq1DArL/8OpYWPUVjHOsB5 PnpQ== X-Gm-Message-State: AOJu0Yx5cK+DtTXMsI7+iDrCijZgzkwfL+yg8Is3v7Hr2PdLBNwryWEr TtUArzrZttsBoYbyz2VldKwcWg== X-Google-Smtp-Source: AGHT+IGa0mywF2NM0O4rN+E+N22z2zGoSyswdtJ2cOuvxwj301QyVM3fuuFhUWCLMCbxcN5eybT61Q== X-Received: by 2002:a1c:4c12:0:b0:3fb:af9a:bf30 with SMTP id z18-20020a1c4c12000000b003fbaf9abf30mr195111wmf.2.1692298211708; Thu, 17 Aug 2023 11:50:11 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:2f99:c690:b4da:e3d2]) by smtp.gmail.com with ESMTPSA id a23-20020a05600c225700b003fe1cdbc33dsm3963020wmm.9.2023.08.17.11.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:50:11 -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 v2 5/6] gpio: cdev: wake up linereq poll() on device unbind Date: Thu, 17 Aug 2023 20:49:57 +0200 Message-Id: <20230817184958.25349-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230817184958.25349-1-brgl@bgdev.pl> References: <20230817184958.25349-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 Add a notifier block to the linereq structure and register it with the gpio_device's device notifier. Upon reception of an event, 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: Kent Gibson Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 8b081c9b8d27..4c3b186bc638 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -555,6 +555,7 @@ struct line { * @label: consumer label used to tag GPIO descriptors * @num_lines: the number of lines in the lines array * @wait: wait queue that handles blocking reads of events + * @device_unregistered_nb: notifier block for receiving gdev unregister e= vents * @event_buffer_size: the number of elements allocated in @events * @events: KFIFO for the GPIO events * @seqno: the sequence number for edge events generated on all lines in @@ -569,6 +570,7 @@ struct linereq { const char *label; u32 num_lines; wait_queue_head_t wait; + struct notifier_block device_unregistered_nb; u32 event_buffer_size; DECLARE_KFIFO_PTR(events, struct gpio_v2_line_event); atomic_t seqno; @@ -610,6 +612,17 @@ struct linereq { GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE | \ GPIO_V2_LINE_EDGE_FLAGS) =20 +static int linereq_unregistered_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct linereq *lr =3D container_of(nb, struct linereq, + device_unregistered_nb); + + wake_up_poll(&lr->wait, EPOLLIN | EPOLLERR); + + return NOTIFY_OK; +} + static void linereq_put_event(struct linereq *lr, struct gpio_v2_line_event *le) { @@ -1567,6 +1580,10 @@ static void linereq_free(struct linereq *lr) { unsigned int i; =20 + if (lr->device_unregistered_nb.notifier_call) + blocking_notifier_chain_unregister(&lr->gdev->device_notifier, + &lr->device_unregistered_nb); + for (i =3D 0; i < lr->num_lines; i++) { if (lr->lines[i].desc) { edge_detector_stop(&lr->lines[i]); @@ -1727,6 +1744,12 @@ static int linereq_create(struct gpio_device *gdev, = void __user *ip) offset); } =20 + lr->device_unregistered_nb.notifier_call =3D linereq_unregistered_notify; + ret =3D blocking_notifier_chain_register(&gdev->device_notifier, + &lr->device_unregistered_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 17:43:13 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 A1506C5479A for ; Thu, 17 Aug 2023 18:51:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354604AbjHQSuk (ORCPT ); Thu, 17 Aug 2023 14:50:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354590AbjHQSuP (ORCPT ); Thu, 17 Aug 2023 14:50:15 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 261622722 for ; Thu, 17 Aug 2023 11:50:14 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fe1d462762so1906825e9.0 for ; Thu, 17 Aug 2023 11:50:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1692298212; x=1692903012; 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=Ymh7FtRtjmNqFd5iXsBgPf98eexBLYZK+7NV8eOQbss=; b=qUnHYo2R5NY07SwtBVrLB+cELSlnFOYYRN03P7vvjPjZuIuPHyWfTWaLN1ErKtjlqP bYWVqs7taGTCwggjcL3BzWcr557kkFPZRMweo0pWGsKnHbYmi5iwQwTi7du/vIfYXMYt LNXTlEx+mlpu6zl8ixAXJW13tkDxYXCKZCi8vYukF2MFR5+JvjtoDiqo6C9NZ7X+Ud6q QVY+D4IoaF2Z2tTd7SDBzAppL8muK9WRwH6dbOXXna6hchjx0bGIKu5b206lUiR2pk5k WTK2mZGb6cZPGWcyGZmHJQR3JbFyCRm0HZm6D+retC1/Zi9xZlyxuPWgo/fQdpMPzNG2 geUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692298212; x=1692903012; 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=Ymh7FtRtjmNqFd5iXsBgPf98eexBLYZK+7NV8eOQbss=; b=erxGBL6swPrULct33bh3UWg11ywhYNkRieiQwYatX1BXSgfZ813WrtC1lyaKuAC9EV Fyg1aVO3wyZYalsgsS31C85JCT3jDpU6hwJK6cCVkuRUDEUX1AduItHVdYZvk1rJ6BBN FBLy/HfR6dwx1X6JjDtykoZKMoxjh8irOFH2qW99ls7deoJz8qhIJB2dJV+TZFFxYk7k W0InYJAoS3N7J/HFLWfVm3xFg3wykxHfyo9dwRpGtIfJy8vskhAVem0rpofG4m6NT73m vblmYkAgNOtSgqqm2vkHBr8Ai5KRouSapcNGC/n9tr6ljiOVmXz1c2/MzS0EdUud2Qx3 AqGg== X-Gm-Message-State: AOJu0YwB0IGgI3F3x7HVgOuvnVZRHpB/pGqfigj8JOHIBdLK6cLutsxl SNsBDm0FqE+WPAHPT0031XxutQ== X-Google-Smtp-Source: AGHT+IGEkvy4TWcD9g9170QYDYF4klTaCVDRS1y5zHC7+DrV5zU7NafjnIW8fB1BcZJI2wLMIYs9/g== X-Received: by 2002:a1c:cc16:0:b0:3f8:2777:15e with SMTP id h22-20020a1ccc16000000b003f82777015emr463874wmb.31.1692298212737; Thu, 17 Aug 2023 11:50:12 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:2f99:c690:b4da:e3d2]) by smtp.gmail.com with ESMTPSA id a23-20020a05600c225700b003fe1cdbc33dsm3963020wmm.9.2023.08.17.11.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:50:12 -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 v2 6/6] gpio: cdev: wake up lineevent poll() on device unbind Date: Thu, 17 Aug 2023 20:49:58 +0200 Message-Id: <20230817184958.25349-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230817184958.25349-1-brgl@bgdev.pl> References: <20230817184958.25349-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 Add a notifier block to the lineevent_state structure and register it with the gpio_device's device notifier. Upon reception of an event, 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: Kent Gibson Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 4c3b186bc638..76a71471c724 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -1802,6 +1802,7 @@ static int linereq_create(struct gpio_device *gdev, v= oid __user *ip) * @eflags: the event flags this line was requested with * @irq: the interrupt that trigger in response to events on this GPIO * @wait: wait queue that handles blocking reads of events + * @device_unregistered_nb: notifier block for receiving gdev unregister e= vents * @events: KFIFO for the GPIO events * @timestamp: cache for the timestamp storing it between hardirq * and IRQ thread, used to bring the timestamp close to the actual @@ -1814,6 +1815,7 @@ struct lineevent_state { u32 eflags; int irq; wait_queue_head_t wait; + struct notifier_block device_unregistered_nb; DECLARE_KFIFO(events, struct gpioevent_data, 16); u64 timestamp; }; @@ -1847,6 +1849,17 @@ static __poll_t lineevent_poll(struct file *file, return call_poll_locked(file, wait, le->gdev, lineevent_poll_unlocked); } =20 +static int lineevent_unregistered_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct lineevent_state *le =3D container_of(nb, struct lineevent_state, + device_unregistered_nb); + + wake_up_poll(&le->wait, EPOLLIN | EPOLLERR); + + return NOTIFY_OK; +} + struct compat_gpioeevent_data { compat_u64 timestamp; u32 id; @@ -1932,6 +1945,9 @@ static ssize_t lineevent_read(struct file *file, char= __user *buf, =20 static void lineevent_free(struct lineevent_state *le) { + if (le->device_unregistered_nb.notifier_call) + blocking_notifier_chain_unregister(&le->gdev->device_notifier, + &le->device_unregistered_nb); if (le->irq) free_irq(le->irq, le); if (le->desc) @@ -2160,6 +2176,12 @@ static int lineevent_create(struct gpio_device *gdev= , void __user *ip) INIT_KFIFO(le->events); init_waitqueue_head(&le->wait); =20 + le->device_unregistered_nb.notifier_call =3D lineevent_unregistered_notif= y; + ret =3D blocking_notifier_chain_register(&gdev->device_notifier, + &le->device_unregistered_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