From patchwork Thu Aug 17 18:49:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 714881 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 AA996C3DA70 for ; Thu, 17 Aug 2023 18:51:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354563AbjHQSue (ORCPT ); Thu, 17 Aug 2023 14:50:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354567AbjHQSuM (ORCPT ); Thu, 17 Aug 2023 14:50:12 -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 555B72727 for ; Thu, 17 Aug 2023 11:50:11 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3fe2d218eedso1878015e9.0 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=dpTBAtn92XoQWybpK5HlbB7uqQl6mTiPnFu5sZe9TyTwnCV3QGhl0L9pfJiKLeU3si e3K+yp0ngM5wQ4eVrgZkYB80A9kDIk2CUH/htSIQRdcfTXE68X1ecqnbNn84coXOYO7B OsvUhsNH/VLXNIiNxQa/386ryEEKwATZuW0B1v+XVMzZKvVyt8G/DA0lxocLWtgNiI2l FeqrUp0nCh4APdrWVdc7RRp+1TeAyRYe5p515R+IUhlrD0ukHQ53ya7mvT7wAiVadolT XPxukt1AozJZWqKFaDl9PcNBj9EhdKR41WnXar7h2kGfsWL174kIVf5rR9X+lp7LGO8S o/BQ== X-Gm-Message-State: AOJu0YzpI2AqlJLUOQYCIAy3JP+OiS5ILmw9ELEfpuwYN78Ml4NbVW4J ITBnsLOhJIM2JlE61bUiguUd+A== 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 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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 --- 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, dev_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, void *data, spin_unlock_irqrestore(&gpio_lock, flags); BLOCKING_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier); + BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier); init_rwsem(&gdev->sem); #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; #ifdef CONFIG_PINCTRL