From nobody Mon Feb 9 17:21:46 2026 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7045C12B68 for ; Mon, 5 Feb 2024 09:34:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125670; cv=none; b=ebP7A2kfk8Wog6/mmNXi3tb+EKmA7/nyywEitjfITkDtIgAbpCZP9l0KfxZevc3PAeKc0IVhsrpWFZPJNc+WzR4b02QrzXpN7b8c5aDh7pgMX9nhY5OIPtlu2hW9f4C9FjVPmf9+UC4tcii37C5cXaExsAVEMfFbpN/G3JZTZ6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125670; c=relaxed/simple; bh=0Rfbf/BB2kuh3N9x1MELf3P0npd6SPlaMiWUc84gE7I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=h9bEgfYjcDHHjy1ElJrGPkHm7bGBF2kipdXXy8leBhMIgX1mGVaST++Ae4+vV5/q96OV87Zaul6oQWlLBqCF+w969z+cYPwEvY5v0UW27bAE61P+xqLYzI3fx2ioVzoUpdtXY2OF1JhzLktaukqyipceFJbIYPzZFDzvPA8BxSs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=jyOguWp+; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="jyOguWp+" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-511206d1c89so5689223e87.1 for ; Mon, 05 Feb 2024 01:34:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125666; x=1707730466; darn=vger.kernel.org; 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=gZRS1zyu26vQVi7j92zbmxVuaJZtVgYt1D5+4xPvFSc=; b=jyOguWp+kpH09gVJsrPO5KACqVmtQ3Ge82ffKzQ6D3X52lpjz6REcBUl5zFnwf+ZSF nwoP6FOvdi4E5tG0qWbhlMsgYvn0utd3R+qe/8ud9Jw90glrAAOVJ2gu2gfVFDieyb4i /gNWUInc16TgGmfoVTwkQ4KOc+3M+iMX4buxQJaAErsID9x7AezrxfHwsBB5Ip+Sjh1B 8ZRAtLsZcGvDRd9e6EkHpe6iBi7fOW0h1uU4QoZCwGdKPiwWwLb6BKT+t2lgsJtX65yC 1cEWOAunYNRlB24e0ObVNA23TVt3+j2cofTGMl/3Qsem7Qms1oFlgK+RTg0Ih9rHazDk nYYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125666; x=1707730466; 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=gZRS1zyu26vQVi7j92zbmxVuaJZtVgYt1D5+4xPvFSc=; b=Tx8cqV83giKlnGVLNmfBW5ex12BKX8d9OMyTZkQWYoTRlm6HeXdJ+bjXKnoQ1ppZmF i8m3GIjj33nF3izj4xlVeNie3CdRhEIWmMZw1amcWQmfD7tzVJV9XxP7JetgYrGRCzS4 nnYnGvPQTvWwKWKD9KmnIqsq57LGvJF1KN/SC6+fpRrSXVc6LSpFX3vwpY+I0pj8P0FK coMb2Eb9Nu1ExV39IQQyb4eX6Yw43UkuRnc8sjzHwVUT2nefKEEyJREuAnpCHgBVR83w Vx/zX8NM6Q43BVbJHTugmcMQfyNdsR5FdgGZiXWLIKOkj38JSn/UcsySwp5Nh0yEMrJ1 xwgg== X-Gm-Message-State: AOJu0YybcCvWdyLJB+bnvtv77VQWDijxpOyOZuBWX3US8bWKFq6jHZU5 U3+p0x1EOBYIBjJ3SODYI/v9eaHdQsbKNedpebVJPBZ4KJr1BYfQDguHYVJzRDU= X-Google-Smtp-Source: AGHT+IEd6tunhVzZkyJVEKC6oz3MaVkv9hic/ul3q8nrd/ZO1wINV/ecIdZh/NoroatsW9bNRhx2CA== X-Received: by 2002:a05:6512:499:b0:511:4e85:5b2e with SMTP id v25-20020a056512049900b005114e855b2emr1712174lfq.24.1707125666288; Mon, 05 Feb 2024 01:34:26 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCU+vE/hN5OHfThEldMWTXwjgwpzbjEIJXxJbsGGLwcQ3GS81/JAXe1wWuze1QVKDWESvHMDgYFpcnOzOZNAg64butxJVKCqHwfBpyCP6I5G8vsNwhcqT0ua8ubiGtu3ywLv3Mu2HqXx0E+RGoa631p+MMEmyRNvqWFD4FbDabeyjooQobe8SgiJZ1bTu9rZ9h2K8JS2dANB4zn8pQ3jOza6khb66H6bmKwh3TtAl86R6CWO41NlYVYW/uAJLQImEyD/+3xTpB1iynNXbvPyT8bvN2/6ck7wwfd2wBD3vH7UZMsy+lljQJipgJiXgBOJAE3xNO2XRyXEVS9pPRaXQ0Jwx65HMNiVUg== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:25 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 01/23] gpio: protect the list of GPIO devices with SRCU Date: Mon, 5 Feb 2024 10:33:56 +0100 Message-Id: <20240205093418.39755-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski We're working towards removing the "multi-function" GPIO spinlock that's implemented terribly wrong. We tried using an RW-semaphore to protect the list of GPIO devices but it turned out that we still have old code using legacy GPIO calls that need to translate the global GPIO number to the address of the associated descriptor and - to that end - traverse the list while holding the lock. If we change the spinlock to a sleeping lock then we'll end up with "scheduling while atomic" bugs. Let's allow lockless traversal of the list using SRCU and only use the mutex when modyfing the list. While at it: let's protect the period between when we start the lookup and when we finally request the descriptor (increasing the reference count of the GPIO device) with the SRCU read lock. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 220 ++++++++++++++++++++++------------------- 1 file changed, 116 insertions(+), 104 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index d50a786f8176..a14eef93ead8 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2,6 +2,7 @@ =20 #include #include +#include #include #include #include @@ -14,12 +15,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include =20 #include @@ -81,7 +84,12 @@ DEFINE_SPINLOCK(gpio_lock); =20 static DEFINE_MUTEX(gpio_lookup_lock); static LIST_HEAD(gpio_lookup_list); + LIST_HEAD(gpio_devices); +/* Protects the GPIO device list against concurrent modifications. */ +static DEFINE_MUTEX(gpio_devices_lock); +/* Ensures coherence during read-only accesses to the list of GPIO devices= . */ +DEFINE_STATIC_SRCU(gpio_devices_srcu); =20 static DEFINE_MUTEX(gpio_machine_hogs_mutex); static LIST_HEAD(gpio_machine_hogs); @@ -113,20 +121,16 @@ static inline void desc_set_label(struct gpio_desc *d= , const char *label) struct gpio_desc *gpio_to_desc(unsigned gpio) { struct gpio_device *gdev; - unsigned long flags; =20 - spin_lock_irqsave(&gpio_lock, flags); - - list_for_each_entry(gdev, &gpio_devices, list) { - if (gdev->base <=3D gpio && - gdev->base + gdev->ngpio > gpio) { - spin_unlock_irqrestore(&gpio_lock, flags); - return &gdev->descs[gpio - gdev->base]; + scoped_guard(srcu, &gpio_devices_srcu) { + list_for_each_entry_srcu(gdev, &gpio_devices, list, + srcu_read_lock_held(&gpio_devices_srcu)) { + if (gdev->base <=3D gpio && + gdev->base + gdev->ngpio > gpio) + return &gdev->descs[gpio - gdev->base]; } } =20 - spin_unlock_irqrestore(&gpio_lock, flags); - if (!gpio_is_valid(gpio)) pr_warn("invalid GPIO %d\n", gpio); =20 @@ -282,7 +286,8 @@ static int gpiochip_find_base_unlocked(int ngpio) struct gpio_device *gdev; int base =3D GPIO_DYNAMIC_BASE; =20 - list_for_each_entry(gdev, &gpio_devices, list) { + list_for_each_entry_srcu(gdev, &gpio_devices, list, + lockdep_is_held(&gpio_devices_lock)) { /* found a free space? */ if (gdev->base >=3D base + ngpio) break; @@ -354,23 +359,25 @@ static int gpiodev_add_to_list_unlocked(struct gpio_d= evice *gdev) { struct gpio_device *prev, *next; =20 + lockdep_assert_held(&gpio_devices_lock); + if (list_empty(&gpio_devices)) { /* initial entry in list */ - list_add_tail(&gdev->list, &gpio_devices); + list_add_tail_rcu(&gdev->list, &gpio_devices); return 0; } =20 next =3D list_first_entry(&gpio_devices, struct gpio_device, list); if (gdev->base + gdev->ngpio <=3D next->base) { /* add before first entry */ - list_add(&gdev->list, &gpio_devices); + list_add_rcu(&gdev->list, &gpio_devices); return 0; } =20 prev =3D list_last_entry(&gpio_devices, struct gpio_device, list); if (prev->base + prev->ngpio <=3D gdev->base) { /* add behind last entry */ - list_add_tail(&gdev->list, &gpio_devices); + list_add_tail_rcu(&gdev->list, &gpio_devices); return 0; } =20 @@ -382,11 +389,13 @@ static int gpiodev_add_to_list_unlocked(struct gpio_d= evice *gdev) /* add between prev and next */ if (prev->base + prev->ngpio <=3D gdev->base && gdev->base + gdev->ngpio <=3D next->base) { - list_add(&gdev->list, &prev->list); + list_add_rcu(&gdev->list, &prev->list); return 0; } } =20 + synchronize_srcu(&gpio_devices_srcu); + return -EBUSY; } =20 @@ -399,26 +408,21 @@ static int gpiodev_add_to_list_unlocked(struct gpio_d= evice *gdev) static struct gpio_desc *gpio_name_to_desc(const char * const name) { struct gpio_device *gdev; - unsigned long flags; + struct gpio_desc *desc; =20 if (!name) return NULL; =20 - spin_lock_irqsave(&gpio_lock, flags); - - list_for_each_entry(gdev, &gpio_devices, list) { - struct gpio_desc *desc; + guard(srcu)(&gpio_devices_srcu); =20 + list_for_each_entry_srcu(gdev, &gpio_devices, list, + srcu_read_lock_held(&gpio_devices_srcu)) { for_each_gpio_desc(gdev->chip, desc) { - if (desc->name && !strcmp(desc->name, name)) { - spin_unlock_irqrestore(&gpio_lock, flags); + if (desc->name && !strcmp(desc->name, name)) return desc; - } } } =20 - spin_unlock_irqrestore(&gpio_lock, flags); - return NULL; } =20 @@ -748,7 +752,10 @@ static void gpiochip_setup_devs(void) struct gpio_device *gdev; int ret; =20 - list_for_each_entry(gdev, &gpio_devices, list) { + guard(srcu)(&gpio_devices_srcu); + + list_for_each_entry_srcu(gdev, &gpio_devices, list, + srcu_read_lock_held(&gpio_devices_srcu)) { ret =3D gpiochip_setup_dev(gdev); if (ret) dev_err(&gdev->dev, @@ -813,7 +820,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, vo= id *data, struct lock_class_key *request_key) { struct gpio_device *gdev; - unsigned long flags; unsigned int i; int base =3D 0; int ret =3D 0; @@ -878,49 +884,47 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, = void *data, =20 gdev->ngpio =3D gc->ngpio; =20 - spin_lock_irqsave(&gpio_lock, flags); - - /* - * TODO: this allocates a Linux GPIO number base in the global - * GPIO numberspace for this chip. In the long run we want to - * get *rid* of this numberspace and use only descriptors, but - * it may be a pipe dream. It will not happen before we get rid - * of the sysfs interface anyways. - */ - base =3D gc->base; - if (base < 0) { - base =3D gpiochip_find_base_unlocked(gc->ngpio); + scoped_guard(mutex, &gpio_devices_lock) { + /* + * TODO: this allocates a Linux GPIO number base in the global + * GPIO numberspace for this chip. In the long run we want to + * get *rid* of this numberspace and use only descriptors, but + * it may be a pipe dream. It will not happen before we get rid + * of the sysfs interface anyways. + */ + base =3D gc->base; if (base < 0) { - spin_unlock_irqrestore(&gpio_lock, flags); - ret =3D base; - base =3D 0; + base =3D gpiochip_find_base_unlocked(gc->ngpio); + if (base < 0) { + ret =3D base; + base =3D 0; + goto err_free_label; + } + + /* + * TODO: it should not be necessary to reflect the + * assigned base outside of the GPIO subsystem. Go over + * drivers and see if anyone makes use of this, else + * drop this and assign a poison instead. + */ + gc->base =3D base; + } else { + dev_warn(&gdev->dev, + "Static allocation of GPIO base is deprecated, use dynamic allocation= .\n"); + } + + gdev->base =3D base; + + ret =3D gpiodev_add_to_list_unlocked(gdev); + if (ret) { + chip_err(gc, "GPIO integer space overlap, cannot add chip\n"); goto err_free_label; } - /* - * TODO: it should not be necessary to reflect the assigned - * base outside of the GPIO subsystem. Go over drivers and - * see if anyone makes use of this, else drop this and assign - * a poison instead. - */ - gc->base =3D base; - } else { - dev_warn(&gdev->dev, - "Static allocation of GPIO base is deprecated, use dynamic allocation.= \n"); - } - gdev->base =3D base; - - ret =3D gpiodev_add_to_list_unlocked(gdev); - if (ret) { - spin_unlock_irqrestore(&gpio_lock, flags); - chip_err(gc, "GPIO integer space overlap, cannot add chip\n"); - goto err_free_label; } =20 for (i =3D 0; i < gc->ngpio; i++) gdev->descs[i].gdev =3D gdev; =20 - 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); @@ -1011,9 +1015,9 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, = void *data, goto err_print_message; } err_remove_from_list: - spin_lock_irqsave(&gpio_lock, flags); - list_del(&gdev->list); - spin_unlock_irqrestore(&gpio_lock, flags); + scoped_guard(mutex, &gpio_devices_lock) + list_del_rcu(&gdev->list); + synchronize_srcu(&gpio_devices_srcu); err_free_label: kfree_const(gdev->label); err_free_descs: @@ -1076,8 +1080,9 @@ void gpiochip_remove(struct gpio_chip *gc) dev_crit(&gdev->dev, "REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n"); =20 - scoped_guard(spinlock_irqsave, &gpio_lock) - list_del(&gdev->list); + scoped_guard(mutex, &gpio_devices_lock) + list_del_rcu(&gdev->list); + synchronize_srcu(&gpio_devices_srcu); =20 /* * The gpiochip side puts its use of the device to rest here: @@ -1125,7 +1130,7 @@ struct gpio_device *gpio_device_find(void *data, */ might_sleep(); =20 - guard(spinlock_irqsave)(&gpio_lock); + guard(srcu)(&gpio_devices_srcu); =20 list_for_each_entry(gdev, &gpio_devices, list) { if (gdev->chip && match(gdev->chip, data)) @@ -4133,30 +4138,39 @@ static struct gpio_desc *gpiod_find_and_request(str= uct device *consumer, bool platform_lookup_allowed) { unsigned long lookupflags =3D GPIO_LOOKUP_FLAGS_DEFAULT; - struct gpio_desc *desc; - int ret; - - desc =3D gpiod_find_by_fwnode(fwnode, consumer, con_id, idx, &flags, &loo= kupflags); - if (gpiod_not_found(desc) && platform_lookup_allowed) { - /* - * Either we are not using DT or ACPI, or their lookup did not - * return a result. In that case, use platform lookup as a - * fallback. - */ - dev_dbg(consumer, "using lookup tables for GPIO lookup\n"); - desc =3D gpiod_find(consumer, con_id, idx, &lookupflags); - } - - if (IS_ERR(desc)) { - dev_dbg(consumer, "No GPIO consumer %s found\n", con_id); - return desc; - } - /* - * If a connection label was passed use that, else attempt to use - * the device name as label + * scoped_guard() is implemented as a for loop, meaning static + * analyzers will complain about these two not being initialized. */ - ret =3D gpiod_request(desc, label); + struct gpio_desc *desc =3D NULL; + int ret =3D 0; + + scoped_guard(srcu, &gpio_devices_srcu) { + desc =3D gpiod_find_by_fwnode(fwnode, consumer, con_id, idx, + &flags, &lookupflags); + if (gpiod_not_found(desc) && platform_lookup_allowed) { + /* + * Either we are not using DT or ACPI, or their lookup + * did not return a result. In that case, use platform + * lookup as a fallback. + */ + dev_dbg(consumer, + "using lookup tables for GPIO lookup\n"); + desc =3D gpiod_find(consumer, con_id, idx, &lookupflags); + } + + if (IS_ERR(desc)) { + dev_dbg(consumer, "No GPIO consumer %s found\n", + con_id); + return desc; + } + + /* + * If a connection label was passed use that, else attempt to use + * the device name as label + */ + ret =3D gpiod_request(desc, label); + } if (ret) { if (!(ret =3D=3D -EBUSY && flags & GPIOD_FLAGS_BIT_NONEXCLUSIVE)) return ERR_PTR(ret); @@ -4727,35 +4741,33 @@ static void gpiolib_dbg_show(struct seq_file *s, st= ruct gpio_device *gdev) =20 static void *gpiolib_seq_start(struct seq_file *s, loff_t *pos) { - unsigned long flags; struct gpio_device *gdev =3D NULL; loff_t index =3D *pos; =20 s->private =3D ""; =20 - spin_lock_irqsave(&gpio_lock, flags); - list_for_each_entry(gdev, &gpio_devices, list) - if (index-- =3D=3D 0) { - spin_unlock_irqrestore(&gpio_lock, flags); + guard(srcu)(&gpio_devices_srcu); + + list_for_each_entry(gdev, &gpio_devices, list) { + if (index-- =3D=3D 0) return gdev; - } - spin_unlock_irqrestore(&gpio_lock, flags); + } =20 return NULL; } =20 static void *gpiolib_seq_next(struct seq_file *s, void *v, loff_t *pos) { - unsigned long flags; struct gpio_device *gdev =3D v; void *ret =3D NULL; =20 - spin_lock_irqsave(&gpio_lock, flags); - if (list_is_last(&gdev->list, &gpio_devices)) - ret =3D NULL; - else - ret =3D list_first_entry(&gdev->list, struct gpio_device, list); - spin_unlock_irqrestore(&gpio_lock, flags); + scoped_guard(srcu, &gpio_devices_srcu) { + if (list_is_last(&gdev->list, &gpio_devices)) + ret =3D NULL; + else + ret =3D list_first_entry(&gdev->list, struct gpio_device, + list); + } =20 s->private =3D "\n"; ++*pos; --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E3F012B8A for ; Mon, 5 Feb 2024 09:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125671; cv=none; b=BQo44hipfdSvd3eWMEFaFmGxHsxgx3RUol+Ghr4wnuMV87rY5wTtsaHdYuqXaLHi4ET2gue732JFGrEevOw0gPG4zG5zXL6eov78n3A6FB5X9zjOQPnbJAbWJ9NMKwa5McB5dcRhNARA6gGAzWD7bxyOMUo2E7LAbhnR2X2eCXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125671; c=relaxed/simple; bh=w9OTZVARMR4Mdnl0o0yhVNJkoS2c5kOcFylZbMhF7Oo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lpGkxsC7tKEyNVCc2HJ4VBBNMFOo9Lvo3QIh6rjhuxAzxPFdFldKDUxnSrR6fqxqJTUXKT5vIEYyQ49viKOUrlzXx8JzM1+CLozC7qIk73jHznj3sPc1e3tV+WGXCbYeofuJzVRZBtiMGvrzXQWmkUDGfijqSc91gv1Jm1fYu3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=Hve7TEUn; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="Hve7TEUn" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-40fc65783aeso25373165e9.2 for ; Mon, 05 Feb 2024 01:34:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125667; x=1707730467; darn=vger.kernel.org; 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=mCe01XgCpcinR2htLJWjY1RLrdRFN2p3/+OpFVj9aQM=; b=Hve7TEUn3MCqrdR7JXdEyuYo2XMGXSIvIlZ3buFYvmDsjzlT4dT5PgKTr7PmY2P2JH tp2bsA7Ih1g0u0B3M0V/hL20E6AFT5olkivyqRw7llPf71cuemaQuwwrfojcs8pEP6ow j2yZ2RGos/QQMckJsbbbB86EIVAXw7xBzeSDYcOx0KlIfWhqYX8BRKXDr9xbivhfM0dJ ZMhdOYCz3O/4zc5PtbSmSFhmNBCZzWc74X+RsEfP5FPFxHMbnRPZPSgyGoBI3Q1Rxp2g IJlJcr1YulUVDhCRMxOlTmYPyKPF0+/l4yESc74/EUbe+cZD/ip2eTAX/7j8o/pXMI1f Y+TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125667; x=1707730467; 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=mCe01XgCpcinR2htLJWjY1RLrdRFN2p3/+OpFVj9aQM=; b=psKRdzyI6jefeJ8WqmKrwcl4Gow6AwwO71Zt8SXuYnZl/DoJiLXaW9B3eR9jkRHt5J kR2f3TMw8dSz8WhPDVmsJJW3qnQjUSM2oJXfw00KDtdSYqDb12WjnMqGKLwT4jEetKoB LHEWCh8RPYvJAh+BsmiQerF7MBH2O70/5jTNk1so9JMqWNfGuPwZX4lEaEbRE3X3OfAx g4eeuQqr16pSMUP9uuyYh+6rUehBtUfFkZPwYREht7lw69rTkVoajii/f6WIOWWrl1wW S0NT4iHl+5nHUPOVoswim3Db4F/7Fa3QDwUrzHWP0matzLsKFs+cB+Gghd7OQyZZTnXP 6UmQ== X-Gm-Message-State: AOJu0Yxo6SRkpcLQX3gXIkhUIGj3e5AKG5ZGImM16343CzEKVOFhBFLh PbZKZaAkgUyzUDKN5ZrSI6qKvHgyUB/o7eK4rxJS8D5KXG6PitPO9G3zBpKi/ZY= X-Google-Smtp-Source: AGHT+IEL3J9p5BXWGBPz7AI47HRJRAqQdPPdU85CEgl2ZpCxmqbm2bH4OibqUJ9q4vkgL1ejZSG1uQ== X-Received: by 2002:a05:600c:1c06:b0:40f:b630:a9cb with SMTP id j6-20020a05600c1c0600b0040fb630a9cbmr4101104wms.6.1707125667557; Mon, 05 Feb 2024 01:34:27 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXxt3LeBVGvnr1P5pPQb4AEa9+llY3je+7jtCjmRAYyLAZngAs/Xcd+Umcj1bz4tdnQ/lTJcXe/qcu7VCvfQ9Vf+884tRivPpIA5/efCz3hMMp4qqTn/Aw+ALXxQhvEmaXvseYnn6EAhRHucSmg3ltSb+J1T3hJ8p9SGAXuLLh2nfCQWDT8Z+ftk096wh/wtd3nxqYaavK4GtiRPIV/fNsXpVV07A/t7R/WD5NjN6u1CyxCnkSBcgKVp1Kg83drGbbDbypO9McRBjJPb4XfgZUUSZwEjXFdh3CYRQnQ4qy99/O0ajhg8D0fnHAOLaL0LU4ycgoKQdgyWyX/3+to3ggmSbJHr92LCw== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:26 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 02/23] gpio: of: assign and read the hog pointer atomically Date: Mon, 5 Feb 2024 10:33:57 +0100 Message-Id: <20240205093418.39755-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski The device nodes representing GPIO hogs cannot be deleted without unregistering the GPIO chip so there's no need to serialize their access. However we must ensure that users can get the right address so write and read it atomically. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-of.c | 4 ++-- drivers/gpio/gpiolib.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 77509aa19900..bd6b8702c790 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -800,7 +800,7 @@ static int of_gpiochip_add_hog(struct gpio_chip *chip, = struct device_node *hog) return ret; =20 #ifdef CONFIG_OF_DYNAMIC - desc->hog =3D hog; + WRITE_ONCE(desc->hog, hog); #endif } =20 @@ -848,7 +848,7 @@ static void of_gpiochip_remove_hog(struct gpio_chip *ch= ip, struct gpio_desc *desc; =20 for_each_gpio_desc_with_flag(chip, desc, FLAG_IS_HOGGED) - if (desc->hog =3D=3D hog) + if (READ_ONCE(desc->hog) =3D=3D hog) gpiochip_free_own_desc(desc); } =20 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index a14eef93ead8..4c18b693d06c 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2324,7 +2324,7 @@ static bool gpiod_free_commit(struct gpio_desc *desc) clear_bit(FLAG_EDGE_FALLING, &desc->flags); clear_bit(FLAG_IS_HOGGED, &desc->flags); #ifdef CONFIG_OF_DYNAMIC - desc->hog =3D NULL; + WRITE_ONCE(desc->hog, NULL); #endif ret =3D true; } --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E21B12B7A for ; Mon, 5 Feb 2024 09:34:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125671; cv=none; b=FjJ7wlTFA72zK+rbHpoTAL5pgb3vmVYXZld3XRXyZ0U0j13sHrbx7C2EPOuMwW0cis1PZ3lP8ekYRXtiEiHS39JJD6DeCPTaG1/LTD8MdwOAY2u0qErzQ4YVegmX1hBL51Cs95DhXV/OUW9lAQlBhbLHdYRBkAWkHWJ37VZuQ2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125671; c=relaxed/simple; bh=wKoekw2eVVFcj9oxq6vzdf2ok15iXRtTtNq2jliv4lA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tolKB4g3D0l9nT64Eu4bdUTwkINqR4YZ9D9olvykeZMd1YPf6cdOf5LZV4uz9EPrAwq37jc1kJt4y45qr1/NJVeGLS3Ka6LSsTILn7/FrzjDnrRl9RrlPgqbm0a/3DuynJEzalwA9zZPjsQdhk9KdagSyta0+WziNpR/UxlMbRs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=RVuSZXDU; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="RVuSZXDU" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-40fc549ab9bso25502815e9.0 for ; Mon, 05 Feb 2024 01:34:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125668; x=1707730468; darn=vger.kernel.org; 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=ZZDQVAK/m+EwHZp2HJIrHIBUSEbpzq9pOlgL2Kpkkjg=; b=RVuSZXDU1PPPz0u88nlb5x4+Ori5uy8kod2URqu0ndVD0AKG32/31hpR+Pvp/gc3b9 opVFI3FwfHGnVS2rk1TrPdYId4493uyRFx2V3pymUrV/9WPhPaTgeRPeFlp1GhDhFXif 6hfC5uL9+jo0HXqN6YntjPPC3fU166Ur4ddE2TTwZ13eUz+ivZ+r0FzO7f85bcLi51D0 xTPZ6qVdzEince491l5iGgp4Vt9uQrbXOwdYLCwqIKPaI5LykkTvG41rVmAwwFhyLkn7 WacRFnHgX3iPN8eMqF6ooKIkR3GjB4OrbakdAxYLBnvqhGEZJhkvcti+ZOGf8nOuTnsz mYTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125668; x=1707730468; 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=ZZDQVAK/m+EwHZp2HJIrHIBUSEbpzq9pOlgL2Kpkkjg=; b=pKgEBuS6cBrSszSXnmwvh41Sx+xlzMLgrOXhfbCtL28Mr+iSG+0ZKec2+NJl6sMRQX fu7daq64nXzJyB1PBrMhoc8gpOcIo8tI9M6W3ZtSNEW3VBKzNwMxUN1AKxYmnwJf4TsF BZ+H5/0SiJxRmdQ8cRgrKbAW3d7MINQ8ipWV7gAOZ0r9pyEdxs7XwCPvR2eCpLLKX6MK RTpWOHz8AocAL4uWG7H3ttidESNsNq5dl3P6SAUc6OJ0UQVhKnOh82hTMJAa3/4VVDI/ v7C1ns22QOOisPsuOkK6EXic53oAYTNKV2H38JnI2LjLEC/8h5fOvDGUASFFlJiNcmyh os7g== X-Gm-Message-State: AOJu0YxRB6I87jfJw1Yo1ZCggExbntKuAW5JWRrv2Jnys5GxYMwEugZS hIl6zcpqru8061wwckjklPHFaj/D2Kxo5/g6awgd5ns+8asOxBCv3yvFjObPnQc/PO9I/w7gDYy Y X-Google-Smtp-Source: AGHT+IGOzddUhMQZJ0PD2K9+76g0yiZag3OnprMbiqKxoQPCFOLRGilGiVvAOxPHQD+R4ETWI4CyHQ== X-Received: by 2002:a05:600c:a01:b0:40f:c1f9:c884 with SMTP id z1-20020a05600c0a0100b0040fc1f9c884mr4142575wmp.39.1707125668491; Mon, 05 Feb 2024 01:34:28 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUm83IhfTyQ7y6ls6Z3lT+Xx58RcKqxvlQep2ldxlrwxsmT6NcjogMnkVoMyYiXpWnpXWVIeKQtwOrmmrndaMAqI5KG9I60lg++7fcDO3ZPAQtwB/f2qKxHFMp0HkGXLedguNBPIg9CgET6gFQkgOEtAdQyYdY40lzTOYSeuOSfs/TkjOj2V0B1oloOCsHFU9z+cI8EgYAjCt1kBBVBqrpLZr8g/scnZo6DE9UR4/jE+/+Qvy50gfaRgAa57BMfsB5lFKBORni4uhRb7XTe46mfdX0t/Es7DCy64o5WBJFoIew/LJv4F2Y4AGKITDNSsozpyl6QecaDvfaJiMIFf8Yf7T81pzJ8bw== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:28 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 03/23] gpio: remove unused logging helpers Date: Mon, 5 Feb 2024 10:33:58 +0100 Message-Id: <20240205093418.39755-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski The general rule of the kernel is to not provide symbols that have no users upstream. Let's remove logging helpers that are not used anywhere. This will save us work later when we'll be modifying them to use the upcoming SRCU infrastructure. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.h | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index a4a2520b5f31..c3ae5bfa3f2e 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -219,31 +219,18 @@ static inline int gpio_chip_hwgpio(const struct gpio_= desc *desc) =20 /* With descriptor prefix */ =20 -#define gpiod_emerg(desc, fmt, ...) \ - pr_emerg("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\ - ##__VA_ARGS__) -#define gpiod_crit(desc, fmt, ...) \ - pr_crit("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ - ##__VA_ARGS__) #define gpiod_err(desc, fmt, ...) \ pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ ##__VA_ARGS__) #define gpiod_warn(desc, fmt, ...) \ pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ ##__VA_ARGS__) -#define gpiod_info(desc, fmt, ...) \ - pr_info("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ - ##__VA_ARGS__) #define gpiod_dbg(desc, fmt, ...) \ pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\ ##__VA_ARGS__) =20 /* With chip prefix */ =20 -#define chip_emerg(gc, fmt, ...) \ - dev_emerg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) -#define chip_crit(gc, fmt, ...) \ - dev_crit(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) #define chip_err(gc, fmt, ...) \ dev_err(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) #define chip_warn(gc, fmt, ...) \ --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AFDA12E51 for ; Mon, 5 Feb 2024 09:34:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125672; cv=none; b=T8yOOJmzSuS3loVlb+XC1EoP+UnWeJXZJWvS6789HQbn2wcnKjh2kuHXIkNMREkgxucNkqlUeNRngmPoIIf3Jc2uL7tMKLInf2g5REuuu/rBqg02jE5kkNGPFbSP0LdP6pRTyryYQU17XvWQf9zumFyZ32hgKqT2HTEP71VuH3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125672; c=relaxed/simple; bh=rvDmiJvoOjsEAG1Ifqh4V4UhyPYg6qZuDJ20zQ/Khlg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ep9/532DMUf7mYPHA8v2OIC0PwWVWmiNf0VYIN/5WAH7SEl1L6cIjTyXGBjBvSls8tYN6WjQ+YmyNmtAinZa5+0jgDaNeBsIjT/ANedThBsJutUwexjMJ1mv/UIK/lmX53ox/ZK/+2Kzgx1cUJPKLW9gLtnWi2h6+FFRgkYVrHw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=lw5MOHFe; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="lw5MOHFe" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-33b29b5ea96so929064f8f.0 for ; Mon, 05 Feb 2024 01:34:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125669; x=1707730469; darn=vger.kernel.org; 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=ggk/HS4V+gdB4Ghsw/F6Qu63h8wKplBC7+YEgEKvm/I=; b=lw5MOHFe8DfzKx2vttTyd4yHtivqVHI/wtoGHeHt5J7vTRC3sYrZzviPf1HrqARmgD xQSkKqKjjnm+3cP63K7x7DRBxapvqLVP0/OMavRCOHlz8guTZO+4YDENwr6jGzlSBHRk +7tfSmiIBOxxZtYeLnutc9Y2WndHGL2eFOsrHeCx92zBiL6g+uWTWX3xaMafAqMjm/k9 dbNZano0JMJRp5Ox+F7OkcSsgsXv7AYgCrxBn7Efa4hAU0I5pJpO+c8Db1tzDMG4wA44 q/+sqIMjObQyezTG8NMcQVnw4sOuSGTqkVi/z3ZfRSuakqgXORGU/qYfisPBNmv369j3 NH+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125669; x=1707730469; 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=ggk/HS4V+gdB4Ghsw/F6Qu63h8wKplBC7+YEgEKvm/I=; b=DQWe3iXd++EQedFzZ9OFnMDz7Ke79Gd0Y5y6NgWT4NJ/P7fUw1ZTnlYTBq8Ukcm+Y9 CxzjTIvfjN53qA7UmqeFCSBuDxaz0nVuqzqr/GC4jtPLuapT86RKeGnZR8J8plF3MU/p nG/doDCraUAevWPB5bBk0suMpy6ekk64XXVcxLahhdLUE7W5w8Ok/Os44Iu1zyeCw+UF ue/AFjSr9SQRUP0uyRl7EIDbkcrQNMpgurbWyDQnNbMlSWu3U8yD23uYmUnc4dcXcold 3TGhJte6AHo0OLKZZ17in37kJOb4AOtVGWHlgJwpbAbZ2yn/uFZ68Yb4eZAggnefAUKX 9Lxw== X-Gm-Message-State: AOJu0YxM2+LB5QTdNiG7LnoPdq7H/YoMNhu6wkWXo69ts7LFPfaNslsB RYH7mTMzc0LY2P1ods6YXS478sDYgpLIfj91dn1FZBk1wbPenbQ4hKOqoo9wMLI= X-Google-Smtp-Source: AGHT+IGmV+7oO3tTihglftOvAY9ys2JC0HqwERsmzJ5U7qwgZaAkLeRUyf/il5ao0F9eBGp+iUhtKA== X-Received: by 2002:adf:db44:0:b0:337:d84c:1d6 with SMTP id f4-20020adfdb44000000b00337d84c01d6mr3723241wrj.18.1707125669370; Mon, 05 Feb 2024 01:34:29 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUwWtApFLfLTngT2lkUY8xlP8ZuNiah9r0wTDnJOYT7AjyUHSkQKKGQ/LAQz4/cydeGnZShFBn1MrvvPVo/PkEc/nACNX+IyRUnM6M6nnXnwZ5cLfLN9WuOwBvoZIQ8jVjIRsfP4LjMT9bEHv5eGfFCyvaqi2HLcKfSKh30/U8qIZGz652uPwvvV5NnrCwmS86MRCJlRPMWEzxmid9j6frzRqQglH9W+JAnkZ62dFIMHeHpTYmsJitoD+KMtC0WfZ3L52/QzmDYeIpiX6dbbdG5xCY/HxtiuaEoOi3IGQTnUW4FWAEQKJ9N3pVajdFRfKjOEuBNYk5MEiZqc1Qju124+XnPndyvkQ== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:28 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 04/23] gpio: provide and use gpiod_get_label() Date: Mon, 5 Feb 2024 10:33:59 +0100 Message-Id: <20240205093418.39755-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski We will soon serialize access to the descriptor label using SRCU. The write-side of the protection will require calling synchronize_srcu() which must not be called from atomic context. We have two irq helpers: gpiochip_lock_as_irq() and gpiochip_unlock_as_irq() that set the label if the GPIO is not requested but is being used as interrupt. They are called with a spinlock held from the interrupt subsystem. They must not do it if we are to use SRCU so instead let's move the special corner case to a dedicated getter. First: let's implement and use the getter where it's applicable. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 4 ++-- drivers/gpio/gpiolib.c | 9 +++++++-- drivers/gpio/gpiolib.h | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 34d6712fa07c..2c0a0700762d 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2305,8 +2305,8 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *d= esc, if (desc->name) strscpy(info->name, desc->name, sizeof(info->name)); =20 - if (desc->label) - strscpy(info->consumer, desc->label, + if (gpiod_get_label(desc)) + strscpy(info->consumer, gpiod_get_label(desc), sizeof(info->consumer)); =20 dflags =3D READ_ONCE(desc->flags); diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 4c18b693d06c..cfd311ec5dda 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -105,6 +105,11 @@ static void gpiochip_irqchip_free_valid_mask(struct gp= io_chip *gc); =20 static bool gpiolib_initialized; =20 +const char *gpiod_get_label(struct gpio_desc *desc) +{ + return desc->label; +} + static inline void desc_set_label(struct gpio_desc *d, const char *label) { d->label =3D label; @@ -2385,7 +2390,7 @@ char *gpiochip_dup_line_label(struct gpio_chip *gc, u= nsigned int offset) * * Until this happens, this allocation needs to be atomic. */ - label =3D kstrdup(desc->label, GFP_ATOMIC); + label =3D kstrdup(gpiod_get_label(desc), GFP_ATOMIC); if (!label) return ERR_PTR(-ENOMEM); =20 @@ -4726,7 +4731,7 @@ static void gpiolib_dbg_show(struct seq_file *s, stru= ct gpio_device *gdev) is_irq =3D test_bit(FLAG_USED_AS_IRQ, &desc->flags); active_low =3D test_bit(FLAG_ACTIVE_LOW, &desc->flags); seq_printf(s, " gpio-%-3d (%-20.20s|%-20.20s) %s %s %s%s\n", - gpio, desc->name ?: "", desc->label, + gpio, desc->name ?: "", gpiod_get_label(desc), is_out ? "out" : "in ", value >=3D 0 ? (value ? "hi" : "lo") : "? ", is_irq ? "IRQ " : "", diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index c3ae5bfa3f2e..1058f326fe2b 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -208,6 +208,7 @@ int gpio_set_debounce_timeout(struct gpio_desc *desc, u= nsigned int debounce); int gpiod_hog(struct gpio_desc *desc, const char *name, unsigned long lflags, enum gpiod_flags dflags); int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev); +const char *gpiod_get_label(struct gpio_desc *desc); =20 /* * Return the GPIO number of the passed descriptor relative to its chip --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23B3D134A9 for ; Mon, 5 Feb 2024 09:34:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125673; cv=none; b=n87fU5y42ATY7EwH1xkmh5scZOf6Lq89DMuT7ofyCBLveeV7M/HUDvz27xEnj2xWJszK3R1h8LjpoSFBUcSdTfl7104uiRepvQ2FBUG4HsKYkAiSkhp3JzhnNOjj9QyCn2wOKC7kCo3Ek1wlyvCcdYfFNOu4JUwMBchvYlXw8E8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125673; c=relaxed/simple; bh=L91BBpikBkHqwcQ57UiFh0/5/PsxnAo8v9+gu/rUrOM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eQtuqQ22gz99Sc6jXKz6LFBrCZKKXouasw1F3krwChESNuslYAFf5b2/ij199/vwT242w8Kdqffkf+47b4sbWnE+kVLGlSMiVBJNjLiNBSJdyGQLd5s6rwihoZSEuuy2Jk2Y3Bg9/dLpQfBw2Od/JFVAiStVP7HjDFZpZ83p8eY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=EvMogXAG; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="EvMogXAG" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-51124d86022so6489913e87.0 for ; Mon, 05 Feb 2024 01:34:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125670; x=1707730470; darn=vger.kernel.org; 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=RSEnfVuvu8Q/tNHp1neFQSbtxw3POuiVtvIa5az8diw=; b=EvMogXAGlsh8KWLG0umTfCX7vtaABlzwJdWaKMsuxtbJoYfEfi1kL8vzQxMo9Li1nl JHEnXPvxJgm2c5W3FrtYOHuvi97i5zs2r9VyhhIBgB/KUfwIBznnq2TRy+SW9sIa7I7X 4O7qkHbIjkja9QZ4/f7gCvE5/ZEw8LTuS/oZShaSqRWe2B/7xDUqYNTGCfOEfE3gPs26 EXTpBv2CKYdJZsrupiz1oakh8SQ/9/carta/uD37Om4SNhdrj5O/N8bszHRw7qsnG/MM 5nK6Sw7lBhWtXPpvAN8xJVyNdhbdw6UCS6fI3Mry+n+WgBGS8Ke2wLNgxhjHRXHeJeCS an1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125670; x=1707730470; 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=RSEnfVuvu8Q/tNHp1neFQSbtxw3POuiVtvIa5az8diw=; b=BXwA1XUKvIABiVEbGpzNBugscSdfEXjBIF+B/Yko5SlCU9IP+2wr8ctn++kggFoOlQ 2nSvc00uOXTrCNrW2ft8BvPhX9UNKHJhsTikmzjOPuffmzVxG9Dt2/jJEFtHpBFHAiIp KDNY54aw+tfQFXWrsq3Wrtnt9k/qljTFW384wcn5B60mu6g+OkM8KAFYNMemhcYS7YWk Rd+isTJSKcHn1qlmxwrUsRUvma1qWbANIs48q/a0yMjXNiE5bAgisdYpEAXSGU9CJt3N OiOzgaRmTq9IMoRK+NtTBM9y8hH6FIwunP/EPoJKEz8nrcTIYM2yV5+2RDrntbmngjpF sICw== X-Gm-Message-State: AOJu0Yw0BECwhBefPCHBf3ESsX/YV5F/borz6HkaVuVXLpKQDVfdLU5Y Th6KEidn7wPwfiJmwlGoCycaFh/qNw0zkzg4F8gYImp9QlVIYH+67oFkyzoStiM= X-Google-Smtp-Source: AGHT+IEcPafTTkHgGkgn+DFvdWRnWTQwe2o6OEptnHsezn9spoJf9YLIqVdfi0Crff3zOVppi25yBQ== X-Received: by 2002:a19:f711:0:b0:511:51af:7548 with SMTP id z17-20020a19f711000000b0051151af7548mr1026924lfe.9.1707125670191; Mon, 05 Feb 2024 01:34:30 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXobqsD3Uis6hLjobTZp6XBfCqM+9f4VYj5owOVxKdXHlS2gCu1PCPgofYK23757bJ/XK2ElC26nPRA4h4YtVC/gdKQ4wq4XOjIOmbTYckFQlDJOqPc6AsLuLziM8+0Qyio6nOZmt8AyTrQuDJ+EJfop1t007ahMAjUqU+0A9qQ3eREHCs9wSMC3KjHXY0TEGrQlG9f6P3CakEMHWrkvp0gv9rO0NFnYOjqOkep+YgX9qCyiwo8Bxsf6PzudPDrsZ+MrNRJho9xwCRjRDokEx9AHlLZ42c+XoqwEem2lZAO+yd4LRCowmQWbAnvrsWp/7n1976/gdhfl9QqNOnLRGwgblsF8s3yYg== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:29 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 05/23] gpio: don't set label from irq helpers Date: Mon, 5 Feb 2024 10:34:00 +0100 Message-Id: <20240205093418.39755-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski We will soon serialize access to the descriptor label using SRCU. The write-side of the protection will require calling synchronize_srcu() which must not be called from atomic context. We have two irq helpers: gpiochip_lock_as_irq() and gpiochip_unlock_as_irq() that set the label if the GPIO is not requested but is being used as interrupt. They are called with a spinlock held from the interrupt subsystem. They must not do it if we are to use SRCU so instead let's move the special corner case to a dedicated getter. Don't actually set the label to "interrupt" in the above case but rather use the newly added gpiod_get_label() helper to hide the logic that atomically checks the descriptor flags and returns the address of a static "interrupt" string. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index cfd311ec5dda..5c041d57077b 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -107,7 +107,14 @@ static bool gpiolib_initialized; =20 const char *gpiod_get_label(struct gpio_desc *desc) { - return desc->label; + unsigned long flags; + + flags =3D READ_ONCE(desc->flags); + if (test_bit(FLAG_USED_AS_IRQ, &flags) && + !test_bit(FLAG_REQUESTED, &flags)) + return "interrupt"; + + return test_bit(FLAG_REQUESTED, &flags) ? desc->label : NULL; } =20 static inline void desc_set_label(struct gpio_desc *d, const char *label) @@ -3593,14 +3600,6 @@ int gpiochip_lock_as_irq(struct gpio_chip *gc, unsig= ned int offset) set_bit(FLAG_USED_AS_IRQ, &desc->flags); set_bit(FLAG_IRQ_IS_ENABLED, &desc->flags); =20 - /* - * If the consumer has not set up a label (such as when the - * IRQ is referenced from .to_irq()) we set up a label here - * so it is clear this is used as an interrupt. - */ - if (!desc->label) - desc_set_label(desc, "interrupt"); - return 0; } EXPORT_SYMBOL_GPL(gpiochip_lock_as_irq); @@ -3623,10 +3622,6 @@ void gpiochip_unlock_as_irq(struct gpio_chip *gc, un= signed int offset) =20 clear_bit(FLAG_USED_AS_IRQ, &desc->flags); clear_bit(FLAG_IRQ_IS_ENABLED, &desc->flags); - - /* If we only had this marking, erase it */ - if (desc->label && !strcmp(desc->label, "interrupt")) - desc_set_label(desc, NULL); } EXPORT_SYMBOL_GPL(gpiochip_unlock_as_irq); =20 --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5A14134C1 for ; Mon, 5 Feb 2024 09:34:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125674; cv=none; b=pXDIhZevBf5ObPsJxsI1y5qkkUu/vJjy+8zn/T/nqTiSyKwFk32ODjHnbfUJl/20b/fPYNPoQu0bf7m7zn/qncNSCCU+BBZkpqLMdoHUIIRoqPoVHab6ETJzJU0BVzfkSlY639kNydkXtVJMyDGP1O88cAG65OutoC6UoMTfzAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125674; c=relaxed/simple; bh=YfUs17R8IhDrlEqhEZxI5M9W373vGN2Q0/ixlOWEz9Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aOqZRfyz0vX9FS1lQDYb3+ZlqfKJdSfg/xWRxCKVQiXEfsil/oCwCTOAMgea1B5Hum7IIp5UKVfGprY1VP4ZDG3iKBAZq40C5oJBm4zHEDAGPK6uNDfi0YycZkYAIOv+Z/4iNVA7ze6P5BXJTDy1FhTaJ5/yMqZWuYVznbxWBOE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=RGGg8q89; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="RGGg8q89" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-40fdb18ffc7so6529535e9.1 for ; Mon, 05 Feb 2024 01:34:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125671; x=1707730471; darn=vger.kernel.org; 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=zpsQDT+5nWCXpBfKiz7J0RVwkAnu4buv5U2Z10kutak=; b=RGGg8q89OytlDemlxtnZ+lVkD8YTSn9byWWMiUr1VU2rShjXSvdsyt3r9hnTa4J+TV yl+ssFKmXnXokYmumyMaopS+8GmTd3BhBkasjxscjNFSQNVNQHUjNExUCxvmj3j4c9n4 5Dhzv1d6FbVcJGhXz+0Er1p3d2po4UFg9PV+jxV1AQKPxDT7AuU3QdpVvE/0ltuiLGo3 5KwpJLp5cKB3uDN1D84RoFGf21VSAhjYwu0/svu5pIFM+K4BM/onzzdtn5c1AJ+ldug3 zT67NdQNojnzYtvEVYcjagN9AlAqrKhTEwPx5Pu0J/EPNUtIVc/9n/XWRTaLZni76at7 2DnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125671; x=1707730471; 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=zpsQDT+5nWCXpBfKiz7J0RVwkAnu4buv5U2Z10kutak=; b=LxYZtI78AJew3E5NnlRJKDANrsBMuQA9Ogyk4PnQMENsG4GYASpzqN0bnM9SLagXRi OD08lbNFO3Y8StJRZ7192XByMpLmJeNTReqg2zcNT+nsZADsphZl86yVwuRv7iplQ/6N OAcrvjnjUzvCIQkDGX2yHi7533qQz+kpet7Ez2KSUAYf496diMt/y7c1aJC2keVKdCUP 0mkTrSxsZ5kLkZM7QW2HmsruvxhzFRp1yNkjxiUyKV4RnZxABRyBh/Fk/i5A37H8nFNP XmP/mASAo5Y55qHVgwiFyS5L5iBDjLz+6oWIv2L1filtJBFAsT4IBo/U3rI/mnTSV4UH O2mw== X-Gm-Message-State: AOJu0YwfICa5z7TOKtOQO0dLhlf0r703nsKIBCjJtJN8iQwDHo0bA9QC Vbu1GWJc542yXJJbbNWPb1cjTDVYaXx/6n31/srjUzS5c3j1WMFxB8yePlw8ufE= X-Google-Smtp-Source: AGHT+IFyKoc6eaHqWsITQ4+Ew7YxpHQC8SW/NhaAAtC3PI9fpag+n2maplobnK/D3irrszBWC8OO6g== X-Received: by 2002:a05:600c:4f91:b0:40f:b680:3e84 with SMTP id n17-20020a05600c4f9100b0040fb6803e84mr4720748wmq.2.1707125671145; Mon, 05 Feb 2024 01:34:31 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCV5ryJJgj3e8xjpQT65Nhl+E4gf4Nj+r4X4IFAL4AEZ/lGUwSZ0u+qFf/rPXMFox5a2kwQQv2on5DmzAoN3wu4NWApqIt10a2UOSYEtgwzO2EnTFT5lsh0vmX1j2WdXH+aTpbLYXOcM0DakgeJMcdQprv+MrtnPuP871RkNCO2+7vLEjXhAtZMnLeeIt0IxYYHmsdlwJegB06/90U9myiaXQIj7QROYhugqt62IyRIeaYcPnXEWA5HXmsw99ndaQhJ6afbJtYHIzsJhcucnfJba8IZ+7dYUIXo6ZNY1dZAcjGN1UyjBzUrCTXaD15G+AOEdCjqE2kMJNGpS6Qfp+8uVwaAc45ld6w== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:30 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 06/23] gpio: add SRCU infrastructure to struct gpio_desc Date: Mon, 5 Feb 2024 10:34:01 +0100 Message-Id: <20240205093418.39755-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski Extend the GPIO descriptor with an SRCU structure in order to serialize the access to the label. Initialize and clean it up where applicable. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 18 ++++++++++++++++-- drivers/gpio/gpiolib.h | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 5c041d57077b..ea0c0158faaf 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -672,6 +672,10 @@ EXPORT_SYMBOL_GPL(gpiochip_line_is_valid); static void gpiodev_release(struct device *dev) { struct gpio_device *gdev =3D to_gpio_device(dev); + unsigned int i; + + for (i =3D 0; i < gdev->ngpio; i++) + cleanup_srcu_struct(&gdev->descs[i].srcu); =20 ida_free(&gpio_ida, gdev->id); kfree_const(gdev->label); @@ -832,7 +836,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, vo= id *data, struct lock_class_key *request_key) { struct gpio_device *gdev; - unsigned int i; + unsigned int i, j; int base =3D 0; int ret =3D 0; =20 @@ -965,6 +969,13 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, v= oid *data, for (i =3D 0; i < gc->ngpio; i++) { struct gpio_desc *desc =3D &gdev->descs[i]; =20 + ret =3D init_srcu_struct(&desc->srcu); + if (ret) { + for (j =3D 0; j < i; j++) + cleanup_srcu_struct(&desc->srcu); + goto err_remove_of_chip; + } + if (gc->get_direction && gpiochip_line_is_valid(gc, i)) { assign_bit(FLAG_IS_OUT, &desc->flags, !gc->get_direction(gc, i)); @@ -976,7 +987,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, vo= id *data, =20 ret =3D gpiochip_add_pin_ranges(gc); if (ret) - goto err_remove_of_chip; + goto err_cleanup_desc_srcu; =20 acpi_gpiochip_add(gc); =20 @@ -1015,6 +1026,9 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, = void *data, gpiochip_irqchip_free_valid_mask(gc); err_remove_acpi_chip: acpi_gpiochip_remove(gc); +err_cleanup_desc_srcu: + for (i =3D 0; i < gdev->ngpio; i++) + cleanup_srcu_struct(&gdev->descs[i].srcu); err_remove_of_chip: gpiochip_free_hogs(gc); of_gpiochip_remove(gc); diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 1058f326fe2b..6e14b629c48b 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -17,6 +17,7 @@ #include #include #include +#include =20 #define GPIOCHIP_NAME "gpiochip" =20 @@ -147,6 +148,7 @@ void gpiod_line_state_notify(struct gpio_desc *desc, un= signed long action); * @label: Name of the consumer * @name: Line name * @hog: Pointer to the device node that hogs this line (if any) + * @srcu: SRCU struct protecting the label pointer. * * These are obtained using gpiod_get() and are preferable to the old * integer-based handles. @@ -184,6 +186,7 @@ struct gpio_desc { #ifdef CONFIG_OF_DYNAMIC struct device_node *hog; #endif + struct srcu_struct srcu; }; =20 #define gpiod_not_found(desc) (IS_ERR(desc) && PTR_ERR(desc) =3D=3D -ENOE= NT) --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E129013AED for ; Mon, 5 Feb 2024 09:34:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125675; cv=none; b=K1fcy/5Iwga88Ct7sZiCbNjpverqLyOt6V/dh0UcCtCc86L5IB7WVTwNh1aVtXqn5QHbu1RllFYjr0G5S04130edHHK2/ytBk1K6KObgt9IgnBWZHLASeZiYYnd+kilvsi1RnnhRtGgSStB16jaeTXm3enVacZtCtZM70itF9IA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125675; c=relaxed/simple; bh=Iu1ud2V7hAqRPw6qsJ4BEkBo20yGRwt6IVyG748uVng=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ql5yuhUqZDs1RppOskDnTE5UDbta8eX93HAE2jphG1EpRPVbXAfaoX0x/AuZ3OaLAQBCej+0p24/a2ibDTucWtZwTlShib9VlXJ4xpoM/Ai5Y5KPu41VNu+YC6Ku1m6jjrJxul5cDIUvGedKiDas5VXbLfZ3Srh5OIPETwgO3ks= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=ocrqLTly; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="ocrqLTly" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-40fdd11475aso3070225e9.0 for ; Mon, 05 Feb 2024 01:34:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125672; x=1707730472; darn=vger.kernel.org; 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=SZKu4GUN8Mdrmtq+mCLkathjFvWJwZX/fdEUwbcMDKM=; b=ocrqLTlyHem20c2HZRIZRuPnZkX6vJXs3gzTELx+5TfKM2tkfIk72hkPB8VmNDYD4m baV8GCuD35Gkiec/lfL7mMWc+1gHV9o6XJB2BUcDemFK1I/KDuLrGatrhQbsN9qDEKbz +6OJwUibzIDSf+W8EHhcVbEEq0vlR3qEcSE6Le8OYZFQ3zJ95KT2o2eAM5hi5wZ0feVq w/74MwmtJ6Dv57u+5ckJoBbbENPPztRxJJoQieVglfd2NrK/Zl3k6w2KoglMfO79T3kn HoY+WBg2TovQRVpCpJfTCwp0q76QzLmritT8014t2Qxjy5E9S9rz0fPbR+WDsd6IJsl5 YiMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125672; x=1707730472; 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=SZKu4GUN8Mdrmtq+mCLkathjFvWJwZX/fdEUwbcMDKM=; b=F+ZVn/ew1i063/wdQsde9fcGeZItLwDZrOD8h1T/XJoPDOFzbJtCCEXxyEfeqpQM4+ CKfUk1YmeU7xzBV3p4BJk6zfalLTDk26LDaHBIjqi8DxbCh5y0JV+oVcVzkhO2l4B1EY jf2KXYxWRMvg3wD7WM1geOkExfu/nWLxnPCTtfB0UpLlEc9gllbUVY9PlRbBw2x3l7mB 0FP6iqdH/UWd58/6wunfjGMyg4fGRaKSszDyPTC3e2WdHH66Lge5GCrg+TkGFpz6ExEw liGVic1UVV/ySM4WVVBwe3wgobmNifeaGKXpC5wf8dwdg0zTqU9doTfyzsxHyyCOpc18 7ikg== X-Gm-Message-State: AOJu0YxWNI8ud8/HMw7XjyKz9DTvTq3OGvy0w5cAEQ4ysPH1UPAHJra+ aM1zKjA6BnN6aW3CkUttkQJZoFMJPdUndtH07/2kAhhqkZw66HPscQOPnnb0+bc= X-Google-Smtp-Source: AGHT+IFDs25h1zo11JFYWw/lWaxEJX4khotrq6H9fGUlWGR98K+wisEz2DEBoU/sA+YMzz+RtVUYaQ== X-Received: by 2002:a05:600c:190f:b0:40f:ddc8:f801 with SMTP id j15-20020a05600c190f00b0040fddc8f801mr506301wmq.34.1707125672015; Mon, 05 Feb 2024 01:34:32 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVWF4OPWhnyYDlGIv9CoNgJBcAmGOGu4ZDCZ/I3ZjxRyQjJY6xv0cL40qoBgpJYceHqbjp7DG4VWbAQq7dcExpzxlkGQZkW04j6VWRnfm/UMGkzxEQ2b83rP+u8/z7qlIH9WkSxHHjqGkuPoPJk7sS2c6UWBtJGTctulhKyUGl4wG2PNk0InO3RiABpcHD+9T9+G/q/gA0uh+TZUfosdgkOxwKjf6JgCE7W4ENJMHlse6iRE6yY3nXpGO6Ey9bUZIKmOpaEmsxjwuqlePYcRWximBuS2hXvy5ToMcFcLjUIYINzPS/OETEA2sMm4dwPI7Pf11U0lo2YPZYt7LzmH8ZbuLoDGBb5tA== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:31 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 07/23] gpio: protect the descriptor label with SRCU Date: Mon, 5 Feb 2024 10:34:02 +0100 Message-Id: <20240205093418.39755-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski In order to ensure that the label is not freed while it's being accessed, let's protect it with SRCU and synchronize it everytime it's changed. Let's modify desc_set_label() to manage the memory used for the label as it can only be freed once synchronize_srcu() returns. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 10 +++++--- drivers/gpio/gpiolib.c | 47 +++++++++++++++++++++++-------------- drivers/gpio/gpiolib.h | 34 +++++++++++++++++++-------- 3 files changed, 61 insertions(+), 30 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 2c0a0700762d..75f4912339a6 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2297,6 +2297,7 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *d= esc, { struct gpio_chip *gc =3D desc->gdev->chip; unsigned long dflags; + const char *label; =20 memset(info, 0, sizeof(*info)); info->offset =3D gpio_chip_hwgpio(desc); @@ -2305,9 +2306,12 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *= desc, if (desc->name) strscpy(info->name, desc->name, sizeof(info->name)); =20 - if (gpiod_get_label(desc)) - strscpy(info->consumer, gpiod_get_label(desc), - sizeof(info->consumer)); + scoped_guard(srcu, &desc->srcu) { + label =3D gpiod_get_label(desc); + if (label) + strscpy(info->consumer, label, + sizeof(info->consumer)); + } =20 dflags =3D READ_ONCE(desc->flags); } diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index ea0c0158faaf..f425e0264b7e 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -114,12 +114,26 @@ const char *gpiod_get_label(struct gpio_desc *desc) !test_bit(FLAG_REQUESTED, &flags)) return "interrupt"; =20 - return test_bit(FLAG_REQUESTED, &flags) ? desc->label : NULL; + return test_bit(FLAG_REQUESTED, &flags) ? + rcu_dereference(desc->label) : NULL; } =20 -static inline void desc_set_label(struct gpio_desc *d, const char *label) +static int desc_set_label(struct gpio_desc *desc, const char *label) { - d->label =3D label; + const char *new =3D NULL, *old; + + if (label) { + /* FIXME: make this GFP_KERNEL once the spinlock is out. */ + new =3D kstrdup_const(label, GFP_ATOMIC); + if (!new) + return -ENOMEM; + } + + old =3D rcu_replace_pointer(desc->label, new, 1); + synchronize_srcu(&desc->srcu); + kfree_const(old); + + return 0; } =20 /** @@ -2223,9 +2237,7 @@ static int gpiod_request_commit(struct gpio_desc *des= c, const char *label) * before IRQs are enabled, for non-sleeping (SOC) GPIOs. */ =20 - if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) =3D=3D 0) { - desc_set_label(desc, label ? : "?"); - } else { + if (test_and_set_bit(FLAG_REQUESTED, &desc->flags)) { ret =3D -EBUSY; goto out_free_unlock; } @@ -2253,6 +2265,13 @@ static int gpiod_request_commit(struct gpio_desc *de= sc, const char *label) spin_lock_irqsave(&gpio_lock, flags); } spin_unlock_irqrestore(&gpio_lock, flags); + + ret =3D desc_set_label(desc, label ? : "?"); + if (ret) { + clear_bit(FLAG_REQUESTED, &desc->flags); + return ret; + } + return 0; =20 out_free_unlock: @@ -2337,8 +2356,6 @@ static bool gpiod_free_commit(struct gpio_desc *desc) gc->free(gc, gpio_chip_hwgpio(desc)); spin_lock_irqsave(&gpio_lock, flags); } - kfree_const(desc->label); - desc_set_label(desc, NULL); clear_bit(FLAG_ACTIVE_LOW, &desc->flags); clear_bit(FLAG_REQUESTED, &desc->flags); clear_bit(FLAG_OPEN_DRAIN, &desc->flags); @@ -2356,6 +2373,7 @@ static bool gpiod_free_commit(struct gpio_desc *desc) } =20 spin_unlock_irqrestore(&gpio_lock, flags); + desc_set_label(desc, NULL); gpiod_line_state_notify(desc, GPIOLINE_CHANGED_RELEASED); =20 return ret; @@ -2403,6 +2421,8 @@ char *gpiochip_dup_line_label(struct gpio_chip *gc, u= nsigned int offset) if (!test_bit(FLAG_REQUESTED, &desc->flags)) return NULL; =20 + guard(srcu)(&desc->srcu); + /* * FIXME: Once we mark gpiod_direction_input/output() and * gpiod_get_direction() with might_sleep(), we'll be able to protect @@ -3514,16 +3534,8 @@ EXPORT_SYMBOL_GPL(gpiod_cansleep); int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) { VALIDATE_DESC(desc); - if (name) { - name =3D kstrdup_const(name, GFP_KERNEL); - if (!name) - return -ENOMEM; - } =20 - kfree_const(desc->label); - desc_set_label(desc, name); - - return 0; + return desc_set_label(desc, name); } EXPORT_SYMBOL_GPL(gpiod_set_consumer_name); =20 @@ -4733,6 +4745,7 @@ static void gpiolib_dbg_show(struct seq_file *s, stru= ct gpio_device *gdev) int value; =20 for_each_gpio_desc(gc, desc) { + guard(srcu)(&desc->srcu); if (test_bit(FLAG_REQUESTED, &desc->flags)) { gpiod_get_direction(desc); is_out =3D test_bit(FLAG_IS_OUT, &desc->flags); diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 6e14b629c48b..d2e73eea9e92 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -180,7 +180,7 @@ struct gpio_desc { #define FLAG_EVENT_CLOCK_HTE 19 /* GPIO CDEV reports hardware timestamps = in events */ =20 /* Connection label */ - const char *label; + const char __rcu *label; /* Name of the GPIO */ const char *name; #ifdef CONFIG_OF_DYNAMIC @@ -223,15 +223,29 @@ static inline int gpio_chip_hwgpio(const struct gpio_= desc *desc) =20 /* With descriptor prefix */ =20 -#define gpiod_err(desc, fmt, ...) \ - pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ - ##__VA_ARGS__) -#define gpiod_warn(desc, fmt, ...) \ - pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ - ##__VA_ARGS__) -#define gpiod_dbg(desc, fmt, ...) \ - pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\ - ##__VA_ARGS__) +#define gpiod_err(desc, fmt, ...) \ +do { \ + scoped_guard(srcu, &desc->srcu) { \ + pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), \ + gpiod_get_label(desc) ? : "?", ##__VA_ARGS__); \ + } \ +} while (0) + +#define gpiod_warn(desc, fmt, ...) \ +do { \ + scoped_guard(srcu, &desc->srcu) { \ + pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), \ + gpiod_get_label(desc) ? : "?", ##__VA_ARGS__); \ + } \ +} while (0) + +#define gpiod_dbg(desc, fmt, ...) \ +do { \ + scoped_guard(srcu, &desc->srcu) { \ + pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), \ + gpiod_get_label(desc) ? : "?", ##__VA_ARGS__); \ + } \ +} while (0) =20 /* With chip prefix */ =20 --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E216314006 for ; Mon, 5 Feb 2024 09:34:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125676; cv=none; b=oC6TrWk02fCf+9e7kGGzaN66AUBdQ4kToZ32U6dO91mLJtgz3HRzfHiD35mmMzCIl80WAEjsaJ47bl28HgJ4xmQ/qxroBR8IJwXWMiiO+xOv8zQ8Qrz7qUqEsPMHtMyqZeRfhJn/XMQ+xidpl+loAyA1qpCVqcp7smWkoAysvUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125676; c=relaxed/simple; bh=QndNeSWqDTX/zFjnwCo02F7D/CRpA6gYSyfRPlHOvEw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qFwS8M4eeaecconQa/I3KP85znfXzS3wgXbXjHZYYKE5m0+e9dcUtv7PEs6pSZtlAPlHAE4TuTh9kQ4nZA34ZwFHHJdgdB6pBJMkvy8ZMIv+O2arvd7UUJFSFgQqTrWVVHUorSqiPFBoYgBJ5E4jifwyy6+IWHrIoUBoqLGUQbs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=RKjTqk2Z; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="RKjTqk2Z" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-51147d0abd1so1370700e87.1 for ; Mon, 05 Feb 2024 01:34:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125673; x=1707730473; darn=vger.kernel.org; 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=GkfvkjtzEhDkQSOg4G+yVVF8O3dwJMh/iXMkfAAfTgY=; b=RKjTqk2ZylDq88zxeYhB89loVrt+e0Nihxz+aoTPRicgpNW/Nq/PAsowxtWAHfCAOL +3maT8cXr9s/COgOsAOn+n++p42AXHtfvk09WtU0CyVNvAS0TU8meeDfRp/4UGtmBkqw 0r+96EsJWBBZPloV646QtKRk3F/Oyi0s0on8sdiakvWUW4WKg6dIz+YcoUVHcDp/y5Ci aqYy4vdhLiF4YqO+RsLKC7/sIqlb6wuEHtW1bGnxJ0/NNPLqUEe/CcHITbN7JGsaDtwB jKDT6SVU4lcy5ukyeqD7kUOYrLBAEEOVM7MsUAG31QPBlPCKzyv1pjSsNTUxNL4USNCE CHtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125673; x=1707730473; 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=GkfvkjtzEhDkQSOg4G+yVVF8O3dwJMh/iXMkfAAfTgY=; b=RSE/BtpS0WbR3ljcA8JVfzkbMuMlmHizP2BQsvI13Ay11FYeh2NbIHM7bX75bkKw8j tdOgUGg9gthFF/yGGudpwYdgsk2Jb2pDKZ1J44HvlBcBkZv4ylOFrJRErY2ow5t48fIV KTCNkfhoadOdPvPZII6xv60GcYNALUqrKTpQDJezHGCIXQgFttBYGbdJNrFpZg6Ys6qh twTGA8qgcSZSuk7uYSBlHBzcFSYNXRyhu+uPxVt9/a6IzRLnIfoxdIetNyePvwBCh2+d y9NMrLfO048xHm35g6yrEc23rqh3UrxaCa6IUnfvglE1/N82mmt1YMLMrpj5vkgzQKKF lLjA== X-Gm-Message-State: AOJu0Yy4CAhA8O0l4VyDgkFJ1Fofn24t4YCa68Mb16LqRt0IQOCr5m2F eImpWmQPfs7NtjNGnGhdin8TR52hN7ORDPxU44H3nUPcuWk2MUyygCjLQMYTTeY= X-Google-Smtp-Source: AGHT+IEioOygbwzOiy8IYXaqffGjI1iQJ28ymii8IJ/QHZobuyxDN4NK6zExQjLK8wD8AOwGSbQsug== X-Received: by 2002:a19:7008:0:b0:511:4f1c:ef43 with SMTP id h8-20020a197008000000b005114f1cef43mr1520317lfc.10.1707125672969; Mon, 05 Feb 2024 01:34:32 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXJv09UAJMwHDheEwlhQmtq785dpHyI9qQU6Sgt9oU0/XH58nkLzfK4Bg+uwolkHslsZJtdQtN4SCOXjNBH6ed0woHAAYAU+ld5fGgnmcxc2E1Bjgsl2aMg5IKMOmz2uhvVUwZblNOp9bfso8qZFr7LGF3fppU6zTPTdPxdcFj976hV2v4tkrSccdQNR9ej7kqvq0CnDQUVVExd0LCXkqGZwpwUPNLKTPhaQ0XW1yRn1+KvpQYICzjMU2F76H1/xZgg85QgN010/3S8yovMH2xqkHgaMlCyFTD/4ZPPYbeYAYnW/rDr6h2AWHrbDZcq9qiXA4B2dRCn4R8zmJtwkP0Dl8q6P4D77Q== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:32 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 08/23] gpio: sysfs: use gpio_device_find() to iterate over existing devices Date: Mon, 5 Feb 2024 10:34:03 +0100 Message-Id: <20240205093418.39755-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski With the list of GPIO devices now protected with SRCU we can use gpio_device_find() to traverse it from sysfs. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-sysfs.c | 41 ++++++++++++++++-------------------- drivers/gpio/gpiolib.c | 2 +- drivers/gpio/gpiolib.h | 1 - 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 6bf5332136e5..3c3b8559cff5 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -790,11 +790,24 @@ void gpiochip_sysfs_unregister(struct gpio_device *gd= ev) } } =20 +static int gpiofind_sysfs_register(struct gpio_chip *gc, void *data) +{ + struct gpio_device *gdev =3D gc->gpiodev; + int ret; + + if (gdev->mockdev) + return 0; + + ret =3D gpiochip_sysfs_register(gdev); + if (ret) + chip_err(gc, "failed to register the sysfs entry: %d\n", ret); + + return 0; +} + static int __init gpiolib_sysfs_init(void) { - int status; - unsigned long flags; - struct gpio_device *gdev; + int status; =20 status =3D class_register(&gpio_class); if (status < 0) @@ -806,26 +819,8 @@ static int __init gpiolib_sysfs_init(void) * We run before arch_initcall() so chip->dev nodes can have * registered, and so arch_initcall() can always gpiod_export(). */ - spin_lock_irqsave(&gpio_lock, flags); - list_for_each_entry(gdev, &gpio_devices, list) { - if (gdev->mockdev) - continue; + gpio_device_find(NULL, gpiofind_sysfs_register); =20 - /* - * TODO we yield gpio_lock here because - * gpiochip_sysfs_register() acquires a mutex. This is unsafe - * and needs to be fixed. - * - * Also it would be nice to use gpio_device_find() here so we - * can keep gpio_chips local to gpiolib.c, but the yield of - * gpio_lock prevents us from doing this. - */ - spin_unlock_irqrestore(&gpio_lock, flags); - status =3D gpiochip_sysfs_register(gdev); - spin_lock_irqsave(&gpio_lock, flags); - } - spin_unlock_irqrestore(&gpio_lock, flags); - - return status; + return 0; } postcore_initcall(gpiolib_sysfs_init); diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f425e0264b7e..6cfb75ee739d 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -85,7 +85,7 @@ DEFINE_SPINLOCK(gpio_lock); static DEFINE_MUTEX(gpio_lookup_lock); static LIST_HEAD(gpio_lookup_list); =20 -LIST_HEAD(gpio_devices); +static LIST_HEAD(gpio_devices); /* Protects the GPIO device list against concurrent modifications. */ static DEFINE_MUTEX(gpio_devices_lock); /* Ensures coherence during read-only accesses to the list of GPIO devices= . */ diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index d2e73eea9e92..2bf3f9e13ae4 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -136,7 +136,6 @@ int gpiod_set_array_value_complex(bool raw, bool can_sl= eep, int gpiod_set_transitory(struct gpio_desc *desc, bool transitory); =20 extern spinlock_t gpio_lock; -extern struct list_head gpio_devices; =20 void gpiod_line_state_notify(struct gpio_desc *desc, unsigned long action); =20 --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7F501428A for ; Mon, 5 Feb 2024 09:34:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125679; cv=none; b=SMK/1EtWPyCb9Vpz0iJBdVYIheD/yAOhjM2Yj/MBbyDDKWtkFaZ9HbwCuQWkA2gXALTXCRGVKetjBzxqjH1pfxYEvk9w+gMbk37kpFD/KNqjIj/f4DiwHz27XkrZ345tOomUPDhoAIRFudpTzKKPRdPs4CLCSmV6szHGSH62Aa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125679; c=relaxed/simple; bh=AZJTe9uH/HRjd3Eb1E9LViLgyCA0fSyifMWHq+z8I84=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OhIH+flde1d3IvACrj9aEdNYyeXkA1u7UjA6KisQ+LnrF3AbvnXODjvLUAQx2dxvneEiBmgoWXqU8Yr4/k38wz3V7megqXtJ0p9mLs7JVhIw5TPtByeQhoG8XiqqEQphKtq9l1OjJOOayc2gEgfIXMLt2qRVIgVjK74u9a0OPPI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=qEbT5HvP; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="qEbT5HvP" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-40fd72f721dso9536465e9.0 for ; Mon, 05 Feb 2024 01:34:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125674; x=1707730474; darn=vger.kernel.org; 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=vmzSsuQlbDZ+t30agBye8l5Gy5EgwDATrqd1ITBls6s=; b=qEbT5HvPzWhg5xIcD7DCDzBGSPngY6uCPgEd+nYMGrdq0pKUXT9/pqW9i44SBawFWx 8eafhZuAjWOE6N9UX//xPvuBbSIpqFClWzp1X1iLf/lt5KURb/tQJ5UFlcjSxERMsjKe b+fxnMDbumy93CMPaaQYOl6yUwRPdF8I8RcIKzeKMdWXvEMzyBfDWgGkmHwjNCcf4zRa u8Vv3yftoPu9LQ+NcpNMXywN6dhook8J3RY44ycirvNfNx1f/JGpHokcToV90w1rLqKz MJLYYDYTey4w6hoHh8dgaBwgJj0JpKbpVfjeMrOmMe1Gg+r3jQzzbsUgMkH7D+aGzNl8 QcTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125674; x=1707730474; 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=vmzSsuQlbDZ+t30agBye8l5Gy5EgwDATrqd1ITBls6s=; b=oeVHtp0ZAizQxOFTgfJhET16n3uuswCDV2RjckQ9S6V0BZlVb5GT/6Zj5FYKq7aU0e XJg39HWp/1PB2ehq6LbOJxgQqkWZ4ppoN4lpI2CbvYthPONHKC6DLsOy//2jK5DDmzDa I0/IIfuBzbEoEZVw4WxYaxPsXQCgGuupjSgLZvqrk/hJeTVpqBlhlWLgYIT4LqrIuh5I kM06y/Lcbso/9H32pZGoba3SsR0eqaM+QqE008oG6wG86tea518LXhRoC+gBk+C9f7lT ZjyU2iQ4OUc1qjZ7+Nr2HKS8066TKnYtZPR/G3khDezZO8IETQM3M5472tFEQxgUM5jO tGow== X-Gm-Message-State: AOJu0YyPuh5H3hpF7iOFUF/2tNaYew5LynnjQsqyCEoNhLyAglkzUZtw FHhANYTGRiPrQ3WeSzfJ6NL7ups328JdjERw9ACabFM+wg3pwxi7mXV55WnuF1ZferP2RgOnEGf g X-Google-Smtp-Source: AGHT+IHDaj3kNqPSeHGzX7jhB1piE+yGHsR31u8qOcgsycwVXq6Gkc70ZJK4doI9mG88u18meGSCjg== X-Received: by 2002:a05:600c:19c6:b0:40f:b691:d3c1 with SMTP id u6-20020a05600c19c600b0040fb691d3c1mr3833847wmq.30.1707125673807; Mon, 05 Feb 2024 01:34:33 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWaFE4TMMOkTAIjFTWDd+DVJBGl1fKNmAfr2NjMOlktEWI9BDzUbkqEPClKAxZ/xbBeZOLOwD+/OMaZaQqiAxcC8/w8nobZZDEMwGISykisMLvPH2IwXWyp/asBCGeM2shxYLgPFHw2bu8yavrW7xGrgGd+MAaJsQb040xMAnnQqSZm9HLquiyFmm3J1Uskus9e6gWjs3L9kHuEqhggKQUr8D9lWGB70EaaTOGUxuxZl+vRC75dFsFbHDpRQf68Cj+ytznMV8H7U5zrXz1QLUWdjhiWEjmuMJbzpt/SfLujnsM3U/7y9ea5cZpHfP3Ghr38pfKPbVkKSA1Y1c+C8WjcSz9XRa14xA== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:33 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 09/23] gpio: remove gpio_lock Date: Mon, 5 Feb 2024 10:34:04 +0100 Message-Id: <20240205093418.39755-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski The "multi-function" gpio_lock is pretty much useless with how it's used in GPIOLIB currently. Because many GPIO API calls can be called from all contexts but may also call into sleeping driver callbacks, there are many places with utterly broken workarounds like yielding the lock to call a possibly sleeping function and then re-acquiring it again without taking into account that the protected state may have changed. It was also used to protect several unrelated things: like individual descriptors AND the GPIO device list. We now serialize access to these two with SRCU and so can finally remove the spinlock. There is of course the question of consistency of lockless access to GPIO descriptors. Because we only support exclusive access to GPIOs (officially anyway, I'm looking at you broken GPIOD_FLAGS_BIT_NONEXCLUSIVE bit...) and the API contract with providers does not guarantee serialization, it's enough to ensure we cannot accidentally dereference an invalid pointer and that the state we present to both users and providers remains consistent. To achieve that: read the flags field atomically except for a few special cases. Read their current value before executing callback code and use this value for any subsequent logic. Modifying the flags depends on the particular use-case and can differ. For instance: when requesting a GPIO, we need to set the REQUESTED bit immediately so that the next user trying to request the same line sees -EBUSY. While at it: the allocations that used GFP_ATOMIC until this point can now switch to GFP_KERNEL. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 18 +++--- drivers/gpio/gpiolib-sysfs.c | 17 ++---- drivers/gpio/gpiolib.c | 106 +++++++++++------------------------ drivers/gpio/gpiolib.h | 2 - 4 files changed, 46 insertions(+), 97 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 75f4912339a6..3588aaf90e45 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2302,18 +2302,16 @@ static void gpio_desc_to_lineinfo(struct gpio_desc = *desc, memset(info, 0, sizeof(*info)); info->offset =3D gpio_chip_hwgpio(desc); =20 - scoped_guard(spinlock_irqsave, &gpio_lock) { - if (desc->name) - strscpy(info->name, desc->name, sizeof(info->name)); + if (desc->name) + strscpy(info->name, desc->name, sizeof(info->name)); =20 - scoped_guard(srcu, &desc->srcu) { - label =3D gpiod_get_label(desc); - if (label) - strscpy(info->consumer, label, - sizeof(info->consumer)); - } + dflags =3D READ_ONCE(desc->flags); =20 - dflags =3D READ_ONCE(desc->flags); + scoped_guard(srcu, &desc->srcu) { + label =3D gpiod_get_label(desc); + if (label && test_bit(FLAG_REQUESTED, &dflags)) + strscpy(info->consumer, label, + sizeof(info->consumer)); } =20 /* diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 3c3b8559cff5..1cc707685f87 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -563,7 +563,6 @@ int gpiod_export(struct gpio_desc *desc, bool direction= _may_change) struct gpio_device *gdev; struct gpiod_data *data; struct gpio_chip *chip; - unsigned long flags; struct device *dev; int status, offset; =20 @@ -578,6 +577,9 @@ int gpiod_export(struct gpio_desc *desc, bool direction= _may_change) return -EINVAL; } =20 + if (!test_and_set_bit(FLAG_EXPORT, &desc->flags)) + return -EPERM; + gdev =3D desc->gdev; chip =3D gdev->chip; =20 @@ -589,18 +591,11 @@ int gpiod_export(struct gpio_desc *desc, bool directi= on_may_change) goto err_unlock; } =20 - spin_lock_irqsave(&gpio_lock, flags); - if (!test_bit(FLAG_REQUESTED, &desc->flags) || - test_bit(FLAG_EXPORT, &desc->flags)) { - spin_unlock_irqrestore(&gpio_lock, flags); - gpiod_dbg(desc, "%s: unavailable (requested=3D%d, exported=3D%d)\n", - __func__, - test_bit(FLAG_REQUESTED, &desc->flags), - test_bit(FLAG_EXPORT, &desc->flags)); + if (!test_bit(FLAG_REQUESTED, &desc->flags)) { + gpiod_dbg(desc, "%s: unavailable (not requested)\n", __func__); status =3D -EPERM; goto err_unlock; } - spin_unlock_irqrestore(&gpio_lock, flags); =20 data =3D kzalloc(sizeof(*data), GFP_KERNEL); if (!data) { @@ -628,7 +623,6 @@ int gpiod_export(struct gpio_desc *desc, bool direction= _may_change) goto err_free_data; } =20 - set_bit(FLAG_EXPORT, &desc->flags); mutex_unlock(&sysfs_lock); return 0; =20 @@ -636,6 +630,7 @@ int gpiod_export(struct gpio_desc *desc, bool direction= _may_change) kfree(data); err_unlock: mutex_unlock(&sysfs_lock); + clear_bit(FLAG_EXPORT, &desc->flags); gpiod_dbg(desc, "%s: status %d\n", __func__, status); return status; } diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6cfb75ee739d..5ed5b71590ab 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -76,12 +76,6 @@ static struct bus_type gpio_bus_type =3D { */ #define FASTPATH_NGPIO CONFIG_GPIOLIB_FASTPATH_LIMIT =20 -/* gpio_lock prevents conflicts during gpio_desc[] table updates. - * While any GPIO is requested, its gpio_chip is not removable; - * each GPIO's "requested" flag serves as a lock and refcount. - */ -DEFINE_SPINLOCK(gpio_lock); - static DEFINE_MUTEX(gpio_lookup_lock); static LIST_HEAD(gpio_lookup_list); =20 @@ -123,8 +117,7 @@ static int desc_set_label(struct gpio_desc *desc, const= char *label) const char *new =3D NULL, *old; =20 if (label) { - /* FIXME: make this GFP_KERNEL once the spinlock is out. */ - new =3D kstrdup_const(label, GFP_ATOMIC); + new =3D kstrdup_const(label, GFP_KERNEL); if (!new) return -ENOMEM; } @@ -1088,7 +1081,6 @@ EXPORT_SYMBOL_GPL(gpiochip_add_data_with_key); void gpiochip_remove(struct gpio_chip *gc) { struct gpio_device *gdev =3D gc->gpiodev; - unsigned long flags; unsigned int i; =20 down_write(&gdev->sem); @@ -1109,12 +1101,10 @@ void gpiochip_remove(struct gpio_chip *gc) */ gpiochip_set_data(gc, NULL); =20 - spin_lock_irqsave(&gpio_lock, flags); for (i =3D 0; i < gdev->ngpio; i++) { if (test_bit(FLAG_REQUESTED, &gdev->descs[i].flags)) break; } - spin_unlock_irqrestore(&gpio_lock, flags); =20 if (i !=3D gdev->ngpio) dev_crit(&gdev->dev, @@ -2221,62 +2211,43 @@ EXPORT_SYMBOL_GPL(gpiochip_remove_pin_ranges); static int gpiod_request_commit(struct gpio_desc *desc, const char *label) { struct gpio_chip *gc =3D desc->gdev->chip; - unsigned long flags; unsigned int offset; int ret; =20 + if (test_and_set_bit(FLAG_REQUESTED, &desc->flags)) + return -EBUSY; + if (label) { label =3D kstrdup_const(label, GFP_KERNEL); if (!label) return -ENOMEM; } =20 - spin_lock_irqsave(&gpio_lock, flags); - /* NOTE: gpio_request() can be called in early boot, * before IRQs are enabled, for non-sleeping (SOC) GPIOs. */ =20 - if (test_and_set_bit(FLAG_REQUESTED, &desc->flags)) { - ret =3D -EBUSY; - goto out_free_unlock; - } - if (gc->request) { - /* gc->request may sleep */ - spin_unlock_irqrestore(&gpio_lock, flags); offset =3D gpio_chip_hwgpio(desc); if (gpiochip_line_is_valid(gc, offset)) ret =3D gc->request(gc, offset); else ret =3D -EINVAL; - spin_lock_irqsave(&gpio_lock, flags); + if (ret) + goto out_clear_bit; + } =20 - if (ret) { - desc_set_label(desc, NULL); - clear_bit(FLAG_REQUESTED, &desc->flags); - goto out_free_unlock; - } - } - if (gc->get_direction) { - /* gc->get_direction may sleep */ - spin_unlock_irqrestore(&gpio_lock, flags); + if (gc->get_direction) gpiod_get_direction(desc); - spin_lock_irqsave(&gpio_lock, flags); - } - spin_unlock_irqrestore(&gpio_lock, flags); =20 ret =3D desc_set_label(desc, label ? : "?"); - if (ret) { - clear_bit(FLAG_REQUESTED, &desc->flags); - return ret; - } + if (ret) + goto out_clear_bit; =20 return 0; =20 -out_free_unlock: - spin_unlock_irqrestore(&gpio_lock, flags); - kfree_const(label); +out_clear_bit: + clear_bit(FLAG_REQUESTED, &desc->flags); return ret; } =20 @@ -2346,35 +2317,32 @@ static bool gpiod_free_commit(struct gpio_desc *des= c) =20 might_sleep(); =20 - spin_lock_irqsave(&gpio_lock, flags); - gc =3D desc->gdev->chip; - if (gc && test_bit(FLAG_REQUESTED, &desc->flags)) { - if (gc->free) { - spin_unlock_irqrestore(&gpio_lock, flags); - might_sleep_if(gc->can_sleep); + flags =3D READ_ONCE(desc->flags); + + if (gc && test_bit(FLAG_REQUESTED, &flags)) { + if (gc->free) gc->free(gc, gpio_chip_hwgpio(desc)); - spin_lock_irqsave(&gpio_lock, flags); - } - clear_bit(FLAG_ACTIVE_LOW, &desc->flags); - clear_bit(FLAG_REQUESTED, &desc->flags); - clear_bit(FLAG_OPEN_DRAIN, &desc->flags); - clear_bit(FLAG_OPEN_SOURCE, &desc->flags); - clear_bit(FLAG_PULL_UP, &desc->flags); - clear_bit(FLAG_PULL_DOWN, &desc->flags); - clear_bit(FLAG_BIAS_DISABLE, &desc->flags); - clear_bit(FLAG_EDGE_RISING, &desc->flags); - clear_bit(FLAG_EDGE_FALLING, &desc->flags); - clear_bit(FLAG_IS_HOGGED, &desc->flags); + + clear_bit(FLAG_ACTIVE_LOW, &flags); + clear_bit(FLAG_REQUESTED, &flags); + clear_bit(FLAG_OPEN_DRAIN, &flags); + clear_bit(FLAG_OPEN_SOURCE, &flags); + clear_bit(FLAG_PULL_UP, &flags); + clear_bit(FLAG_PULL_DOWN, &flags); + clear_bit(FLAG_BIAS_DISABLE, &flags); + clear_bit(FLAG_EDGE_RISING, &flags); + clear_bit(FLAG_EDGE_FALLING, &flags); + clear_bit(FLAG_IS_HOGGED, &flags); #ifdef CONFIG_OF_DYNAMIC WRITE_ONCE(desc->hog, NULL); #endif ret =3D true; - } + desc_set_label(desc, NULL); + WRITE_ONCE(desc->flags, flags); =20 - spin_unlock_irqrestore(&gpio_lock, flags); - desc_set_label(desc, NULL); - gpiod_line_state_notify(desc, GPIOLINE_CHANGED_RELEASED); + gpiod_line_state_notify(desc, GPIOLINE_CHANGED_RELEASED); + } =20 return ret; } @@ -2416,22 +2384,12 @@ char *gpiochip_dup_line_label(struct gpio_chip *gc,= unsigned int offset) if (IS_ERR(desc)) return NULL; =20 - guard(spinlock_irqsave)(&gpio_lock); - if (!test_bit(FLAG_REQUESTED, &desc->flags)) return NULL; =20 guard(srcu)(&desc->srcu); =20 - /* - * FIXME: Once we mark gpiod_direction_input/output() and - * gpiod_get_direction() with might_sleep(), we'll be able to protect - * the GPIO descriptors with mutex (while value setting operations will - * become lockless). - * - * Until this happens, this allocation needs to be atomic. - */ - label =3D kstrdup(gpiod_get_label(desc), GFP_ATOMIC); + label =3D kstrdup(gpiod_get_label(desc), GFP_KERNEL); if (!label) return ERR_PTR(-ENOMEM); =20 diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 2bf3f9e13ae4..9b7afe87f1bd 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -135,8 +135,6 @@ int gpiod_set_array_value_complex(bool raw, bool can_sl= eep, =20 int gpiod_set_transitory(struct gpio_desc *desc, bool transitory); =20 -extern spinlock_t gpio_lock; - void gpiod_line_state_notify(struct gpio_desc *desc, unsigned long action); =20 /** --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3A3912B7A for ; Mon, 5 Feb 2024 09:34:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125678; cv=none; b=idOmKCzsujmcEsXm0qPrtvn1sTyqV5qF9KG6vZxuv3dxMk5nSg6sTX26n1KMyzoJZYGLoOCRluLukPdrPTkaVvj6qKFKSOlmZzQ/CvfjzwCqaMzMJiYDQanIS8xzqeauQSZKGsD+2OaFOIm2rMJ4c7m2lalon1RlKOwcAE/oV7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125678; c=relaxed/simple; bh=rfKavv+WG6jGS5BHlahGWQusPjVqbbXZ7CB6SI+xjkE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=en6C0DnfR6IafjJddFPtwwKRDqHZCelUwMNRZCxxaBQhXXatQolWkZCCnxBlcFskazb+qRWGOlRaJUx3TltVMJFVYxTpaYgxyw4tZZouniTXjh0050wonxGE5Z6mzANSOtGkYh8yGmTTPyQW/KHG9t7pDT3/hbzlY+p8rPHNh1c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=eo6843DD; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="eo6843DD" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-5100cb238bcso7531976e87.3 for ; Mon, 05 Feb 2024 01:34:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125675; x=1707730475; darn=vger.kernel.org; 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=oBVIUbEZhzPUY5wnbR8PSqxrCBFBG4RRWNGnrCutvhg=; b=eo6843DD9eFSeuKm9WWRqFLHKuNJsAsJCe1t5eP56+JJ5PPb0Uy35xAGsWJC47J78V ooKBZR48+Crkfcf8B5H0p9bmvcyvopaVnz/xZSJxjaRS7kWL+SwnlUxUDSJY6AbFAbTK DreAJ6YjZ6jU3kvpSdJ5RSE1G87roRZLMP/SdKjb0YHLiH4fn4wC2j9PFtuvfwdBTLa3 tN2C8mo/YzPr9ch9cyxyjTXVxNZeTnLmnu2UT7FXZ0hiY1v/KQFIfRyjBGn0knCWk3/k 3viNMxPwTRhIJwo5KlAhmwXfZjBTAkMB/PTNG85LG9DgDOuMgxM10k4ehNo7RKrQ1p/E 1upQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125675; x=1707730475; 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=oBVIUbEZhzPUY5wnbR8PSqxrCBFBG4RRWNGnrCutvhg=; b=DgoVzgmYfUFfxjKDTHummVlCSXcPnxy/zbRVeIUezw1Hw+vliHRbNJENUMsJdku/rj Wj9AQ2RtxdF076mV4qk3J9XtY08YLw0+a6RwhFoKUTLuMZQclUX/vpds7avlR9f/KA8W 77fXLSSqvMtJqc2pNZaDhE1iLO9ZMskn6LWFGZC91EbRnmnhT1CSsFtEAIUhFehkx3aO a1MR7/qcl5abUWy7wTkeJVyulOfK0SPR7j/ySFg+xM8ieG6tfefWMmOWxqcPntMl+dsB WgeBKWWFUtwywOGlM9dwOVpDq7+d6/oymgK2grZmDedHmuqgPkEDJNAWf/Jbh3kQUQFU PIPA== X-Gm-Message-State: AOJu0Yw21zDVanlHYnQswUNnfntvayJU0d7hSQcz7MpE0K98UwZdZeMO 3C/LZVhwdgQoiZuscFG77M3JQu55l3lFJ9XYBDZhaQCP+I54Te30tgaUn91i1g4= X-Google-Smtp-Source: AGHT+IFf5V3o092bmqPbbvpWyHNdPE2eO7k80aGf9SuKa1MQgaO3K0nCTsSkjqLFZNeKshudZ6G6cQ== X-Received: by 2002:a05:6512:10c8:b0:50e:7410:d5b0 with SMTP id k8-20020a05651210c800b0050e7410d5b0mr6312960lfg.28.1707125674803; Mon, 05 Feb 2024 01:34:34 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCU+vRrFS3A2LQom52oicbbrO1+QRNmZbSVSC2RqEnatt0iYkThW7J9MLI/MMTZItiNU4cz3RvUAZw2i+BnyZCheQOcyCcYrKBEa8LZGPtzgg/Wbvo/C/fo9aHnqMgD6aWctF6ZMr1nY7P7LAql/Z9HOAXR7qHTosr4yZLKD4rzhVqqsFyyrS9fNhgwstDS+qJVd6aaaAzK7zoN3jCZdzJRfHMJihL3AFoPtaXNULJtw5Ru1s8z6IDJDfwolEKW3s8fRKtgu9xPmBB/H5TQ3sGWvIkPe3/njUZsQevjoFlwMadyF1zAa8VW9+gzCEtVs2/zxSHsttQNI1q2RrRxH1QAI4Xe8GEtACw== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:34 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 10/23] gpio: reinforce desc->flags handling Date: Mon, 5 Feb 2024 10:34:05 +0100 Message-Id: <20240205093418.39755-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski We now removed the gpio_lock spinlock and modified the places previously protected by it to handle desc->flags access in a consistent way. Let's improve other places that were previously unprotected by reading the flags field of gpio_desc once and using the stored value for logic consistency. If we need to modify the field, let's also write it back once with a consistent value resulting from the function's logic. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 5ed5b71590ab..d49f84d692ce 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -336,18 +336,20 @@ static int gpiochip_find_base_unlocked(int ngpio) int gpiod_get_direction(struct gpio_desc *desc) { struct gpio_chip *gc; + unsigned long flags; unsigned int offset; int ret; =20 gc =3D gpiod_to_chip(desc); offset =3D gpio_chip_hwgpio(desc); + flags =3D READ_ONCE(desc->flags); =20 /* * Open drain emulation using input mode may incorrectly report * input here, fix that up. */ - if (test_bit(FLAG_OPEN_DRAIN, &desc->flags) && - test_bit(FLAG_IS_OUT, &desc->flags)) + if (test_bit(FLAG_OPEN_DRAIN, &flags) && + test_bit(FLAG_IS_OUT, &flags)) return 0; =20 if (!gc->get_direction) @@ -361,7 +363,8 @@ int gpiod_get_direction(struct gpio_desc *desc) if (ret > 0) ret =3D 1; =20 - assign_bit(FLAG_IS_OUT, &desc->flags, !ret); + assign_bit(FLAG_IS_OUT, &flags, !ret); + WRITE_ONCE(desc->flags, flags); =20 return ret; } @@ -747,9 +750,6 @@ static void gpiochip_machine_hog(struct gpio_chip *gc, = struct gpiod_hog *hog) return; } =20 - if (test_bit(FLAG_IS_HOGGED, &desc->flags)) - return; - rv =3D gpiod_hog(desc, hog->line_name, hog->lflags, hog->dflags); if (rv) gpiod_err(desc, "%s: unable to hog GPIO line (%s:%u): %d\n", @@ -2522,13 +2522,16 @@ static int gpio_set_config(struct gpio_desc *desc, = enum pin_config_param mode) static int gpio_set_bias(struct gpio_desc *desc) { enum pin_config_param bias; + unsigned long flags; unsigned int arg; =20 - if (test_bit(FLAG_BIAS_DISABLE, &desc->flags)) + flags =3D READ_ONCE(desc->flags); + + if (test_bit(FLAG_BIAS_DISABLE, &flags)) bias =3D PIN_CONFIG_BIAS_DISABLE; - else if (test_bit(FLAG_PULL_UP, &desc->flags)) + else if (test_bit(FLAG_PULL_UP, &flags)) bias =3D PIN_CONFIG_BIAS_PULL_UP; - else if (test_bit(FLAG_PULL_DOWN, &desc->flags)) + else if (test_bit(FLAG_PULL_DOWN, &flags)) bias =3D PIN_CONFIG_BIAS_PULL_DOWN; else return 0; @@ -2694,24 +2697,28 @@ EXPORT_SYMBOL_GPL(gpiod_direction_output_raw); */ int gpiod_direction_output(struct gpio_desc *desc, int value) { + unsigned long flags; int ret; =20 VALIDATE_DESC(desc); - if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) + + flags =3D READ_ONCE(desc->flags); + + if (test_bit(FLAG_ACTIVE_LOW, &flags)) value =3D !value; else value =3D !!value; =20 /* GPIOs used for enabled IRQs shall not be set as output */ - if (test_bit(FLAG_USED_AS_IRQ, &desc->flags) && - test_bit(FLAG_IRQ_IS_ENABLED, &desc->flags)) { + if (test_bit(FLAG_USED_AS_IRQ, &flags) && + test_bit(FLAG_IRQ_IS_ENABLED, &flags)) { gpiod_err(desc, "%s: tried to set a GPIO tied to an IRQ as output\n", __func__); return -EIO; } =20 - if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) { + if (test_bit(FLAG_OPEN_DRAIN, &flags)) { /* First see if we can enable open drain in hardware */ ret =3D gpio_set_config(desc, PIN_CONFIG_DRIVE_OPEN_DRAIN); if (!ret) @@ -2721,7 +2728,7 @@ int gpiod_direction_output(struct gpio_desc *desc, in= t value) ret =3D gpiod_direction_input(desc); goto set_output_flag; } - } else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { + } else if (test_bit(FLAG_OPEN_SOURCE, &flags)) { ret =3D gpio_set_config(desc, PIN_CONFIG_DRIVE_OPEN_SOURCE); if (!ret) goto set_output_value; @@ -4418,21 +4425,22 @@ int gpiod_hog(struct gpio_desc *desc, const char *n= ame, int hwnum; int ret; =20 + if (test_and_set_bit(FLAG_IS_HOGGED, &desc->flags)) + return 0; + gc =3D gpiod_to_chip(desc); hwnum =3D gpio_chip_hwgpio(desc); =20 local_desc =3D gpiochip_request_own_desc(gc, hwnum, name, lflags, dflags); if (IS_ERR(local_desc)) { + clear_bit(FLAG_IS_HOGGED, &desc->flags); ret =3D PTR_ERR(local_desc); pr_err("requesting hog GPIO %s (chip %s, offset %d) failed, %d\n", name, gc->label, hwnum, ret); return ret; } =20 - /* Mark GPIO as hogged so it can be identified and removed later */ - set_bit(FLAG_IS_HOGGED, &desc->flags); - gpiod_dbg(desc, "hogged as %s%s\n", (dflags & GPIOD_FLAGS_BIT_DIR_OUT) ? "output" : "input", (dflags & GPIOD_FLAGS_BIT_DIR_OUT) ? --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A950A168DA for ; Mon, 5 Feb 2024 09:34:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125679; cv=none; b=WeYWQJz3ifzAPEWV17Of5h99GsgTWHnTYHqlNxFEeVRzccqFKZ247IpZBesfMQ0M65gs98FQ9DI6X4OkSefmt1w88UM8pvG9uDXYFbd9wOlrcRCnbpA9UPpD7a5nt8vLXeTWX8UZEMo2xjbH4C58H+oR9Hr/woBfdI0NXkI8kbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125679; c=relaxed/simple; bh=ovwDn1Lb6tSdzCyIZYdd/rd1ePt6cjIadVa1Vg7f7aY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=o2+VDxOclL3Bx8ekdcAMHmk6GqS8a8IzSvj4y/TNWAgeosXBb7wWYZcjK5k988SJ6rhzGpGtCHoeU5irtCEKLLB5CLGV/6FGXQXO46nETFwslBntqEnVRmfZdwzbOI9h9U1GR7qHcuSRXn2Uvx/zdiKAptOrmdGwQyOeqvphi8k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=d26DncOR; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="d26DncOR" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-40fb63c40c0so37295865e9.2 for ; Mon, 05 Feb 2024 01:34:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125675; x=1707730475; darn=vger.kernel.org; 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=0ag8nRnrxnEMvnEvUPbNUe/ytaETypis2xHLc3wBVPY=; b=d26DncORw3t+yGIra0imTW+0tLdJRc1oa4ZSqyLFvsDHIc45NluPg1seG3pag1eKo0 VpJbppUYMFgjXnZLGiI8MV1uekgNHm+LRYzqO0MTJo8T5b5NFA1O4uvFz6SHHZfqTUAi +F+lZyi7PjhuoNyjSoOpcVbbvCp7jkv/C6QzAmn4YPRl8/UHOz+l6sVQPZGIj98QUIk8 bIFPXRKh/wMff0+MGX3AKQYrbTXkFNvfkyOSnMPd8yq1M51nOZL4n+HusCm8148bFwhf NIWHqPM3qeZU4sFb8OLbB2iFHxSsAYm8QRaiEQr+35+GRwzVJrodQhZTHxP+TtR9w8qe InFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125675; x=1707730475; 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=0ag8nRnrxnEMvnEvUPbNUe/ytaETypis2xHLc3wBVPY=; b=w6iuP8xTQ9/spdtND9WCVBTB1WtG9/6tzyAKgfRz2pgT/uasUbLlFoLzBkmQYlauL1 FGpwQCT/IdiDYyE882EGvEgq4mfx6gPuj4j1a48J6pXBGGJ0tpMtYRW7k/xXiGr9FdlQ k3ZeWrwfT+Yu9HHJbmQ+AKNHDJwkkScPptYI5YA27H40GS5OirKFmXE1QEjzvycTQIcg NvNhRBeM4YAB+gqlC8xeakyJ5ree/CiztqRg6njpBnac+Q21aBY9Uw/iLKbGEI1Yl3ke 51JE/H6Nspu6Q3CxGB58jQaoMZpd//7Rh/dNG5FQnQCdxnuiqc8aWU5mcErs/u/g6BCz ZUhw== X-Gm-Message-State: AOJu0YyX1cFZIS0K2/HJYOhk2WfHVgE8O+XGJP0RMWXRpBtVMm5QOsiU zKMVp7bAABXtAywkRIRC/noOYh50+uMeysWOSTRnhFzngwBPOoFhUwsu0r8z+1k= X-Google-Smtp-Source: AGHT+IHSJoTtocwyZLmVaK6jsmh0L0SfYF1jX0prYviYSXwbw76F10dFvCuDdYWWf2UvqRfu8/1Rnw== X-Received: by 2002:a05:600c:19cf:b0:40e:fbdd:238a with SMTP id u15-20020a05600c19cf00b0040efbdd238amr4414433wmq.37.1707125675774; Mon, 05 Feb 2024 01:34:35 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXdCX/l3wUqepSg30cg8LTd03aaPjbEVI0mjv9Mf5RrDr7lTxGAutl0RuHHzUC0iD87ZFAPr02TW26I7/M80456Z60mAJjmVXPYK0ONK9DaeFtjXvfb6kZdIxRLm+/+gt48fT1DVi7WjtUHYG08yT1JI0prbmnHCIIZvyuu/M9pCSsXQUGQop9gc2FEfmFCdvl9ZsdMZFDKGbVKlLWCoPt3Tj4tCEYyUlCMnOfAm4jaQe4NiifzVAP07t3/spZvpTBKDLRerfFXdLraeWAhrQapHsnzpmZbMnZVWjwevstDEUrRLJfYrSjyaJMb5HQtTw8cfNNg5SrBRie0YLJ+T5WLkQWIx/YHyg== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:35 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 11/23] gpio: remove unneeded code from gpio_device_get_desc() Date: Mon, 5 Feb 2024 10:34:06 +0100 Message-Id: <20240205093418.39755-12-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski The GPIO chip pointer is unused. Let's remove it. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index d49f84d692ce..f77f919dbad9 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -184,16 +184,6 @@ EXPORT_SYMBOL_GPL(gpiochip_get_desc); struct gpio_desc * gpio_device_get_desc(struct gpio_device *gdev, unsigned int hwnum) { - struct gpio_chip *gc; - - /* - * FIXME: This will be locked once we protect gdev->chip everywhere - * with SRCU. - */ - gc =3D gdev->chip; - if (!gc) - return ERR_PTR(-ENODEV); - if (hwnum >=3D gdev->ngpio) return ERR_PTR(-EINVAL); =20 --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C65F171AC for ; Mon, 5 Feb 2024 09:34:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125680; cv=none; b=gZTsn2scf6V5yv39FGYtF7qUmqUY0wJ1qwGsMd7SDZvo/bPv5s/k8Fd0Co8hwsBSl6upPgCJe01OtbwX5RG3aklRQDKolUF1W5o9vzpaEqy1ZV3Tlgbi0FGvL2SbPKCoqVUdvWIePnI6hnifn1iNgprnm2lpJ8NHBwUKG/mRBD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125680; c=relaxed/simple; bh=6pZf3MPfcP7U/qzAucrcxQHtn245jLEQDsd8yxAaDXY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Vpkw3thWjpskifRHhya5uvFEuypXnjsH+H6EYBWSbi9wIQ59VkMbqvO4i+L4LKCphNaLSIJ5sD798uN90NCfLfWIxd5UAlfA4DEQA+oscis52zIAxqFhiUdEhzKhDNZu54ZBdZqtJtOsQRPmDAPg/qP1/Oc300F8f2foZ8KPlxQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=Wv111LTZ; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="Wv111LTZ" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-40fb94d42e4so33510615e9.2 for ; Mon, 05 Feb 2024 01:34:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125676; x=1707730476; darn=vger.kernel.org; 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=fPWICPIbUQqhQWXK/aPucJT3q02Uu3yz0IoZJm+ImZ4=; b=Wv111LTZxj8WUrUEuKtOGY7+yl5fqYo+8RKnHXmCJAphqtZbowkZHWQ/rB+aSqq29s QCLOYrGNPsnWDpdpEo7rVvKWPc4ROlrZVrdoQ1Ayo/JHorbX4YHau+YDZtv5aMcsAAu+ ofD4xkCP7G8qFUaKE+gJhrUBiDg8rH2lWcZbi3tVP16yn1pIRFeBdi7Zo9MelAxmb2Y9 rJSYX4pev8T5jtVycnl2HKPgoeIJzF6oe1t+xDTKpb31Jcf9xCyPcUclQTzxK1DTVvyM x0iSu+hKjYSmQj1DXh9fz7c7cfKoslZmumUjmhGU+6m7SM6T6T07YYovyEfaZ6vXd9tP CqSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125676; x=1707730476; 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=fPWICPIbUQqhQWXK/aPucJT3q02Uu3yz0IoZJm+ImZ4=; b=rlRDp1PmwDfONaCsqZljISUCElNohQ+Xk0H/WMwYYfw0+d69Wbvw6xGTsrUh5JnQl/ 7k5ZoIAjoDPepy62CHAHvn3/MYiajTFNsOTsm/f9HXPWN221eWog08YgZQoXa7vSpESS D0pV4Tyr1G2j6X2Sfw0Aogr8UoRYDN5nedwKEqrgOaX/2Xk8g6Blh38w1C0k0fW7Sovp kI84TA/Njir8Xy93cgIUxh7dDrius0ykHGBPmLVztgrW81PJATlEd1zSdDxysHvV7T0O 5Chjssv5+4OqDVX68UOlhirf0uuNi11SLB8vqLCE769APED1WRTGkf8gGJM7L2cK1njQ gyUQ== X-Gm-Message-State: AOJu0YyngrXdu78h/uC+0G+y+4vewRAITWEmGYZtkpdbCTsqQr/xfKe1 kKBpvsV/XSGpW7LiXwjEw7fbCKQF4VN4hpuYt1nBP2YRlUTtEex6xT5jbGGQD3Y= X-Google-Smtp-Source: AGHT+IG21q8aYCNLml1cXS2JVIuYakcxkQAkcMiZABjqWfdpPL7byMFcdGrefOCQfYZl8ybztm6cMg== X-Received: by 2002:a05:600c:5191:b0:40e:60c3:c327 with SMTP id fa17-20020a05600c519100b0040e60c3c327mr3910240wmb.1.1707125676576; Mon, 05 Feb 2024 01:34:36 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUU/8yo/GZ+OF/G9T3pL+XmpQ6Byf0DyWVqn2QJEbCSns32/4tJB8SUprsV9AxBNmx3gG8oW13Wux0CylhKHd+TQbXiCadEdaXmUNbKIUZOOU7cZfDMXGjArmp/8bw58Pd9nBhV+X8b/WFw9qRiCgC92K8BBZH8t/7DHrvC3Q/K/QaCIlYwY6mzCXWT4peHngvkkVfXI6rzKLf65ONr91uKuWmOoMRre5LsmqAI3PxHVakQnNWGRYLjqe1y/y0QXfHK4YPAvk4fM9CdQIufi1Rhb62ZH5bEvd7LkDRDuLhx2VooOIwIq1qrvdaTKBghypZyJ9D9O2A9wYgS7OMYkp5fN+ml4DBJnA== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:36 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 12/23] gpio: sysfs: extend the critical section for unregistering sysfs devices Date: Mon, 5 Feb 2024 10:34:07 +0100 Message-Id: <20240205093418.39755-13-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski Checking the gdev->mockdev pointer for NULL must be part of the critical section. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-sysfs.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 1cc707685f87..5da316ea9cc7 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 =20 #include +#include #include #include #include @@ -768,15 +769,15 @@ void gpiochip_sysfs_unregister(struct gpio_device *gd= ev) struct gpio_desc *desc; struct gpio_chip *chip =3D gdev->chip; =20 - if (!gdev->mockdev) - return; + scoped_guard(mutex, &sysfs_lock) { + if (!gdev->mockdev) + return; =20 - device_unregister(gdev->mockdev); + device_unregister(gdev->mockdev); =20 - /* prevent further gpiod exports */ - mutex_lock(&sysfs_lock); - gdev->mockdev =3D NULL; - mutex_unlock(&sysfs_lock); + /* prevent further gpiod exports */ + gdev->mockdev =3D NULL; + } =20 /* unregister gpiod class devices owned by sysfs */ for_each_gpio_desc_with_flag(chip, desc, FLAG_SYSFS) { --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BE6314A8E for ; Mon, 5 Feb 2024 09:34:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125681; cv=none; b=LN8CGh6JFNc6BZ09w8o0MXFosaJ8CC6jdmkgE7tBvxbjYKO9JaBuOyjHAHkmpCSApE8d/UrwOfk0+5uFu3xdMveY7W5gfDZUe5YURmqZ7bOnVc7oaFYs5r4FbKDTrBHfEQNl8gB1qCiV0PXlWqJKa2NT4wZGEbAlvJ3uD4sNrbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125681; c=relaxed/simple; bh=dvNWzN3ht8/FdUM9oKycIS4wx6Ize3NJvGw5mcCj4kA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ISQk6DXinnk5N5VeNyZrFxRYUtTa1Urwv02apEXCroKvu5FEEcq0eHmxST/VyyjdeBhDn1VxekcqaMSfl19cYxi2FGGt2GUNZYMxVqRymrI0d5SIYjOv8fp+ny9Tq5VZGvhjBqf3Pg59InVxJeiEeNhHX/R7Eqa1cW6EUQc64dQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=orscmaR7; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="orscmaR7" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-40fc549ab9bso25503785e9.0 for ; Mon, 05 Feb 2024 01:34:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125677; x=1707730477; darn=vger.kernel.org; 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=nkDPe1O0gAbIcKrknOKSxNlPidMI9YPWSkCZD1MG6Wc=; b=orscmaR7Efyb+6xjb8f5wnnU8y9W3058FcC+OP5Yj+a11/+LuPWhyzLLR3Xh4MLsvN 7IAe55dI4mmaz0I12mylsMDUOnOvMCDsT8kAHMZovp1g8wsTiq2+LBWfbd2uhjxHnd/e HgCOQAFh4N2yvw38CBjKKqAljikWUQ1e4Cw87V50YGlgUN6JJ/10rKqY35ACn6k3r7GQ S6iy9TW54oOehVrSblKPC3zWTCK0ByJVLhQ8SE8ISyAVEcQ9YDbFHqbe3B4gmr59MRkE SE+PlJdhN3hdpu6/I+nB5nIFkrWx3RsFBhb4YyfkLSVVPUEPAxoPJoa0+Uba3vJYsn13 ophA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125677; x=1707730477; 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=nkDPe1O0gAbIcKrknOKSxNlPidMI9YPWSkCZD1MG6Wc=; b=rxMYkA1UJMQkn6t+89m7vgzJO2KxLuT6OlBfMcbvhEkggrqygzY7MjCA2elp2AkLqI TpjL2+l401LxovdMM15TfU5LjLvozMSq+cECSKieUUZzhjXQ/JSN6iRHNeUujq0TRwKX fFsgdqggcJ3/8xfXENxYFhZ0A1kbVsd8mhPjPnqE/fVUUPzf8tz512WN/EF2AZwYnDcR ALIdw3qsCWTalRXEY5uIiwGntpKdcc7x8xFdp9xUEdjbfjrm/hUGkywcBdhtYz9vfVFy Djsy6wLKjY/SWT9TaPW6RzYW+WOVvqVqeUiRuzWXEa3RLt5t9NgFTwPgc5x2cPBfU2cI MGAQ== X-Gm-Message-State: AOJu0Yy7yq0Gt2p8pOKDHyw/G//Lb1xF+8SCL4AI1amMMAPMSucSZkqw w1pPZE7HhmxejmYk+ZFhk6gJlAXSGzODH8UEIT7VE1ktIste4Hhkfqn5nvIptU4= X-Google-Smtp-Source: AGHT+IGRtximsZuHOJ+4t7O1k20vhwzMFUlcMGGnBrLsaGExTNJF6XHpbFDep4ZG6gEfToYEqqNUog== X-Received: by 2002:a05:600c:154f:b0:40f:d253:38f1 with SMTP id f15-20020a05600c154f00b0040fd25338f1mr3921163wmg.26.1707125677471; Mon, 05 Feb 2024 01:34:37 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUtKZ4n8oU5koW9HFK4egEwXKSg2J4+0iyLOdhFrR5BFLFICgg2ZxVxx+HreUxjkIAcZ6Er128kBk0zLOFMm9V644WeSe7Em77IlosfjExrIlg1PVfe1r/QRTj2eojyqPxCu/1MB4dVaD5MBh+c5vQclpTdCLc1zlhVyNDUPB3IofmtBUzDqtC3CbIm7N3fiuHywSMglHKV6rWVC6TdXOEvv0Il52DsBqy2BQ9jT6wHy8U3UmPJkcLJFIAQhYXyOSCmrKkbchdWerYdX1CyBMx80AQu6oCx416aCbL2BYiYbg6F2VpvFNnGsDtJCmyZzKTSDQkgh0+tOl0DqhynPWNvXXYMx6Yz3Q== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:37 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 13/23] gpio: sysfs: pass the GPIO device - not chip - to sysfs callbacks Date: Mon, 5 Feb 2024 10:34:08 +0100 Message-Id: <20240205093418.39755-14-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski We're working towards protecting the chip pointer in struct gpio_device with SRCU. In order to use it in sysfs callbacks we must pass the pointer to the GPIO device that wraps the chip instead of the address of the chip itself as the user data. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-sysfs.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 5da316ea9cc7..654a5bc53047 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -401,27 +401,27 @@ static const struct attribute_group *gpio_groups[] = =3D { static ssize_t base_show(struct device *dev, struct device_attribute *attr, char *buf) { - const struct gpio_chip *chip =3D dev_get_drvdata(dev); + const struct gpio_device *gdev =3D dev_get_drvdata(dev); =20 - return sysfs_emit(buf, "%d\n", chip->base); + return sysfs_emit(buf, "%d\n", gdev->chip->base); } static DEVICE_ATTR_RO(base); =20 static ssize_t label_show(struct device *dev, struct device_attribute *attr, char *buf) { - const struct gpio_chip *chip =3D dev_get_drvdata(dev); + const struct gpio_device *gdev =3D dev_get_drvdata(dev); =20 - return sysfs_emit(buf, "%s\n", chip->label ?: ""); + return sysfs_emit(buf, "%s\n", gdev->chip->label ?: ""); } static DEVICE_ATTR_RO(label); =20 static ssize_t ngpio_show(struct device *dev, struct device_attribute *attr, char *buf) { - const struct gpio_chip *chip =3D dev_get_drvdata(dev); + const struct gpio_device *gdev =3D dev_get_drvdata(dev); =20 - return sysfs_emit(buf, "%u\n", chip->ngpio); + return sysfs_emit(buf, "%u\n", gdev->chip->ngpio); } static DEVICE_ATTR_RO(ngpio); =20 @@ -751,7 +751,7 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) parent =3D &gdev->dev; =20 /* use chip->base for the ID; it's already known to be unique */ - dev =3D device_create_with_groups(&gpio_class, parent, MKDEV(0, 0), chip, + dev =3D device_create_with_groups(&gpio_class, parent, MKDEV(0, 0), gdev, gpiochip_groups, GPIOCHIP_NAME "%d", chip->base); if (IS_ERR(dev)) --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53E9E12E43 for ; Mon, 5 Feb 2024 09:34:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125682; cv=none; b=FoEMWchTtReNfRuPrc8bibgjV2LkqtuKaaDbXDGtWT6quc+VyuXscZeafESH1YdhcV0VQTJ6FivBWuzGms2xBiuHwwoqjw1dIMhJ2+WHnkkYW4hjkjf11vFtRmN9Uo3G/Glpcs/OW9zNTfEQeneVPrjYElYGo1rhZUX8XMebRJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125682; c=relaxed/simple; bh=yLFHAeDDaUuIFRqdSf+MG12ymiBBzwEskiNkeG6cKEk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=l3ANzdS6MWxuQeHffxISzlSTynbva+blVEBHpa8Hl7fr6v7lGOYeaax2TlQDnNp1uPaJyq89Y6Ehhc/xelTtnRNOB+B98DxgBv062WZDjNRpmEvpgx33s9XPHauUKpUR+fkX2tSzabKErQuhO/pqTIKD8+e+lp2r4wNriuNYNTY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=HU9Nb2/u; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="HU9Nb2/u" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-5111e5e4e2bso6456641e87.3 for ; Mon, 05 Feb 2024 01:34:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125678; x=1707730478; darn=vger.kernel.org; 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=IsALcY7SVXjN//VI/pQguwi8KjWlDmDQg/LjiqJYZd0=; b=HU9Nb2/uyHGQwalTZDAF9Pk53iHHcGQmSFF3R+DwkIp3akQljNzZzkhAeZjoiAKnlw KWWSGf4BDMR7jSowS51HVJFA+K1SOTV6wxgSJhWpLfoM5gR0gZY+/C8upIopDm9MiTP3 dBkNJT0UErgrQe/IGr1zEovflTcNW8W0OS58pde+ctdqgDIu+PLeDsAtC5Qf225th4Jv ME3zodHI6gEO5jE0rKRO9dETanET90ep7/GvGvL1FvIUWZqwFsGFPKcA2q0FdGSWwFer ZI93Gi55Iukg5IUqlw6e+cw4w9Znm9lkjdOO18P3svoDY2rpy40mTWFUQgzBvNAXAiyl /9wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125678; x=1707730478; 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=IsALcY7SVXjN//VI/pQguwi8KjWlDmDQg/LjiqJYZd0=; b=nZExo7rFQ0rK7kD5j6AUNVxHRHydc3IPqp/pbYitCH+AVvrR/sXb6dYO69QmMxtAWZ yLxYZ36+B/DTPiNAo0ZENKppFYEvsgmtmoL3EEkoL/C52v/+5QnAUmPElhItCUYnl7kr fSGxNAbzrUANCEh2QfqUTeGPLKLC16m36CF3gVWrVKhxH8uCb146CAc/tGHJwofSIKS1 2HjmXALI0BnDVVFiwuy41XN+9VjzNemctroDkNVChtINYV0bSDrDPBlPiSseAu4TobKU Akllehz42I1Dr/qIzkh4CVsQMWB180a2toeQ31R5OzfNaNGnGx/Frsm1/J3WFnohMY5r qSgw== X-Gm-Message-State: AOJu0YzVcsV7IrC0kJAlTMr3Z1guapzFqSwecVyIE6TIuh7uztMR48zW v5t0IkU/Ab5i4481kgPj3bEoLjrVRsAiOXiEc+2nETg1ha01TU5fHGSN4dpMtG0= X-Google-Smtp-Source: AGHT+IHJSPbTzeawrSm1nAoPiS4N3G71Ns86R6QPG9cspUSWjZVEyhsD2m1pxHBJmfCPkCAmQllpZg== X-Received: by 2002:a19:e058:0:b0:511:553a:a963 with SMTP id g24-20020a19e058000000b00511553aa963mr234884lfj.46.1707125678325; Mon, 05 Feb 2024 01:34:38 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXTHkt/qB5FXU75JA1jOYrtC+7TPevSXOu647eXrUYKxxCr1lss+Tz7tEhMBCZMheoh1VgOSfnyR48SNftUuoObspzJ4U6YMtYp8Xlb3zVzsG9ceD2B1fDwCNkhBNs90EAUoEYYyj37VzclnsG4bqiMp4TqH5FqU0KZSPiDxE3q0cc0AS5qC0/ngPCp9347dK/67/lxRHOpQ4o0GlswOOLW6i4C6JtMonyL3Hul7DOkyOAcLuUWL1/bO7YdHGkXgvG7Fdqz+uLjzXxdNxmp2ZoaR6KHVt9+ui/iE8+txviUdrNRZZ9Y7omDdq1voIY8Cx1KZt5G4MgWOEGv0+1CyYJOnwf1rha82Q== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:37 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 14/23] gpio: cdev: replace gpiochip_get_desc() with gpio_device_get_desc() Date: Mon, 5 Feb 2024 10:34:09 +0100 Message-Id: <20240205093418.39755-15-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski gpio_device_get_desc() is the safer alternative to gpiochip_get_desc(). As we don't really need to dereference the chip pointer to retrieve the descriptors in character device code, let's use it. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 3588aaf90e45..8e37e3befa08 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -332,7 +332,7 @@ static int linehandle_create(struct gpio_device *gdev, = void __user *ip) /* Request each GPIO */ for (i =3D 0; i < handlereq.lines; i++) { u32 offset =3D handlereq.lineoffsets[i]; - struct gpio_desc *desc =3D gpiochip_get_desc(gdev->chip, offset); + struct gpio_desc *desc =3D gpio_device_get_desc(gdev, offset); =20 if (IS_ERR(desc)) { ret =3D PTR_ERR(desc); @@ -1739,7 +1739,7 @@ static int linereq_create(struct gpio_device *gdev, v= oid __user *ip) /* Request each GPIO */ for (i =3D 0; i < ulr.num_lines; i++) { u32 offset =3D ulr.offsets[i]; - struct gpio_desc *desc =3D gpiochip_get_desc(gdev->chip, offset); + struct gpio_desc *desc =3D gpio_device_get_desc(gdev, offset); =20 if (IS_ERR(desc)) { ret =3D PTR_ERR(desc); @@ -2123,7 +2123,7 @@ static int lineevent_create(struct gpio_device *gdev,= void __user *ip) lflags =3D eventreq.handleflags; eflags =3D eventreq.eventflags; =20 - desc =3D gpiochip_get_desc(gdev->chip, offset); + desc =3D gpio_device_get_desc(gdev, offset); if (IS_ERR(desc)) return PTR_ERR(desc); =20 @@ -2419,7 +2419,7 @@ static int lineinfo_get_v1(struct gpio_chardev_data *= cdev, void __user *ip, return -EFAULT; =20 /* this doubles as a range check on line_offset */ - desc =3D gpiochip_get_desc(cdev->gdev->chip, lineinfo.line_offset); + desc =3D gpio_device_get_desc(cdev->gdev, lineinfo.line_offset); if (IS_ERR(desc)) return PTR_ERR(desc); =20 @@ -2456,7 +2456,7 @@ static int lineinfo_get(struct gpio_chardev_data *cde= v, void __user *ip, if (memchr_inv(lineinfo.padding, 0, sizeof(lineinfo.padding))) return -EINVAL; =20 - desc =3D gpiochip_get_desc(cdev->gdev->chip, lineinfo.offset); + desc =3D gpio_device_get_desc(cdev->gdev, lineinfo.offset); if (IS_ERR(desc)) return PTR_ERR(desc); =20 --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA65E175BD for ; Mon, 5 Feb 2024 09:34:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125682; cv=none; b=nb0rmzFLieFFSifOz+vZ1bLFzyzrqYiwd+zOYJKjXPcFpNB4wc0VBgC0qh69JGiXCgwqXyzWGfrKTNCcv3ptTNo6KNhXA8ddhemullRmuh3P9xKOlAStIkzhHKpJBTHu1vyjtuVIWgtza2s3sts7r/S4MPsnJoawskeBbeH/GXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125682; c=relaxed/simple; bh=uoIIVRHu2uJkO9SDw8JuUKRoDUO7ImNaDoq5Rnmn41o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=O0gwnn05Yr2Cd0VMi9u4dq4C6FnYG0GsNbf0SjzNfLUanKYwzLQKQFvsXsI9FV9NKTibbrGCNWx4GA5bF3YG3nW8ywAm2wlT0pb5ZdpsN3P9webGKuBTQJ4Mwn8spj8eGJ3ppnP6Seyq0I+fMf/17eVKJPBiex0qeK/1Oz1y40k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=eRPX0c9M; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="eRPX0c9M" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-40fdddbb8b1so1367895e9.0 for ; Mon, 05 Feb 2024 01:34:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125679; x=1707730479; darn=vger.kernel.org; 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=k7MTTS1PPnO0o443gYifMTGiFsAoLhFBJ+RUlJK1fWQ=; b=eRPX0c9MNcy97yyAx1T3uuLCXlNIgW9umvNP3JhanCUCB1ORc6hZmoE4j4VBXHBl61 QfTTY0QSEZk1sZo04yahG682FzVsHoYDCTUDYaLN+D5OD2vwPIiNhJZ9ehaAfr1mzyiS +9JeBPn4dsLYfjl3l1FeXi7MzJIhiAyLgg3WG87xJC+DIBDkbSobelhLhDVuqq6RMt2Y LTb8y2UJxm6U+fA2Kp2ZWHCGMUTZZvb5JV9PIIws4DQUYqsoczTHGRW+wse8JdUea2Rp r52zpDBL1zCO5O7rIRbEQIKeGjXVvZbBCc54eF+3VSrD/R+N4TErYzBd0GDNQt4nlec9 qDMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125679; x=1707730479; 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=k7MTTS1PPnO0o443gYifMTGiFsAoLhFBJ+RUlJK1fWQ=; b=a0EiU7LnZ/YIOs5O/xU6As7Vf7NfsMJ90R0TgC41Ldqlk7NZzrnyPzXAepTP9heAqf W07hy5G9+UvWf6IAtxgQINTYyCqqvD0uai8B/N2r0rzwbTT6r1Y/qw4e2OFAuTmhb9Md mfB5oQr2336ioMctW9NwGnPHXRJoAp2mOUGKwLuIMBCPBHCHsNRd3Q6Atz/bPgpBYDaS 1+Ta32Ef16DIkUo+ZHQULczx8l61Ko9Vh1KZ3a8UQ7zqd6q8rP27mMG60YWPeTFUZH43 WjNivfLwK7i4M2xWPhHbm/jT7uQldzdeUBTL8FJFLPkRDiSJv+s9lY26Xqb/Bt0gS95y UUaA== X-Gm-Message-State: AOJu0YyBTAIaUAYk6MdOcuqEPnzTtJhrF+OhPQT1I49cqiS1UYya7qTe nTzfkEfdmmH3fzrBRjCwihfnq/GWO02tCewRP3m2YbGy4fwRmMqutTxRyrix7PM= X-Google-Smtp-Source: AGHT+IHKLS0m+gznRf7m4ewPz3qFdhpDGi5EcMyBvF51DPL4JncZsFuDNPywxKAWz7AcWuaFKKPy5Q== X-Received: by 2002:a05:600c:3b8f:b0:40f:d300:eaee with SMTP id n15-20020a05600c3b8f00b0040fd300eaeemr3235595wms.18.1707125679171; Mon, 05 Feb 2024 01:34:39 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXk7jaHjyRYsWkas0qWxQz/p3VQlAB7wKkG3+H6aFffc0ZmUGc1mt2/MfkUsz8Rf2/Q8fg+IP+u+KOSZFVjcbZd41sFlOvG/LFG7+IfiSfCYl136RixMsIEjs7hx1WuZjlzS0mdKqu/Skua9azLfhDNsYG3ELAcIYsMjJ2F1OOh4JkFDM8RdYuCCTLN9RErlSNBrAFviOMuYXWHMQntIGUGsdAPanN+Z7YECyg6jof8/C3OeiGS+O0I1WZaysma0zL4OWC6t5OOyOoWiCMKccl0fu2F//eExMctaZdRs7oZzE0+7UFn5sZzqFFS2xjmWPUpLUG0cuH459GqklTK/HP1n2aOpI9vjQ== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:38 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 15/23] gpio: cdev: don't access gdev->chip if it's not needed Date: Mon, 5 Feb 2024 10:34:10 +0100 Message-Id: <20240205093418.39755-16-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski The variable holding the number of GPIO lines is duplicated in GPIO device so read it instead of unnecessarily dereferencing the chip pointer. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 8e37e3befa08..e993c6a7215a 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2701,7 +2701,7 @@ static int gpio_chrdev_open(struct inode *inode, stru= ct file *file) if (!cdev) return -ENODEV; =20 - cdev->watched_lines =3D bitmap_zalloc(gdev->chip->ngpio, GFP_KERNEL); + cdev->watched_lines =3D bitmap_zalloc(gdev->ngpio, GFP_KERNEL); if (!cdev->watched_lines) goto out_free_cdev; =20 --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD32917BA3 for ; Mon, 5 Feb 2024 09:34:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125683; cv=none; b=jSqjo9r8NVddvV8rCW1wbNbsDpI79K3VZX4iuU5Q+4Ae5Yq5Jk6DE56n4Z6MWKy84SETU4qjiT7yVlGAU3gBIvQQZqzL/4ylqPYm086Hts6/GxTrSz9GLyO+1HtozK03VOE8bRQEk4+4TM6E9JeJwrXUM/QuC0dCoOEwt/OG+Ow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125683; c=relaxed/simple; bh=eyC1HYM9++8jEVAFNoIc4hkrxl4iukZ0gJFO/TcS1lM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dvK9b2CMupT8qLdyBPXl34Ganc+snDPnvdfdS1nmJobHs1QWHd5oHh6Q92dXN9MT9n3TkmqvATmUo5NUt6gxVrASlbPTbQSCwWISMlNRUxnK3E6VxQDaXt8Tk6q4cU5nM2nhkDsBO+qm9q59sOLibnZXYCStH+9RQsKe1Wj8+W4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=dWw4p9kU; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="dWw4p9kU" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-40fdd65a9bdso2705635e9.2 for ; Mon, 05 Feb 2024 01:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125680; x=1707730480; darn=vger.kernel.org; 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=4fizk7gLi6MsEYz29o/FD8jywGHpms/n5O2KFkgE/SM=; b=dWw4p9kUydg9enHFOM/CVcIeJ9JZKRZI8F4CXx9Tu+UmvJIkt+3HRAVZyjR20U9q82 vUY+biHeILC5MEA6AiszZI9UYZu4zPsUNX37UB2yOssBYZi6s1EOQ0JbnnhnsgUzOZYU HHkFQsDad0FggEoUsOskGFVTcFNDB8zXIetWAZouUustteGCSUFoy3Dg/h3H96TZU3kS 4KgZeJLPs89LtA8nfEesb9CyPBW+cCmxSm/iyrLed3IxnmWhb6bBbfFttpC++Rd1tQJI QISmSimtjyHRcEIr2IPM2QhzaKbSqvWUJJdk42O790doGBYpWDU/en87UQk/P1I3+k2n Efag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125680; x=1707730480; 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=4fizk7gLi6MsEYz29o/FD8jywGHpms/n5O2KFkgE/SM=; b=lX6kv4y0c5H0JUbgKaa5Zc4hZbQ06TuFUiWF9IqKdzU1NK87LNpsImjvhje5oOgS5o vRhmJbSK8pHRpjFh0j+OB4ec7dNlTU4k5MqNP45M9nuVE91/K+E3SYy1yRXTulkPeozp xuLqaYW6zYWj5G1v35RrwSuRsdanvUdiYrLVd98WaOD7dHcIYMQlqDkp0jfU3sRSRfQ5 wPB/nJrJMT6dPB3Q3tgSiw//RV7p/HS3YEMzt6skXsU8DEOaZrhlO1B9hv6++wGmZgXe BSMr6R3SZub9GRCG4BO8KBnopAmXVmbWB9/8gBI09hI3HxLJtZIGpWyBh+0hbnMIAcz2 jMeQ== X-Gm-Message-State: AOJu0YwVuHGw4t6wAsGB4dDfkBlqY0iCm+EX6BleuhckrebOseGmoBLH uQnP4kkzQoysiy/boI0arNQsqu9SaDEZ2Ow6mkyuGj48WQQIUTYY5B9rm5mKKFQ= X-Google-Smtp-Source: AGHT+IHs8NsEz1j8efT31ngqMa1MhlmQPpIvYA/AUkpcjmbj0I9bIIh8/Kf/eWarc0dkyZLPNEzXWw== X-Received: by 2002:a05:600c:4e11:b0:40f:cb9d:bbea with SMTP id b17-20020a05600c4e1100b0040fcb9dbbeamr4038067wmq.0.1707125680144; Mon, 05 Feb 2024 01:34:40 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWBl3aOBWX59ah/FQPmhhvtdeqTvaVZ1j6HnJC4Kzm8kRil+MNUNO2s0OId3ecuwtYNrW+7WfwwrMoXstcfipbTh/MqkFaiCmePXRAX8x1QWvwgNHEPJC3JZvVnxdjP7xTaP45Dtc7SulEuda7FEDRL+b/VE8C9eUg9K7hXTSnJX864Q0/hMm2h5TQlII9ldj7hvZlDap/kw39/A7gkcU7LXRq3n9ZjtTWxkO9hIV81Q9hXw8lEm4XGJnKfQvvRmKdQGSD4LDpefXhYrcZLTCXtF8WxTHKhmg0/7J5FjozChL+1lhlvvBLaMSMpFAvGGSwpIs1+Q+r/LLHkwiOHKKVHNQcgjeN5oA== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:39 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 16/23] gpio: don't dereference gdev->chip in gpiochip_setup_dev() Date: Mon, 5 Feb 2024 10:34:11 +0100 Message-Id: <20240205093418.39755-17-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski We don't need to dereference gdev->chip in gpiochip_setup_dev() as at the time it's called, the label in the associated struct gpio_device is already set. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f77f919dbad9..f8d53ebbf25b 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -719,7 +719,7 @@ static int gpiochip_setup_dev(struct gpio_device *gdev) goto err_remove_device; =20 dev_dbg(&gdev->dev, "registered GPIOs %d to %d on %s\n", gdev->base, - gdev->base + gdev->ngpio - 1, gdev->chip->label ? : "generic"); + gdev->base + gdev->ngpio - 1, gdev->label); =20 return 0; =20 --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A497E18027 for ; Mon, 5 Feb 2024 09:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125684; cv=none; b=AOBAY7eRnCbxWAD+wBf6fCCr/J5gAo67zfsE+2sdXU7bawMbz1schTU/8ZdqPlukaox95laGa/jtdIbcWx4PaR9J69Z+PQRnksZXPqxRd4VB1b+0Fz9UPEii3EFGhtJjAdF8wygYEgZJx/fJry7u79UG7XVt5TXqt2MIs0b/V0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125684; c=relaxed/simple; bh=DEm4ivJPwvyJQ3+rwUCzWKrs05E/BVn3gRvUWmQAFN4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=g1X/phDb2CefR8o/aGgPkaD65pgWqi+jKO/9rs2KLtaCDVXO29XmhtO1yOTZz8/HCP5npccDEMXg/jKmveZw/wzW3QBtjonKrhrJA8ZybLrHraLxZVLRQiprLuUSTEkr1J5B+cc/WDfFnn94tjGY/D//ucHwxPBH72tpdfK8yzY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=PZyb4/wu; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="PZyb4/wu" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-40f033c2e30so37965675e9.0 for ; Mon, 05 Feb 2024 01:34:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125681; x=1707730481; darn=vger.kernel.org; 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=VJfsBLVML9p9Iy9pV/o7OjQ6GeZUjbwVmk3zuZ2HyJg=; b=PZyb4/wuX4TCaUqA4Wksz+TjJoDLgA6L5b8sSBHxg97dbH9jJvwzBYcViteljdnNo6 x05CA8lPWScieQnZqqU4XU/GezrSTB/kjA3nwCS7mB+Lx/vS4Iheh/UCYjp5yMvFiHs8 hlskGtu64Jd78pUsQlKayd0Jucl9lwSzMEBPdBm3O8A6mlHcxI6SirOd6cM8q9YANbtC 0pfOtdFi5xMINaBetaDjhKy9/yBSt7F1xupntsv4CHPuyqNmI0/aSainfEi9+/eJ3T0V mN3T5GRBS5SI5970UTFl/lyd/RWSkbpUuPr34PKoQ9xt7Mqgdpqi70Gj70lvXlfhHF3H DoUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125681; x=1707730481; 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=VJfsBLVML9p9Iy9pV/o7OjQ6GeZUjbwVmk3zuZ2HyJg=; b=hmreysZCXCloqnxX3J+QjChFJ2OcNwie6R9XrDAN7KaW8TL8TUnNXg8BFUL619ix0u JrjsEqXUDRKyNXUO8dauwXYF1/DYgNe8vBkD5kp8FUmDsiZ9fYXDPSTLJ1OAQD88CsPi fvAnc7CXiQxIPoiAeul4pwx28di2hrhfXEVWAAgc3QPpkrFHiGXax8F6GnW+DJLF/RHj aN/9U4QEW6k6dUTanosoO3xoici3tjHDGi8g6QdF5wcNmX6OO32MJYR1SpoU+byorYo4 C5CooJFwB/FkuVRaHNPyy0KDXGQ36Uq/UlAhZvvdNYALEYxxD5yLKT/CeP3O7f2Ip1+s /bFw== X-Gm-Message-State: AOJu0Yx26TBE1EFIvzM4LtGjmCovP3QNVoIDzXpSb6Q81AFLeKaoHnZ4 WtbYCWaYft/w0gjlTvOuxI23ZPbxO4EFYoBxxrN83Evx+MdvA326bJKdl2pca0g= X-Google-Smtp-Source: AGHT+IFTk75p4T7YsB2qUfoM1Ugfl9KI9GBfXAbd4boWpGB3sTqz4xEuekxq7k9bDL7O579RyRi3fg== X-Received: by 2002:a05:600c:518e:b0:40f:ddda:4e19 with SMTP id fa14-20020a05600c518e00b0040fddda4e19mr506479wmb.9.1707125680992; Mon, 05 Feb 2024 01:34:40 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWjvm/tk38/dR++2+UOg7NwEVKczDnNOK22kyYjVAFTkO2DGlirfusYq123N8IU068HPfieFUIS/yUiCJFZTy9WOkfcVWCrbummQyXl9mA/PV7fIWijg1B9R3vFGjlEAtxZx5gZ3iQ/VWrexNNQWoZzoLJJaL+DHoYabAl+A9YY7DrudpTECMIi9ih+itfdWNQDKvFY92j7z3QCPeZWjBpij/e1nkZ9RRsYG+zVwIrR5lxfnbfcZhR4QbMBf1i3+sLXiP02vnoMs7JCZPRIjZ4Q2S/+G6GoXyf9F21akdE4JyhXh6cA/VMuU1ldTbkWVDY6+6zxuYu4ExuNGWAyrzxPPeSu8cyZfQ== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:40 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 17/23] gpio: reduce the functionality of validate_desc() Date: Mon, 5 Feb 2024 10:34:12 +0100 Message-Id: <20240205093418.39755-18-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski Checking desc->gdev->chip for NULL without holding it in place with some serializing mechanism is pointless. Remove this check. Also don't check desc->gdev for NULL as it can never happen. We'll be protecting gdev->chip with SRCU soon but we will provide a dedicated, automatic class for that. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f8d53ebbf25b..7d897c807e95 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2251,19 +2251,12 @@ static int validate_desc(const struct gpio_desc *de= sc, const char *func) { if (!desc) return 0; + if (IS_ERR(desc)) { pr_warn("%s: invalid GPIO (errorpointer)\n", func); return PTR_ERR(desc); } - if (!desc->gdev) { - pr_warn("%s: invalid GPIO (no device)\n", func); - return -EINVAL; - } - if (!desc->gdev->chip) { - dev_warn(&desc->gdev->dev, - "%s: backing chip is gone\n", func); - return 0; - } + return 1; } =20 @@ -2339,12 +2332,7 @@ static bool gpiod_free_commit(struct gpio_desc *desc) =20 void gpiod_free(struct gpio_desc *desc) { - /* - * We must not use VALIDATE_DESC_VOID() as the underlying gdev->chip - * may already be NULL but we still want to put the references. - */ - if (!desc) - return; + VALIDATE_DESC_VOID(desc); =20 if (!gpiod_free_commit(desc)) WARN_ON(1); --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94C891864D for ; Mon, 5 Feb 2024 09:34:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125685; cv=none; b=OJNcDYW0+mw2p2iov7BBbGKoojIDxNF3PhygNwrbCdU5sYGD/sp1DSdiY9OMqIQE+Lulqs0nC4dptjfs4dG6gb66r2skHL1Qs0eJ5cpaoLXaYdtKsS2FERegRMX2KOC78rZBp02+Y21ZrPE73Ks3UTecfctO9Bjy0aWChl7kyeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125685; c=relaxed/simple; bh=pEGFI4FzSuM9h9FPQ1IrcofNm0GzKPkH6oHp6XPXvQE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AawZvSYMZstW6AeXS5GB8f8HReo21XU3U7bao9GUGs8URXU7mx594xGiuNQ7MmPeqciq8ZsE0Ivp/03prEY/6nmw1hhlGBV4MIwQA4D6QBZuBCSjM9BXYkpwoqKgyZxFRGFIKArUAXzKOdI6PVufz2wbH1MUY8BL58AE7h5lYqg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=yndcTLQ0; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="yndcTLQ0" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-40fdd65a9cfso2784395e9.3 for ; Mon, 05 Feb 2024 01:34:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125682; x=1707730482; darn=vger.kernel.org; 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=ooFRRocehP/GMHGdd997Hq+dPT1Zk15K+dtqhfO9BRA=; b=yndcTLQ0J+XMpWeWrTV69r+9Jv7+XpYXtiJ+SizmO2PPad0aPD8ZHtd+SanHbaquam fW+EhxZHfBFO9+guedt4pzkoiDJXzOdPlC6Jz1xKRV7MdX7XrYbcNWwwuRKqD3jbGZHn WN4mnGLU4Fc7XqGucb/QtVpnghKEQ5oTb46cvharxyDZaBQpt+maLDSsl8CTDTeVvfxQ YmIEAHFvKvsFvjJWbCwUJqGSS+Tc6WZ/vug0+IFOB/XAT5MNFUgKRURMEN8acDiTCdLB oOcifWTRzVANKBC78/KfXIo0ehGvrapQzeRrG0ACHu0B3qEW1o+GjsguR37W23D+OdHP T4aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125682; x=1707730482; 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=ooFRRocehP/GMHGdd997Hq+dPT1Zk15K+dtqhfO9BRA=; b=QWJBvqOrj7cWmkal+Q6zM0c3EBIgwd6ihxrAza6IeWs4yIS+VPt8p36H2Cbj+5ktjG 7hnZgeB3i2OUIu7ru8/Ju9dXwCZY/cSNzlmU8P9sqQpV/FjFXVBIbcBVIFMNpaIAhmTD LNapvn2DnoEPe9X/1elBO2hk6Sds5RjxuTCMDscAAl0L65+YM0SblEsRcFgEqHgym8KN b2SGcF1ststMdbDM4lVAkAPo5gqmkAR3pd8Hi8enXs7ZF43ePtGaAGjzc1lr61nqN4fQ tFW6uDiT23s8SYWDPgQAn6lIig13vwmS4DIBfJrtyoDd2Sp9zpOVuxPXGX/Y/N2L2oma vMdw== X-Gm-Message-State: AOJu0YxR5NL1Pz1qgG/3EgnCdxSnWqXSxf1C/QLru2d0HuQ6hOCN3Qnr TdG8sOwbW7iYnP4F+I8ppQmTxV8dbIzg30DFp71Zq/YHbhsy+EtbuLpJtz1/Cjo= X-Google-Smtp-Source: AGHT+IFhcLgkx8KHMiKDvuZqNmGC8eNgjwJXoKIcgWEf6Qq0l9U2BDTDNM+uWBEonFwKj2EUg30Mww== X-Received: by 2002:a05:600c:468a:b0:40f:d738:c213 with SMTP id p10-20020a05600c468a00b0040fd738c213mr2655782wmo.29.1707125681808; Mon, 05 Feb 2024 01:34:41 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVeChOtUDPQKIzjVR3gHFJwm13T5fUfp2EvjfPDa0WJAsGA4ulrpHbHNP3ClsXHPf9p/pjCSdJ9BDfYItHn2ag2YYMH9PdOge/KVOSeui5uWnZJwmduSIulnijzimN6uT1BuwnUCCMSQ/y2CoqN8mmCLI/u0lYAG07zbiYh3EDl/Nz8fOgfDfN89X8ZFGEaX/ykGrIPR2ZBNuQet0yxFq0v+ZJdcSitIRDGmnT2yY7htzxh7T+Yd3N1lFAgjziOo6pBuIkRaVDvaOsoiajQziNN5oSlXXaTn7uqCVCvDm3OXQY51irCEEPyXNBzaaKja7uiftMiFshUuLfqmzXsuoQB4/bd8f8TDg== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:41 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 18/23] gpio: remove unnecessary checks from gpiod_to_chip() Date: Mon, 5 Feb 2024 10:34:13 +0100 Message-Id: <20240205093418.39755-19-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski We don't need to check the gdev pointer in struct gpio_desc - it's always assigned and never cleared. It's also pointless to check gdev->chip before we actually serialize access to it. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 7d897c807e95..95b480f01fca 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -214,7 +214,7 @@ EXPORT_SYMBOL_GPL(desc_to_gpio); */ struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) { - if (!desc || !desc->gdev) + if (!desc) return NULL; return desc->gdev->chip; } @@ -3499,7 +3499,7 @@ int gpiod_to_irq(const struct gpio_desc *desc) * requires this function to not return zero on an invalid descriptor * but rather a negative error number. */ - if (!desc || IS_ERR(desc) || !desc->gdev || !desc->gdev->chip) + if (!desc || IS_ERR(desc)) return -EINVAL; =20 gc =3D desc->gdev->chip; --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9207518EB8 for ; Mon, 5 Feb 2024 09:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125686; cv=none; b=BYr5tKaz/OdkLC/Owjlf+wQPNfcB+F5NAM71O0C4flqKN8AnnL4n6Z+xLUdkWMePer93LBI+9vVVb3U7lxOwnesonlx0nkUT1OaMmjVcaiQoNs1tPLVLn5VjlPpjhuaX2ARoOOXLctLEvnNL0y3yZiVWdwDwPG/eIgjfTbjK/Ds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125686; c=relaxed/simple; bh=Dy4mC9/ApSM4G2nhOEYNfhdshYRm02m6ARcUBbiiHZY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lcAhJKNjlDdxB6QtfLBpjCwWaMs32Z2ePPSc76rWc/+nazk8DMqgoCQmLiz6VZJg0RoazHPLy9pN5ghnqKh9uYP6ktcuQ3o+tUcWCUqbeansnuFsNhCgF90RojpqNX+k3R7RJsGg/Xdd8i77B4fAt1dWyyUeGTFjAJO2NXQ3Fsk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=zxXsC8LE; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="zxXsC8LE" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5111e5e4e2bso6456734e87.3 for ; Mon, 05 Feb 2024 01:34:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125682; x=1707730482; darn=vger.kernel.org; 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=iw+aFC5ArC2ijhUY9JiIEGX3/cbiqFWJyl5FMkkWhDw=; b=zxXsC8LEaBbNRHIIUAdNOr5R+GRHSZC0RhzRwdim8ICgN9J3fHCuB1ajtMV5zJSBai gT9glb/Y7X8WX1LujUDAUJ2FFtWYR7TLFOa+tLOpMfXTvCadPIdMUOy0pMzQHU4iaM+L z3O8bP4k4ekD+SR4E3ciE/Dtj+RrKFd324bIYHaEC4sr4BGqHrqBUEVA6qL00uP2SdWr +3mSMCLkwMV8kDr3yQYKfvybTEL5lcMfhU6s6NalldQMXCh765g/lwNVvO9ixBroll8y HLz9XQIg20XwBzaBfMNT9MRJXP4Ko4XVUToD3KMSqMTsK3dgMq1bLVfaj6ab/41c9UBu MljQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125682; x=1707730482; 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=iw+aFC5ArC2ijhUY9JiIEGX3/cbiqFWJyl5FMkkWhDw=; b=L7OctgnbgRJcV+4tenvUIdyyzAXDNhep5cAuUMxgApLSOvID3mXTEYJfaY4kKybR3P NP0XuJvfw1Nh8UkLeQAWw+ROv6HFB4UNejNtiDZMx+V7Ygr/53gU/A88ROLu/rkOTudY tM8C1DcFszONPsDNjF5RgfarbDVrXxR/196Gm141lhL/c+WNJLNInD6DJHGqD/isJ7yA Osgl9D+u58fqsGI3W4VkmkEsEBa7jw0sMOnIkj/aIAlOxBPe2ogxED4/oEqIgEctQDjo kH/JjyLxuUv/UI63Yux4KfhDCC83JoA3C1k8GeBCcu+G0O9CLAAf+bMTBn7+oa4JUUQZ fIxw== X-Gm-Message-State: AOJu0Yx/2mVR++z6lO6K/8BmoMTh8OEeWZp+rnGykUyCCavyBQ7DEIOG 1AoQBn7lHImT8LTPcnp3wNAbhlx5V44yXBODaoxopTeK0ClSSw9pXotdc6xdS1U= X-Google-Smtp-Source: AGHT+IH0kgu91seENjOkYZzprpiiHZskLJKVML41ZB5XP9T3vwqrG04okuAk1g3DYhSvhBfBk0+0mQ== X-Received: by 2002:a05:6512:239c:b0:511:3261:d112 with SMTP id c28-20020a056512239c00b005113261d112mr9043655lfv.9.1707125682699; Mon, 05 Feb 2024 01:34:42 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVTCt4J2ZTbN3EA1wpOUNy4BpzRJVF69tsMRM+N/P3JpQ6XRvjI01O1r4QlVcLcTm0q+KwQGQx6B4KEPf09BG7Lo9M2Hl3u/ZLoAxurWzye+beHodXs4+78XNQ750ntUeGTpazPnXyo0BaNz4nYT5rXDb4yWqu87OcwjG6peV5g4xB54Q4R4XinVQq3cMsbjTdfGnGS7zIx2S+MhiQU5BCXcV33ZOs23NjELsraFc3Xcmpfmr/64b63ai+/quKiyhShqF1xIiI8htQ8Qm7E6RPIaEqvw4/8REyKgkoEnqI4i6z3YWvUfvonjUNQBLzxsyXnVIrOOiVncdUGivf/aKm89A2i0Tg4Og== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:42 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 19/23] gpio: add the can_sleep flag to struct gpio_device Date: Mon, 5 Feb 2024 10:34:14 +0100 Message-Id: <20240205093418.39755-20-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski Duplicating the can_sleep value in GPIO device will allow us to not needlessly dereference the chip pointer in several places and reduce the number of SRCU read-only critical sections. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 11 ++++++----- drivers/gpio/gpiolib.h | 3 +++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 95b480f01fca..2f78fa9f8dbf 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -896,6 +896,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, vo= id *data, } =20 gdev->ngpio =3D gc->ngpio; + gdev->can_sleep =3D gc->can_sleep; =20 scoped_guard(mutex, &gpio_devices_lock) { /* @@ -3066,7 +3067,7 @@ int gpiod_get_raw_value(const struct gpio_desc *desc) { VALIDATE_DESC(desc); /* Should be using gpiod_get_raw_value_cansleep() */ - WARN_ON(desc->gdev->chip->can_sleep); + WARN_ON(desc->gdev->can_sleep); return gpiod_get_raw_value_commit(desc); } EXPORT_SYMBOL_GPL(gpiod_get_raw_value); @@ -3087,7 +3088,7 @@ int gpiod_get_value(const struct gpio_desc *desc) =20 VALIDATE_DESC(desc); /* Should be using gpiod_get_value_cansleep() */ - WARN_ON(desc->gdev->chip->can_sleep); + WARN_ON(desc->gdev->can_sleep); =20 value =3D gpiod_get_raw_value_commit(desc); if (value < 0) @@ -3360,7 +3361,7 @@ void gpiod_set_raw_value(struct gpio_desc *desc, int = value) { VALIDATE_DESC_VOID(desc); /* Should be using gpiod_set_raw_value_cansleep() */ - WARN_ON(desc->gdev->chip->can_sleep); + WARN_ON(desc->gdev->can_sleep); gpiod_set_raw_value_commit(desc, value); } EXPORT_SYMBOL_GPL(gpiod_set_raw_value); @@ -3401,7 +3402,7 @@ void gpiod_set_value(struct gpio_desc *desc, int valu= e) { VALIDATE_DESC_VOID(desc); /* Should be using gpiod_set_value_cansleep() */ - WARN_ON(desc->gdev->chip->can_sleep); + WARN_ON(desc->gdev->can_sleep); gpiod_set_value_nocheck(desc, value); } EXPORT_SYMBOL_GPL(gpiod_set_value); @@ -3465,7 +3466,7 @@ EXPORT_SYMBOL_GPL(gpiod_set_array_value); int gpiod_cansleep(const struct gpio_desc *desc) { VALIDATE_DESC(desc); - return desc->gdev->chip->can_sleep; + return desc->gdev->can_sleep; } EXPORT_SYMBOL_GPL(gpiod_cansleep); =20 diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 9b7afe87f1bd..43ff4931e2c3 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -34,6 +34,8 @@ * @descs: array of ngpio descriptors. * @ngpio: the number of GPIO lines on this GPIO device, equal to the size * of the @descs array. + * @can_sleep: indicate whether the GPIO chip driver's callbacks can sleep + * implying that they cannot be used from atomic context * @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assig= ned * at device creation time. * @label: a descriptive name for the GPIO device, such as the part number @@ -64,6 +66,7 @@ struct gpio_device { struct gpio_desc *descs; int base; u16 ngpio; + bool can_sleep; const char *label; void *data; struct list_head list; --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 664891802B for ; Mon, 5 Feb 2024 09:34:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125687; cv=none; b=GYtyKbXi1AkRalecbGtja8xdMKqxmGHHdY3gUfpHR432wiaLl7C7enDVbSgIYredRrXdpK0umP9Yz4bXAAvDjhQLLaUHAhFwbi7RUv8aaRp3ORvXn3MKOdrvvlvYAWn+PhwwQrbVA4A4E+b6Uc+mXAJA5AG43PyPyK2oZNiqcHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125687; c=relaxed/simple; bh=7mJd5R2FfiEUg4aI1+D/j4yKbEfikBS+gEjl/iwhNCA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DJ+qBSU2M0uZZxrO1XGYbgapscZKtds2BDTMhEU1QMyQcowLxrSbkHdAzy/g6K37UWRaOnufoLj0yrvyhmqL0Bb/ZyR4/oa26cKadxty9vAmjpgTrN5bSxVMowP7FyF4Zj4AOnBSNM+6vJxPzwKvDcflIjHHnlB4enShSbRdG7g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=EFOnRDkp; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="EFOnRDkp" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-511490772f6so1392324e87.2 for ; Mon, 05 Feb 2024 01:34:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125683; x=1707730483; darn=vger.kernel.org; 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=EfCUtQSab/f+GEUcOlTEQIAjO6ADTWtbYYTnCznFDE8=; b=EFOnRDkp0AzyqNzWQHSJTgd0l2m0EZwSGebIvXeU0SQS/fsB0MV3tv1XH7eZbmeT1S 6G6WUJKUmjUwfNh5E6uyZVnpbsg8mSomtUUZNMfjD4CZtZmgFhmIy/ZZV04KjYxDEfrJ v/VKFv3wpZIUAhxyILlfiayI2Kj3/xSkBvQ2u976iThf7XEsgNyQL2H82hGW5RAAccui IwkcqBsBWDyU4Iwftqb77vvNB/qg7qF+Tud8OTunSamKhNKSZI+KKNeHBpgHNf0FDOwI SeTFxuLW9IMMjrHzEdZfZc+wVM3wQYm7iU57gDaNGhZ3KULvhN7WELTX9GJL4gUpInud 1VuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125683; x=1707730483; 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=EfCUtQSab/f+GEUcOlTEQIAjO6ADTWtbYYTnCznFDE8=; b=HDPRbzjGcricz6aDNhySDpr3u8yVyqdhsseDIIpjbC0XlwrRVLVxYUNP1Gogh65i5/ yExntzsV73TbWTU3/uSDUpMpw8DeulJAGpwh4uP1wDkzCFkS6NquwoDbnvLWkbTuClxF Cund1n0aBJOScj7B93eTeW2QUph/03ff+dmlvqF1TJATOwufVtvZLhcnGcT9+s1zqH9p p+mVTTnjl5VyhnsCuybtAh7iBsdJ1/JvnG4T/E49UsM/+N6+6ibIFgBYZD5exvcRqt/0 WwcJc4qJ5woLxC7S5sF+3yrtJifkY3kh9sG9IXLQ0tdLRSE0hrzrtFAqJqjjJ9hlvka3 uhIQ== X-Gm-Message-State: AOJu0Yw+mYsNBrp/3YFsmb+c0QlG/lxqJaPQuvGcCLwWljwrdDpUGXtA PlKKLyUvmCy0sCqfribW4kKqeFHZikedRIR+PJw++m9wJPnlX1LBwrD2xjEId2I= X-Google-Smtp-Source: AGHT+IGbzkspZ2OxUbf5+9mtQYHG+0DglASi8UuDhWIORLHqIuJm4X1N/9W/AZO7TglbOMxo/nZ8Cw== X-Received: by 2002:a05:6512:3b27:b0:511:2e7c:768f with SMTP id f39-20020a0565123b2700b005112e7c768fmr9577478lfv.46.1707125683608; Mon, 05 Feb 2024 01:34:43 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCU40ycQ2gHSQqNLzlj+wixA3sX46WZJeEInwacBub0YUBh0qHj392LloTrzZIyWuLx667WiMDnJRNeTuP623WmzduvSr04AQZqLrZCkoB3AX5UAloP49CHvarI5HWcXvoYbWXPj2xIYdLPIekKoHs411woSyIg0B5WWKqO2OrmkRScRLnjkDBKJYdBINEhy/jf8QFsFWsRw7RLcMPM2b99dUjtU3zLHxrC8OuRF1lSEREI5QLQnG3GJvSL6luR99Thwo11m/SbBCroaL+2LXs0eyNNwi4BH9alZYSA5kVsQ8zP7TEfm/gebww/JNVS7pkxOHYyrOWHqIjyfpqzrXsRKute8BGH/Eg== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:43 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 20/23] gpio: add SRCU infrastructure to struct gpio_device Date: Mon, 5 Feb 2024 10:34:15 +0100 Message-Id: <20240205093418.39755-21-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski Add the SRCU struct to GPIO device. It will be used to serialize access to the GPIO chip pointer. Initialize and clean it up where applicable. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 13 ++++++++++--- drivers/gpio/gpiolib.h | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 2f78fa9f8dbf..c49d7a156bdd 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -680,6 +680,7 @@ static void gpiodev_release(struct device *dev) ida_free(&gpio_ida, gdev->id); kfree_const(gdev->label); kfree(gdev->descs); + cleanup_srcu_struct(&gdev->srcu); kfree(gdev); } =20 @@ -943,6 +944,10 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, v= oid *data, BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier); init_rwsem(&gdev->sem); =20 + ret =3D init_srcu_struct(&gdev->srcu); + if (ret) + goto err_remove_from_list; + #ifdef CONFIG_PINCTRL INIT_LIST_HEAD(&gdev->pin_ranges); #endif @@ -950,15 +955,15 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, = void *data, if (gc->names) { ret =3D gpiochip_set_desc_names(gc); if (ret) - goto err_remove_from_list; + goto err_cleanup_gdev_srcu; } ret =3D gpiochip_set_names(gc); if (ret) - goto err_remove_from_list; + goto err_cleanup_gdev_srcu; =20 ret =3D gpiochip_init_valid_mask(gc); if (ret) - goto err_remove_from_list; + goto err_cleanup_gdev_srcu; =20 ret =3D of_gpiochip_add(gc); if (ret) @@ -1038,6 +1043,8 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, = void *data, gpio_device_put(gdev); goto err_print_message; } +err_cleanup_gdev_srcu: + cleanup_srcu_struct(&gdev->srcu); err_remove_from_list: scoped_guard(mutex, &gpio_devices_lock) list_del_rcu(&gdev->list); diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 43ff4931e2c3..35d71e30c546 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -49,6 +49,7 @@ * @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 + * @srcu: protects the pointer to the underlying GPIO chip * @pin_ranges: range of pins served by the GPIO driver * * This state container holds most of the runtime variable data @@ -73,6 +74,7 @@ struct gpio_device { struct blocking_notifier_head line_state_notifier; struct blocking_notifier_head device_notifier; struct rw_semaphore sem; + struct srcu_struct srcu; =20 #ifdef CONFIG_PINCTRL /* --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A52E8175BC for ; Mon, 5 Feb 2024 09:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125690; cv=none; b=idkMY19k8zcGdT++LW9/xxLY6QB/LGUaKzJjdF3ziBmVcYAAoHTNp2N448HoXDzx2EeEAGf7MSHmLOfd2UKpLwWW5VzTyutTbnkZoPPQjAfpoYXhVddl85QG6aZIeNTp6/g7hYzz6YSrHMakS13hNfHFI6J+QmG6bPNs6yIcv2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125690; c=relaxed/simple; bh=8ourVLEysJ5XmEvbiPJARNgkbTUOGYcVPstK66t5LBQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iASUWrGu5b1UpnsGf2deyjJYIxnk5k1isD+kvoCq8ealnct79R6UpWThJzTR3PIlFV9Hp41OqEkg8IEBnHRbT5RKdPxM1kuPABemK/D8DilBEeZ/zL9zmqiiGHKmJuHha0NWdPmUwVDrPdIJ3u64h3rKbnaFeWgfrO0K0lek9YY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=DxWpusgM; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="DxWpusgM" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-50eac018059so4940437e87.0 for ; Mon, 05 Feb 2024 01:34:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125685; x=1707730485; darn=vger.kernel.org; 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=D36D0mH6CfPSIWqKS6UrwYoJeFTGfcveguFEIKk2pus=; b=DxWpusgMBRHNXvPBb61s2leMnR40F5GHGlAmkKI2/oxDn8mhBYtQHhzJUDjVO+aLll J9WS7gtNarWB1isx46LXgGnMN8rwYhnB1LVbmx7FDvyiNEP6kYGTvzP1Jswf74ASJ903 G7rwJvs1m2uJNiwZddoSSC5yH4PHJ69mKGP5BCLC18xHP3OjVzd5n4QVlshrwAqPrfNc KU2umEBpqCrLC5rYoBI6+ES0sdnu5cFDYW1ox+2j/Wbun+MvOZcxiApGdGqfPvnXVAd2 eTfQJGnZxs6WELc0GodqksdP3IrpqLPUHlN73MdizmADBgADOifY3ZNnKWcllcESrW/L cIuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125685; x=1707730485; 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=D36D0mH6CfPSIWqKS6UrwYoJeFTGfcveguFEIKk2pus=; b=wFjz+uUCdHbV6CIO9PNrOk1j0qM1Z714ZqsU3WtR5vqKONErg7V2dyEBoqBMwJKDY+ Wg6QUokYclDFXtGUU1+8PVmXG0Eae/sZGACBG7fDlOTPbPs4i2Xn/XiGMJ5DlBfTUrBf xmb2unNn1qU8e685/giV3RmXlSzfZeHlAyR00SOTXI45EVVrqIu0isn73GwjHL3SD8uG 7NGhe7C4Vi+ElsOC+ilLM1XHLMLhQIp26CooOfbTiCqM2lMIDeQMICbORh1RuBZh5UmG i5Xyjtkx0K9Q0DZmS1ExzrJoInYnkKFbD7DtYmvB+A/9O3bVMSDoBuhPxDNc1XSA5qEF ACeA== X-Gm-Message-State: AOJu0YxA4akUC9DoT4SACAczexo+JcwanDvJc8c2RuhXchugWmSjBwIk 1bx+843C/68UaybaDsPA2EHXZx/6cywhpJTktY4zB/m6m4T7x1a4+8HdePQg65w= X-Google-Smtp-Source: AGHT+IF4QduckI8fvBjkqmVsLesc2FHREBtsNhmPVabnSPKRD2sH+NRSg/l2bUUUwRMa3fDTkWY+0A== X-Received: by 2002:ac2:4da6:0:b0:511:499d:5dda with SMTP id h6-20020ac24da6000000b00511499d5ddamr2866843lfe.10.1707125684600; Mon, 05 Feb 2024 01:34:44 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCV59de/kiZDl5eLc5DL1x76extKa0szhl8QjDr2dPl4XdXh0nR7UA0ibKw103x0ReR7/dBEYnfCTNCmU1ss/U6/G/5L2bCHZyirudomeyR2kaOt9MJ8184M/lbAANOIm7FJu2T/VNnKx5Cl0/Nt93IJwaspzG4pm7XCtWwwm7wSNGi9wcLpJ2AmwsBp2HRtMbxdru/dpjr9iJJDJGKRsbl2MoqRN8r2u8/BfQWVLTezH3VED+YzAbMAK8Z1ZcTuiG1nIKj4AQOjQuEdyqBMiKRyHSjvyI8YKCH69wYpsFVhHiou2pwPe9n21LfZ6mosP4fbLgbKFz4VPjmn+pxqEFVz/ivCzagBYw== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:44 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 21/23] gpio: protect the pointer to gpio_chip in gpio_device with SRCU Date: Mon, 5 Feb 2024 10:34:16 +0100 Message-Id: <20240205093418.39755-22-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski Ensure we cannot crash if the GPIO device gets unregistered (and the chip pointer set to NULL) during any of the API calls. To that end: wait for all users of gdev->chip to exit their read-only SRCU critical sections in gpiochip_remove(). For brevity: add a guard class which can be instantiated at the top of every function requiring read-only access to the chip pointer and use it in all API calls taking a GPIO descriptor as argument. In places where we only deal with the GPIO device - use regular guard() helpers and rcu_dereference() for chip access. Do the same in API calls taking a const pointer to gpio_desc. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 63 +++++---- drivers/gpio/gpiolib-sysfs.c | 90 +++++++++--- drivers/gpio/gpiolib.c | 257 +++++++++++++++++++++++------------ drivers/gpio/gpiolib.h | 22 ++- 4 files changed, 298 insertions(+), 134 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index e993c6a7215a..ccdeed013f6b 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -205,9 +205,9 @@ static long linehandle_ioctl(struct file *file, unsigne= d int cmd, unsigned int i; int ret; =20 - guard(rwsem_read)(&lh->gdev->sem); + guard(srcu)(&lh->gdev->srcu); =20 - if (!lh->gdev->chip) + if (!rcu_dereference(lh->gdev->chip)) return -ENODEV; =20 switch (cmd) { @@ -1520,9 +1520,9 @@ static long linereq_ioctl(struct file *file, unsigned= int cmd, struct linereq *lr =3D file->private_data; void __user *ip =3D (void __user *)arg; =20 - guard(rwsem_read)(&lr->gdev->sem); + guard(srcu)(&lr->gdev->srcu); =20 - if (!lr->gdev->chip) + if (!rcu_dereference(lr->gdev->chip)) return -ENODEV; =20 switch (cmd) { @@ -1551,9 +1551,9 @@ static __poll_t linereq_poll(struct file *file, struct linereq *lr =3D file->private_data; __poll_t events =3D 0; =20 - guard(rwsem_read)(&lr->gdev->sem); + guard(srcu)(&lr->gdev->srcu); =20 - if (!lr->gdev->chip) + if (!rcu_dereference(lr->gdev->chip)) return EPOLLHUP | EPOLLERR; =20 poll_wait(file, &lr->wait, wait); @@ -1573,9 +1573,9 @@ static ssize_t linereq_read(struct file *file, char _= _user *buf, ssize_t bytes_read =3D 0; int ret; =20 - guard(rwsem_read)(&lr->gdev->sem); + guard(srcu)(&lr->gdev->srcu); =20 - if (!lr->gdev->chip) + if (!rcu_dereference(lr->gdev->chip)) return -ENODEV; =20 if (count < sizeof(le)) @@ -1874,9 +1874,9 @@ static __poll_t lineevent_poll(struct file *file, struct lineevent_state *le =3D file->private_data; __poll_t events =3D 0; =20 - guard(rwsem_read)(&le->gdev->sem); + guard(srcu)(&le->gdev->srcu); =20 - if (!le->gdev->chip) + if (!rcu_dereference(le->gdev->chip)) return EPOLLHUP | EPOLLERR; =20 poll_wait(file, &le->wait, wait); @@ -1912,9 +1912,9 @@ static ssize_t lineevent_read(struct file *file, char= __user *buf, ssize_t ge_size; int ret; =20 - guard(rwsem_read)(&le->gdev->sem); + guard(srcu)(&le->gdev->srcu); =20 - if (!le->gdev->chip) + if (!rcu_dereference(le->gdev->chip)) return -ENODEV; =20 /* @@ -1995,9 +1995,9 @@ static long lineevent_ioctl(struct file *file, unsign= ed int cmd, void __user *ip =3D (void __user *)arg; struct gpiohandle_data ghd; =20 - guard(rwsem_read)(&le->gdev->sem); + guard(srcu)(&le->gdev->srcu); =20 - if (!le->gdev->chip) + if (!rcu_dereference(le->gdev->chip)) return -ENODEV; =20 /* @@ -2295,10 +2295,13 @@ static void gpio_v2_line_info_changed_to_v1( static void gpio_desc_to_lineinfo(struct gpio_desc *desc, struct gpio_v2_line_info *info) { - struct gpio_chip *gc =3D desc->gdev->chip; unsigned long dflags; const char *label; =20 + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return; + memset(info, 0, sizeof(*info)); info->offset =3D gpio_chip_hwgpio(desc); =20 @@ -2331,8 +2334,8 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *d= esc, test_bit(FLAG_USED_AS_IRQ, &dflags) || test_bit(FLAG_EXPORT, &dflags) || test_bit(FLAG_SYSFS, &dflags) || - !gpiochip_line_is_valid(gc, info->offset) || - !pinctrl_gpio_can_use_line(gc, info->offset)) + !gpiochip_line_is_valid(guard.gc, info->offset) || + !pinctrl_gpio_can_use_line(guard.gc, info->offset)) info->flags |=3D GPIO_V2_LINE_FLAG_USED; =20 if (test_bit(FLAG_IS_OUT, &dflags)) @@ -2505,10 +2508,10 @@ static long gpio_ioctl(struct file *file, unsigned = int cmd, unsigned long arg) struct gpio_device *gdev =3D cdev->gdev; void __user *ip =3D (void __user *)arg; =20 - guard(rwsem_read)(&gdev->sem); + guard(srcu)(&gdev->srcu); =20 /* We fail any subsequent ioctl():s when the chip is gone */ - if (!gdev->chip) + if (!rcu_dereference(gdev->chip)) return -ENODEV; =20 /* Fill in the struct and pass to userspace */ @@ -2591,9 +2594,9 @@ static __poll_t lineinfo_watch_poll(struct file *file, struct gpio_chardev_data *cdev =3D file->private_data; __poll_t events =3D 0; =20 - guard(rwsem_read)(&cdev->gdev->sem); + guard(srcu)(&cdev->gdev->srcu); =20 - if (!cdev->gdev->chip) + if (!rcu_dereference(cdev->gdev->chip)) return EPOLLHUP | EPOLLERR; =20 poll_wait(file, &cdev->wait, pollt); @@ -2614,9 +2617,9 @@ static ssize_t lineinfo_watch_read(struct file *file,= char __user *buf, int ret; size_t event_size; =20 - guard(rwsem_read)(&cdev->gdev->sem); + guard(srcu)(&cdev->gdev->srcu); =20 - if (!cdev->gdev->chip) + if (!rcu_dereference(cdev->gdev->chip)) return -ENODEV; =20 #ifndef CONFIG_GPIO_CDEV_V1 @@ -2691,10 +2694,10 @@ static int gpio_chrdev_open(struct inode *inode, st= ruct file *file) struct gpio_chardev_data *cdev; int ret =3D -ENOMEM; =20 - guard(rwsem_read)(&gdev->sem); + guard(srcu)(&gdev->srcu); =20 /* Fail on open if the backing gpiochip is gone */ - if (!gdev->chip) + if (!rcu_dereference(gdev->chip)) return -ENODEV; =20 cdev =3D kzalloc(sizeof(*cdev), GFP_KERNEL); @@ -2781,6 +2784,7 @@ static const struct file_operations gpio_fileops =3D { =20 int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt) { + struct gpio_chip *gc; int ret; =20 cdev_init(&gdev->chrdev, &gpio_fileops); @@ -2791,8 +2795,13 @@ int gpiolib_cdev_register(struct gpio_device *gdev, = dev_t devt) if (ret) return ret; =20 - chip_dbg(gdev->chip, "added GPIO chardev (%d:%d)\n", - MAJOR(devt), gdev->id); + guard(srcu)(&gdev->srcu); + + gc =3D rcu_dereference(gdev->chip); + if (!gc) + return -ENODEV; + + chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id); =20 return 0; } diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 654a5bc53047..15349f92d0ec 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -171,6 +171,10 @@ static int gpio_sysfs_request_irq(struct device *dev, = unsigned char flags) unsigned long irq_flags; int ret; =20 + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; + data->irq =3D gpiod_to_irq(desc); if (data->irq < 0) return -EIO; @@ -195,7 +199,7 @@ static int gpio_sysfs_request_irq(struct device *dev, u= nsigned char flags) * Remove this redundant call (along with the corresponding * unlock) when those drivers have been fixed. */ - ret =3D gpiochip_lock_as_irq(desc->gdev->chip, gpio_chip_hwgpio(desc)); + ret =3D gpiochip_lock_as_irq(guard.gc, gpio_chip_hwgpio(desc)); if (ret < 0) goto err_put_kn; =20 @@ -209,7 +213,7 @@ static int gpio_sysfs_request_irq(struct device *dev, u= nsigned char flags) return 0; =20 err_unlock: - gpiochip_unlock_as_irq(desc->gdev->chip, gpio_chip_hwgpio(desc)); + gpiochip_unlock_as_irq(guard.gc, gpio_chip_hwgpio(desc)); err_put_kn: sysfs_put(data->value_kn); =20 @@ -225,9 +229,13 @@ static void gpio_sysfs_free_irq(struct device *dev) struct gpiod_data *data =3D dev_get_drvdata(dev); struct gpio_desc *desc =3D data->desc; =20 + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return; + data->irq_flags =3D 0; free_irq(data->irq, data); - gpiochip_unlock_as_irq(desc->gdev->chip, gpio_chip_hwgpio(desc)); + gpiochip_unlock_as_irq(guard.gc, gpio_chip_hwgpio(desc)); sysfs_put(data->value_kn); } =20 @@ -401,27 +409,48 @@ static const struct attribute_group *gpio_groups[] = =3D { static ssize_t base_show(struct device *dev, struct device_attribute *attr, char *buf) { - const struct gpio_device *gdev =3D dev_get_drvdata(dev); + struct gpio_device *gdev =3D dev_get_drvdata(dev); + struct gpio_chip *gc; =20 - return sysfs_emit(buf, "%d\n", gdev->chip->base); + guard(srcu)(&gdev->srcu); + + gc =3D rcu_dereference(gdev->chip); + if (!gc) + return -ENODEV; + + return sysfs_emit(buf, "%d\n", gc->base); } static DEVICE_ATTR_RO(base); =20 static ssize_t label_show(struct device *dev, struct device_attribute *attr, char *buf) { - const struct gpio_device *gdev =3D dev_get_drvdata(dev); + struct gpio_device *gdev =3D dev_get_drvdata(dev); + struct gpio_chip *gc; =20 - return sysfs_emit(buf, "%s\n", gdev->chip->label ?: ""); + guard(srcu)(&gdev->srcu); + + gc =3D rcu_dereference(gdev->chip); + if (!gc) + return -ENODEV; + + return sysfs_emit(buf, "%s\n", gc->label ?: ""); } static DEVICE_ATTR_RO(label); =20 static ssize_t ngpio_show(struct device *dev, struct device_attribute *attr, char *buf) { - const struct gpio_device *gdev =3D dev_get_drvdata(dev); + struct gpio_device *gdev =3D dev_get_drvdata(dev); + struct gpio_chip *gc; =20 - return sysfs_emit(buf, "%u\n", gdev->chip->ngpio); + guard(srcu)(&gdev->srcu); + + gc =3D rcu_dereference(gdev->chip); + if (!gc) + return -ENODEV; + + return sysfs_emit(buf, "%u\n", gc->ngpio); } static DEVICE_ATTR_RO(ngpio); =20 @@ -444,13 +473,12 @@ static ssize_t export_store(const struct class *class, const char *buf, size_t len) { struct gpio_desc *desc; - struct gpio_chip *gc; int status, offset; long gpio; =20 status =3D kstrtol(buf, 0, &gpio); - if (status < 0) - goto done; + if (status) + return status; =20 desc =3D gpio_to_desc(gpio); /* reject invalid GPIOs */ @@ -458,9 +486,13 @@ static ssize_t export_store(const struct class *class, pr_warn("%s: invalid GPIO %ld\n", __func__, gpio); return -EINVAL; } - gc =3D desc->gdev->chip; + + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; + offset =3D gpio_chip_hwgpio(desc); - if (!gpiochip_line_is_valid(gc, offset)) { + if (!gpiochip_line_is_valid(guard.gc, offset)) { pr_warn("%s: GPIO %ld masked\n", __func__, gpio); return -EINVAL; } @@ -563,7 +595,6 @@ int gpiod_export(struct gpio_desc *desc, bool direction= _may_change) const char *ioname =3D NULL; struct gpio_device *gdev; struct gpiod_data *data; - struct gpio_chip *chip; struct device *dev; int status, offset; =20 @@ -578,16 +609,19 @@ int gpiod_export(struct gpio_desc *desc, bool directi= on_may_change) return -EINVAL; } =20 + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; + if (!test_and_set_bit(FLAG_EXPORT, &desc->flags)) return -EPERM; =20 gdev =3D desc->gdev; - chip =3D gdev->chip; =20 mutex_lock(&sysfs_lock); =20 /* check if chip is being removed */ - if (!chip || !gdev->mockdev) { + if (!gdev->mockdev) { status =3D -ENODEV; goto err_unlock; } @@ -606,14 +640,14 @@ int gpiod_export(struct gpio_desc *desc, bool directi= on_may_change) =20 data->desc =3D desc; mutex_init(&data->mutex); - if (chip->direction_input && chip->direction_output) + if (guard.gc->direction_input && guard.gc->direction_output) data->direction_can_change =3D direction_may_change; else data->direction_can_change =3D false; =20 offset =3D gpio_chip_hwgpio(desc); - if (chip->names && chip->names[offset]) - ioname =3D chip->names[offset]; + if (guard.gc->names && guard.gc->names[offset]) + ioname =3D guard.gc->names[offset]; =20 dev =3D device_create_with_groups(&gpio_class, &gdev->dev, MKDEV(0, 0), data, gpio_groups, @@ -728,7 +762,7 @@ EXPORT_SYMBOL_GPL(gpiod_unexport); =20 int gpiochip_sysfs_register(struct gpio_device *gdev) { - struct gpio_chip *chip =3D gdev->chip; + struct gpio_chip *chip; struct device *parent; struct device *dev; =20 @@ -741,6 +775,12 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) if (!class_is_registered(&gpio_class)) return 0; =20 + guard(srcu)(&gdev->srcu); + + chip =3D rcu_dereference(gdev->chip); + if (!chip) + return -ENODEV; + /* * For sysfs backward compatibility we need to preserve this * preferred parenting to the gpio_chip parent field, if set. @@ -767,7 +807,7 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) void gpiochip_sysfs_unregister(struct gpio_device *gdev) { struct gpio_desc *desc; - struct gpio_chip *chip =3D gdev->chip; + struct gpio_chip *chip; =20 scoped_guard(mutex, &sysfs_lock) { if (!gdev->mockdev) @@ -779,6 +819,12 @@ void gpiochip_sysfs_unregister(struct gpio_device *gde= v) gdev->mockdev =3D NULL; } =20 + guard(srcu)(&gdev->srcu); + + chip =3D rcu_dereference(gdev->chip); + if (chip) + return; + /* unregister gpiod class devices owned by sysfs */ for_each_gpio_desc_with_flag(chip, desc, FLAG_SYSFS) { gpiod_unexport(desc); diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index c49d7a156bdd..89e1c98b0bda 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -216,7 +216,7 @@ struct gpio_chip *gpiod_to_chip(const struct gpio_desc = *desc) { if (!desc) return NULL; - return desc->gdev->chip; + return rcu_dereference(desc->gdev->chip); } EXPORT_SYMBOL_GPL(gpiod_to_chip); =20 @@ -285,7 +285,7 @@ EXPORT_SYMBOL(gpio_device_get_label); */ struct gpio_chip *gpio_device_get_chip(struct gpio_device *gdev) { - return gdev->chip; + return rcu_dereference(gdev->chip); } EXPORT_SYMBOL_GPL(gpio_device_get_chip); =20 @@ -325,12 +325,21 @@ static int gpiochip_find_base_unlocked(int ngpio) */ int gpiod_get_direction(struct gpio_desc *desc) { - struct gpio_chip *gc; unsigned long flags; unsigned int offset; int ret; =20 - gc =3D gpiod_to_chip(desc); + if (!desc) + /* Sane default is INPUT. */ + return 1; + + if (IS_ERR(desc)) + return -EINVAL; + + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; + offset =3D gpio_chip_hwgpio(desc); flags =3D READ_ONCE(desc->flags); =20 @@ -342,10 +351,10 @@ int gpiod_get_direction(struct gpio_desc *desc) test_bit(FLAG_IS_OUT, &flags)) return 0; =20 - if (!gc->get_direction) + if (!guard.gc->get_direction) return -ENOTSUPP; =20 - ret =3D gc->get_direction(gc, offset); + ret =3D guard.gc->get_direction(guard.gc, offset); if (ret < 0) return ret; =20 @@ -421,6 +430,7 @@ static struct gpio_desc *gpio_name_to_desc(const char *= const name) { struct gpio_device *gdev; struct gpio_desc *desc; + struct gpio_chip *gc; =20 if (!name) return NULL; @@ -429,7 +439,13 @@ static struct gpio_desc *gpio_name_to_desc(const char = * const name) =20 list_for_each_entry_srcu(gdev, &gpio_devices, list, srcu_read_lock_held(&gpio_devices_srcu)) { - for_each_gpio_desc(gdev->chip, desc) { + guard(srcu)(&gdev->srcu); + + gc =3D rcu_dereference(gdev->chip); + if (!gc) + continue; + + for_each_gpio_desc(gc, desc) { if (desc->name && !strcmp(desc->name, name)) return desc; } @@ -847,7 +863,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, vo= id *data, return -ENOMEM; gdev->dev.bus =3D &gpio_bus_type; gdev->dev.parent =3D gc->parent; - gdev->chip =3D gc; + rcu_assign_pointer(gdev->chip, gc); =20 gc->gpiodev =3D gdev; gpiochip_set_data(gc, data); @@ -1087,7 +1103,8 @@ void gpiochip_remove(struct gpio_chip *gc) gpiochip_sysfs_unregister(gdev); gpiochip_free_hogs(gc); /* Numb the device, cancelling all outstanding operations */ - gdev->chip =3D NULL; + rcu_assign_pointer(gdev->chip, NULL); + synchronize_srcu(&gdev->srcu); gpiochip_irqchip_remove(gc); acpi_gpiochip_remove(gc); of_gpiochip_remove(gc); @@ -1150,6 +1167,7 @@ struct gpio_device *gpio_device_find(void *data, void *data)) { struct gpio_device *gdev; + struct gpio_chip *gc; =20 /* * Not yet but in the future the spinlock below will become a mutex. @@ -1160,8 +1178,13 @@ struct gpio_device *gpio_device_find(void *data, =20 guard(srcu)(&gpio_devices_srcu); =20 - list_for_each_entry(gdev, &gpio_devices, list) { - if (gdev->chip && match(gdev->chip, data)) + list_for_each_entry_srcu(gdev, &gpio_devices, list, + srcu_read_lock_held(&gpio_devices_srcu)) { + guard(srcu)(&gdev->srcu); + + gc =3D rcu_dereference(gdev->chip); + + if (gc && match(gc, data)) return gpio_device_get(gdev); } =20 @@ -2208,10 +2231,13 @@ EXPORT_SYMBOL_GPL(gpiochip_remove_pin_ranges); */ static int gpiod_request_commit(struct gpio_desc *desc, const char *label) { - struct gpio_chip *gc =3D desc->gdev->chip; unsigned int offset; int ret; =20 + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; + if (test_and_set_bit(FLAG_REQUESTED, &desc->flags)) return -EBUSY; =20 @@ -2225,17 +2251,17 @@ static int gpiod_request_commit(struct gpio_desc *d= esc, const char *label) * before IRQs are enabled, for non-sleeping (SOC) GPIOs. */ =20 - if (gc->request) { + if (guard.gc->request) { offset =3D gpio_chip_hwgpio(desc); - if (gpiochip_line_is_valid(gc, offset)) - ret =3D gc->request(gc, offset); + if (gpiochip_line_is_valid(guard.gc, offset)) + ret =3D guard.gc->request(guard.gc, offset); else ret =3D -EINVAL; if (ret) goto out_clear_bit; } =20 - if (gc->get_direction) + if (guard.gc->get_direction) gpiod_get_direction(desc); =20 ret =3D desc_set_label(desc, label ? : "?"); @@ -2302,18 +2328,18 @@ int gpiod_request(struct gpio_desc *desc, const cha= r *label) =20 static bool gpiod_free_commit(struct gpio_desc *desc) { - struct gpio_chip *gc; unsigned long flags; bool ret =3D false; =20 might_sleep(); =20 - gc =3D desc->gdev->chip; + CLASS(gpio_chip_guard, guard)(desc); + flags =3D READ_ONCE(desc->flags); =20 - if (gc && test_bit(FLAG_REQUESTED, &flags)) { - if (gc->free) - gc->free(gc, gpio_chip_hwgpio(desc)); + if (guard.gc && test_bit(FLAG_REQUESTED, &flags)) { + if (guard.gc->free) + guard.gc->free(guard.gc, gpio_chip_hwgpio(desc)); =20 clear_bit(FLAG_ACTIVE_LOW, &flags); clear_bit(FLAG_REQUESTED, &flags); @@ -2470,11 +2496,14 @@ static int gpio_set_config_with_argument(struct gpi= o_desc *desc, enum pin_config_param mode, u32 argument) { - struct gpio_chip *gc =3D desc->gdev->chip; unsigned long config; =20 + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; + config =3D pinconf_to_config_packed(mode, argument); - return gpio_do_set_config(gc, gpio_chip_hwgpio(desc), config); + return gpio_do_set_config(guard.gc, gpio_chip_hwgpio(desc), config); } =20 static int gpio_set_config_with_argument_optional(struct gpio_desc *desc, @@ -2564,18 +2593,20 @@ int gpio_set_debounce_timeout(struct gpio_desc *des= c, unsigned int debounce) */ int gpiod_direction_input(struct gpio_desc *desc) { - struct gpio_chip *gc; int ret =3D 0; =20 VALIDATE_DESC(desc); - gc =3D desc->gdev->chip; + + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; =20 /* * It is legal to have no .get() and .direction_input() specified if * the chip is output-only, but you can't specify .direction_input() * and not support the .get() operation, that doesn't make sense. */ - if (!gc->get && gc->direction_input) { + if (!guard.gc->get && guard.gc->direction_input) { gpiod_warn(desc, "%s: missing get() but have direction_input()\n", __func__); @@ -2588,10 +2619,12 @@ int gpiod_direction_input(struct gpio_desc *desc) * direction (if .get_direction() is supported) else we silently * assume we are in input mode after this. */ - if (gc->direction_input) { - ret =3D gc->direction_input(gc, gpio_chip_hwgpio(desc)); - } else if (gc->get_direction && - (gc->get_direction(gc, gpio_chip_hwgpio(desc)) !=3D 1)) { + if (guard.gc->direction_input) { + ret =3D guard.gc->direction_input(guard.gc, + gpio_chip_hwgpio(desc)); + } else if (guard.gc->get_direction && + (guard.gc->get_direction(guard.gc, + gpio_chip_hwgpio(desc)) !=3D 1)) { gpiod_warn(desc, "%s: missing direction_input() operation and line is output\n", __func__); @@ -2610,28 +2643,31 @@ EXPORT_SYMBOL_GPL(gpiod_direction_input); =20 static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int v= alue) { - struct gpio_chip *gc =3D desc->gdev->chip; - int val =3D !!value; - int ret =3D 0; + int val =3D !!value, ret =3D 0; + + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; =20 /* * It's OK not to specify .direction_output() if the gpiochip is * output-only, but if there is then not even a .set() operation it * is pretty tricky to drive the output line. */ - if (!gc->set && !gc->direction_output) { + if (!guard.gc->set && !guard.gc->direction_output) { gpiod_warn(desc, "%s: missing set() and direction_output() operations\n", __func__); return -EIO; } =20 - if (gc->direction_output) { - ret =3D gc->direction_output(gc, gpio_chip_hwgpio(desc), val); + if (guard.gc->direction_output) { + ret =3D guard.gc->direction_output(guard.gc, + gpio_chip_hwgpio(desc), val); } else { /* Check that we are in output mode if we can */ - if (gc->get_direction && - gc->get_direction(gc, gpio_chip_hwgpio(desc))) { + if (guard.gc->get_direction && + guard.gc->get_direction(guard.gc, gpio_chip_hwgpio(desc))) { gpiod_warn(desc, "%s: missing direction_output() operation\n", __func__); @@ -2641,7 +2677,7 @@ static int gpiod_direction_output_raw_commit(struct g= pio_desc *desc, int value) * If we can't actively set the direction, we are some * output-only chip, so just drive the output as desired. */ - gc->set(gc, gpio_chip_hwgpio(desc), val); + guard.gc->set(guard.gc, gpio_chip_hwgpio(desc), val); } =20 if (!ret) @@ -2757,17 +2793,20 @@ EXPORT_SYMBOL_GPL(gpiod_direction_output); int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long fla= gs) { int ret =3D 0; - struct gpio_chip *gc; =20 VALIDATE_DESC(desc); =20 - gc =3D desc->gdev->chip; - if (!gc->en_hw_timestamp) { + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; + + if (!guard.gc->en_hw_timestamp) { gpiod_warn(desc, "%s: hw ts not supported\n", __func__); return -ENOTSUPP; } =20 - ret =3D gc->en_hw_timestamp(gc, gpio_chip_hwgpio(desc), flags); + ret =3D guard.gc->en_hw_timestamp(guard.gc, + gpio_chip_hwgpio(desc), flags); if (ret) gpiod_warn(desc, "%s: hw ts request failed\n", __func__); =20 @@ -2786,17 +2825,20 @@ EXPORT_SYMBOL_GPL(gpiod_enable_hw_timestamp_ns); int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long fl= ags) { int ret =3D 0; - struct gpio_chip *gc; =20 VALIDATE_DESC(desc); =20 - gc =3D desc->gdev->chip; - if (!gc->dis_hw_timestamp) { + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; + + if (!guard.gc->dis_hw_timestamp) { gpiod_warn(desc, "%s: hw ts not supported\n", __func__); return -ENOTSUPP; } =20 - ret =3D gc->dis_hw_timestamp(gc, gpio_chip_hwgpio(desc), flags); + ret =3D guard.gc->dis_hw_timestamp(guard.gc, gpio_chip_hwgpio(desc), + flags); if (ret) gpiod_warn(desc, "%s: hw ts release failed\n", __func__); =20 @@ -2815,12 +2857,13 @@ EXPORT_SYMBOL_GPL(gpiod_disable_hw_timestamp_ns); */ int gpiod_set_config(struct gpio_desc *desc, unsigned long config) { - struct gpio_chip *gc; - VALIDATE_DESC(desc); - gc =3D desc->gdev->chip; =20 - return gpio_do_set_config(gc, gpio_chip_hwgpio(desc), config); + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; + + return gpio_do_set_config(guard.gc, gpio_chip_hwgpio(desc), config); } EXPORT_SYMBOL_GPL(gpiod_set_config); =20 @@ -2918,10 +2961,19 @@ static int gpio_chip_get_value(struct gpio_chip *gc= , const struct gpio_desc *des =20 static int gpiod_get_raw_value_commit(const struct gpio_desc *desc) { + struct gpio_device *gdev; struct gpio_chip *gc; int value; =20 - gc =3D desc->gdev->chip; + /* FIXME Unable to use gpio_chip_guard due to const desc. */ + gdev =3D desc->gdev; + + guard(srcu)(&gdev->srcu); + + gc =3D rcu_dereference(gdev->chip); + if (!gc) + return -ENODEV; + value =3D gpio_chip_get_value(gc, desc); value =3D value < 0 ? value : !!value; trace_gpio_value(desc_to_gpio(desc), 1, value); @@ -2947,6 +2999,14 @@ static int gpio_chip_get_multiple(struct gpio_chip *= gc, return -EIO; } =20 +/* The 'other' chip must be protected with its GPIO device's SRCU. */ +static bool gpio_device_chip_cmp(struct gpio_device *gdev, struct gpio_chi= p *gc) +{ + guard(srcu)(&gdev->srcu); + + return gc =3D=3D rcu_dereference(gdev->chip); +} + int gpiod_get_array_value_complex(bool raw, bool can_sleep, unsigned int array_size, struct gpio_desc **desc_array, @@ -2984,33 +3044,36 @@ int gpiod_get_array_value_complex(bool raw, bool ca= n_sleep, } =20 while (i < array_size) { - struct gpio_chip *gc =3D desc_array[i]->gdev->chip; DECLARE_BITMAP(fastpath_mask, FASTPATH_NGPIO); DECLARE_BITMAP(fastpath_bits, FASTPATH_NGPIO); unsigned long *mask, *bits; int first, j; =20 - if (likely(gc->ngpio <=3D FASTPATH_NGPIO)) { + CLASS(gpio_chip_guard, guard)(desc_array[i]); + if (!guard.gc) + return -ENODEV; + + if (likely(guard.gc->ngpio <=3D FASTPATH_NGPIO)) { mask =3D fastpath_mask; bits =3D fastpath_bits; } else { gfp_t flags =3D can_sleep ? GFP_KERNEL : GFP_ATOMIC; =20 - mask =3D bitmap_alloc(gc->ngpio, flags); + mask =3D bitmap_alloc(guard.gc->ngpio, flags); if (!mask) return -ENOMEM; =20 - bits =3D bitmap_alloc(gc->ngpio, flags); + bits =3D bitmap_alloc(guard.gc->ngpio, flags); if (!bits) { bitmap_free(mask); return -ENOMEM; } } =20 - bitmap_zero(mask, gc->ngpio); + bitmap_zero(mask, guard.gc->ngpio); =20 if (!can_sleep) - WARN_ON(gc->can_sleep); + WARN_ON(guard.gc->can_sleep); =20 /* collect all inputs belonging to the same chip */ first =3D i; @@ -3025,9 +3088,9 @@ int gpiod_get_array_value_complex(bool raw, bool can_= sleep, i =3D find_next_zero_bit(array_info->get_mask, array_size, i); } while ((i < array_size) && - (desc_array[i]->gdev->chip =3D=3D gc)); + gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc)); =20 - ret =3D gpio_chip_get_multiple(gc, mask, bits); + ret =3D gpio_chip_get_multiple(guard.gc, mask, bits); if (ret) { if (mask !=3D fastpath_mask) bitmap_free(mask); @@ -3168,14 +3231,16 @@ EXPORT_SYMBOL_GPL(gpiod_get_array_value); */ static void gpio_set_open_drain_value_commit(struct gpio_desc *desc, bool = value) { - int ret =3D 0; - struct gpio_chip *gc =3D desc->gdev->chip; - int offset =3D gpio_chip_hwgpio(desc); + int ret =3D 0, offset =3D gpio_chip_hwgpio(desc); + + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return; =20 if (value) { - ret =3D gc->direction_input(gc, offset); + ret =3D guard.gc->direction_input(guard.gc, offset); } else { - ret =3D gc->direction_output(gc, offset, 0); + ret =3D guard.gc->direction_output(guard.gc, offset, 0); if (!ret) set_bit(FLAG_IS_OUT, &desc->flags); } @@ -3193,16 +3258,18 @@ static void gpio_set_open_drain_value_commit(struct= gpio_desc *desc, bool value) */ static void gpio_set_open_source_value_commit(struct gpio_desc *desc, bool= value) { - int ret =3D 0; - struct gpio_chip *gc =3D desc->gdev->chip; - int offset =3D gpio_chip_hwgpio(desc); + int ret =3D 0, offset =3D gpio_chip_hwgpio(desc); + + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return; =20 if (value) { - ret =3D gc->direction_output(gc, offset, 1); + ret =3D guard.gc->direction_output(guard.gc, offset, 1); if (!ret) set_bit(FLAG_IS_OUT, &desc->flags); } else { - ret =3D gc->direction_input(gc, offset); + ret =3D guard.gc->direction_input(guard.gc, offset); } trace_gpio_direction(desc_to_gpio(desc), !value, ret); if (ret < 0) @@ -3213,11 +3280,12 @@ static void gpio_set_open_source_value_commit(struc= t gpio_desc *desc, bool value =20 static void gpiod_set_raw_value_commit(struct gpio_desc *desc, bool value) { - struct gpio_chip *gc; + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return; =20 - gc =3D desc->gdev->chip; trace_gpio_value(desc_to_gpio(desc), 0, value); - gc->set(gc, gpio_chip_hwgpio(desc), value); + guard.gc->set(guard.gc, gpio_chip_hwgpio(desc), value); } =20 /* @@ -3278,33 +3346,36 @@ int gpiod_set_array_value_complex(bool raw, bool ca= n_sleep, } =20 while (i < array_size) { - struct gpio_chip *gc =3D desc_array[i]->gdev->chip; DECLARE_BITMAP(fastpath_mask, FASTPATH_NGPIO); DECLARE_BITMAP(fastpath_bits, FASTPATH_NGPIO); unsigned long *mask, *bits; int count =3D 0; =20 - if (likely(gc->ngpio <=3D FASTPATH_NGPIO)) { + CLASS(gpio_chip_guard, guard)(desc_array[i]); + if (!guard.gc) + return -ENODEV; + + if (likely(guard.gc->ngpio <=3D FASTPATH_NGPIO)) { mask =3D fastpath_mask; bits =3D fastpath_bits; } else { gfp_t flags =3D can_sleep ? GFP_KERNEL : GFP_ATOMIC; =20 - mask =3D bitmap_alloc(gc->ngpio, flags); + mask =3D bitmap_alloc(guard.gc->ngpio, flags); if (!mask) return -ENOMEM; =20 - bits =3D bitmap_alloc(gc->ngpio, flags); + bits =3D bitmap_alloc(guard.gc->ngpio, flags); if (!bits) { bitmap_free(mask); return -ENOMEM; } } =20 - bitmap_zero(mask, gc->ngpio); + bitmap_zero(mask, guard.gc->ngpio); =20 if (!can_sleep) - WARN_ON(gc->can_sleep); + WARN_ON(guard.gc->can_sleep); =20 do { struct gpio_desc *desc =3D desc_array[i]; @@ -3340,10 +3411,10 @@ int gpiod_set_array_value_complex(bool raw, bool ca= n_sleep, i =3D find_next_zero_bit(array_info->set_mask, array_size, i); } while ((i < array_size) && - (desc_array[i]->gdev->chip =3D=3D gc)); + gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc)); /* push collected bits to outputs */ if (count !=3D 0) - gpio_chip_set_multiple(gc, mask, bits); + gpio_chip_set_multiple(guard.gc, mask, bits); =20 if (mask !=3D fastpath_mask) bitmap_free(mask); @@ -3499,6 +3570,7 @@ EXPORT_SYMBOL_GPL(gpiod_set_consumer_name); */ int gpiod_to_irq(const struct gpio_desc *desc) { + struct gpio_device *gdev; struct gpio_chip *gc; int offset; =20 @@ -3510,7 +3582,13 @@ int gpiod_to_irq(const struct gpio_desc *desc) if (!desc || IS_ERR(desc)) return -EINVAL; =20 - gc =3D desc->gdev->chip; + gdev =3D desc->gdev; + /* FIXME Cannot use gpio_chip_guard due to const desc. */ + guard(srcu)(&gdev->srcu); + gc =3D rcu_dereference(gdev->chip); + if (!gc) + return -ENODEV; + offset =3D gpio_chip_hwgpio(desc); if (gc->to_irq) { int retirq =3D gc->to_irq(gc, offset); @@ -4690,12 +4768,20 @@ core_initcall(gpiolib_dev_init); =20 static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev) { - struct gpio_chip *gc =3D gdev->chip; bool active_low, is_irq, is_out; unsigned int gpio =3D gdev->base; struct gpio_desc *desc; + struct gpio_chip *gc; int value; =20 + guard(srcu)(&gdev->srcu); + + gc =3D rcu_dereference(gdev->chip); + if (!gc) { + seq_puts(s, "Underlying GPIO chip is gone\n"); + return; + } + for_each_gpio_desc(gc, desc) { guard(srcu)(&desc->srcu); if (test_bit(FLAG_REQUESTED, &desc->flags)) { @@ -4761,9 +4847,12 @@ static void gpiolib_seq_stop(struct seq_file *s, voi= d *v) static int gpiolib_seq_show(struct seq_file *s, void *v) { struct gpio_device *gdev =3D v; - struct gpio_chip *gc =3D gdev->chip; + struct gpio_chip *gc; struct device *parent; =20 + guard(srcu)(&gdev->srcu); + + gc =3D rcu_dereference(gdev->chip); if (!gc) { seq_printf(s, "%s%s: (dangling chip)", (char *)s->private, dev_name(&gdev->dev)); diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 35d71e30c546..b3810f7d286a 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -63,7 +63,7 @@ struct gpio_device { int id; struct device *mockdev; struct module *owner; - struct gpio_chip *chip; + struct gpio_chip __rcu *chip; struct gpio_desc *descs; int base; u16 ngpio; @@ -193,6 +193,26 @@ struct gpio_desc { =20 #define gpiod_not_found(desc) (IS_ERR(desc) && PTR_ERR(desc) =3D=3D -ENOE= NT) =20 +struct gpio_chip_guard { + struct gpio_device *gdev; + struct gpio_chip *gc; + int idx; +}; + +DEFINE_CLASS(gpio_chip_guard, + struct gpio_chip_guard, + srcu_read_unlock(&_T.gdev->srcu, _T.idx), + ({ + struct gpio_chip_guard _guard; + + _guard.gdev =3D desc->gdev; + _guard.idx =3D srcu_read_lock(&_guard.gdev->srcu); + _guard.gc =3D rcu_dereference(_guard.gdev->chip); + + _guard; + }), + struct gpio_desc *desc) + int gpiod_request(struct gpio_desc *desc, const char *label); void gpiod_free(struct gpio_desc *desc); =20 --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EC901B80C for ; Mon, 5 Feb 2024 09:34:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125689; cv=none; b=nngdVD3dKMLSppMsrRt/jnH/eJcKOPd/1+W8mwEhur5nVq5PWDRH8FrlAdP5wHH0wx6ZC0PTvQqpRkkGeLfRU13l2WFgsNnLkVaHC/PCqZzDk4wuMnV5IaLp9eRmyozLynKTsvIC47S3kFflI+jtuHnPGf+IRMuz6eszwA5Plfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125689; c=relaxed/simple; bh=sR04Q3usSUpqWJ46O/KNDsk7BbO6EIW7XnGPi8eaia8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uH5Tx72b59nFBaDlQEh2G2ZrGeveeNZ4ka8qAd/sPCwx8Ki3Zk7xApG4zvJSkTkQkqWfFOwIj1u2OYS/Dq/17TYbdm9pRfU/1dRAo8sMjcfLD8nbDHd7B+5KJC2OwFtZNL511/75354FToDBJgB/EEJTydMMScFSGsRSBwuMAf0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=Nuao0lpK; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="Nuao0lpK" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-40fdd65a9bdso2706355e9.2 for ; Mon, 05 Feb 2024 01:34:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125685; x=1707730485; darn=vger.kernel.org; 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=ANtgl/tgq51oFHA95121eXS9npOxkHEx1ig3f0DQeJE=; b=Nuao0lpKZ1fMSAACPr4RNvbfevd32J4SGwdIRwBJvZErfMuINYZUm3KMud7VMxjZ9M IvhP8ORh6liEzvp5+PBSVsWvpXDyiaxQW/oSvjTvHHdzAMBa2TPVjQsuBeWgA9XvjsCg +3zYnlU685GCEZX40vRr+ls58jPM1tKT17t+HmmBwrupK5VsU87ozN+51Xh2+3IRL2Rm PEbC0WRvdRKt3f31TOo5AfYkb/WzzXFZ8wLcL5ho3m6uIfqkHHtsAfE7VA+y9R38EPei h1ZZP2CmifOx+W8RvL5dVmrO15eDF0KS1irQQiZTIF5HIqeScwFlC2IDXXhNFgiWuFKR iX+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125685; x=1707730485; 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=ANtgl/tgq51oFHA95121eXS9npOxkHEx1ig3f0DQeJE=; b=VT0KNJeb2DNn2Wl5yTlr+4kOBl2+Bw+y4S/QRMbNud4NDCzeB4dFBGBIn4Le7f5Kv+ uYUKCPVrhEbUkS6pn45CsH+fPrjXIyIlTl5bYOGKbBu2BibWV6CpzHV6lqiWdaN2kqS+ pA8/3vtNhk55DBDSK+1ETuy/eaPwhs4s8k1zgZ12yXvpgnXXR9ebsa3J5jPgBTcpVJJa lSPuuvHBx5Vd/UR9WvTAT0Tenfuq6HyXQWnmop82h5UEXIENca0eK3ibbizU21C1eIlW BnsdYqBHiUrZjoejlvCoGl1t80NlQM/cSyBizOaHBUMC4GbFU01XPZvr8ppsZG8yXg3D 2Ixg== X-Gm-Message-State: AOJu0YxEOo0gXOeqSbdMCTBoRCVYINTV40llwK/OoctZDLg9EuQP7ocQ L4WJMGXuTk32bkbcNbC8YBQGQgF1vcVYMM8s6dEJ3Dp1ECVuUVt4aY0+cA656Pk= X-Google-Smtp-Source: AGHT+IEiAxBCDuSUfwYhDsmshalgLzlt7c17tLCl/VIHHdboWKtYEayQQdKgXmml+m/08rFU6F7suA== X-Received: by 2002:a05:600c:1d91:b0:40e:d425:85a with SMTP id p17-20020a05600c1d9100b0040ed425085amr4337540wms.17.1707125685449; Mon, 05 Feb 2024 01:34:45 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWCM1Y10GDWu31dId5ePrOKe9J3PDr0CUXAPIdd0EMoxggyYXZqtAeqpe8kczKAT1O7ZLJQ2/+nD5DNdEz0SMPvQaV+kr71Xyz/B5a6jEVPwSSpwN8TL2cBy17ayRp2ZSBsWdZGzgVsB/y9LHPSWgNqJewKOlaF1DIzeGCkTLwp2qQeMMOq8XhRj+XesAHax3BPVnb8KcWriACDGekYKcJWmhTaoIH3RKVIzF9flWTM8LJZMcvedkMlXeP7Q7A6RDKdBHVdeId08IbGNOr7uyJ4IzL46khiZsExPc8WpydB8ouM2rBXBYXoTWlziJhLwnncN1x8fn39kIVrfzD+w0gms7pRw+CLEQ== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:45 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 22/23] gpio: remove the RW semaphore from the GPIO device Date: Mon, 5 Feb 2024 10:34:17 +0100 Message-Id: <20240205093418.39755-23-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski With all accesses to gdev->chip being protected with SRCU, we can now remove the RW-semaphore specific to the character device which fullfilled the same role up to this point. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 1 - drivers/gpio/gpiolib.c | 4 ---- drivers/gpio/gpiolib.h | 5 ----- 3 files changed, 10 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index ccdeed013f6b..9323b357df43 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 89e1c98b0bda..c7b039398e0d 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -958,7 +958,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, vo= id *data, =20 BLOCKING_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier); BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier); - init_rwsem(&gdev->sem); =20 ret =3D init_srcu_struct(&gdev->srcu); if (ret) @@ -1097,8 +1096,6 @@ void gpiochip_remove(struct gpio_chip *gc) struct gpio_device *gdev =3D gc->gpiodev; unsigned int i; =20 - down_write(&gdev->sem); - /* FIXME: should the legacy sysfs handling be moved to gpio_device? */ gpiochip_sysfs_unregister(gdev); gpiochip_free_hogs(gc); @@ -1136,7 +1133,6 @@ void gpiochip_remove(struct gpio_chip *gc) * gone. */ gcdev_unregister(gdev); - up_write(&gdev->sem); gpio_device_put(gdev); } EXPORT_SYMBOL_GPL(gpiochip_remove); diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index b3810f7d286a..07443d26cbca 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -16,7 +16,6 @@ #include #include #include -#include #include =20 #define GPIOCHIP_NAME "gpiochip" @@ -46,9 +45,6 @@ * 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 * @srcu: protects the pointer to the underlying GPIO chip * @pin_ranges: range of pins served by the GPIO driver * @@ -73,7 +69,6 @@ struct gpio_device { struct list_head list; struct blocking_notifier_head line_state_notifier; struct blocking_notifier_head device_notifier; - struct rw_semaphore sem; struct srcu_struct srcu; =20 #ifdef CONFIG_PINCTRL --=20 2.40.1 From nobody Mon Feb 9 17:21:46 2026 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EAAF1B943 for ; Mon, 5 Feb 2024 09:34:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125691; cv=none; b=tnSDMId7qdj+A1ExTzRO1/nZXw7KiTXcWD0hi6mr0chGPAB0vuI0GJz8jUM+wJdyOUlEM3HZSx0Ed6rXPjZ701OqCBAMYZFeYOjR1sX3VGJdR4vsHWKfnAyWU+ZOnVakSC25BYtTBgqdd6iqGLpnIM8Z4khQcJ3WuzSxWYqdxVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707125691; c=relaxed/simple; bh=CiYSawPebEql0iEz39lQ3pUTtJzpFVAjWsd3kTouEKs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LdBoq30Xb8UKXTJPXyq4KYvs93xdjUU11Tctfy8E8GWyYGtUsEjcCAgBR6c7hszW7/Q9burtMRElYHM0mPFlxhn7kxjNhd7C9J9rgT5D9D5C6ab35uPpj03t84Qv4E9HRhmRB4zJ47eGxPy+mCm7JPv+Zz5fOag7dkH3jR9VIpA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=lHv8qbOz; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="lHv8qbOz" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-511413e52d4so2124160e87.1 for ; Mon, 05 Feb 2024 01:34:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707125686; x=1707730486; darn=vger.kernel.org; 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=IuD4jOVymyzS+IMUJo9eXlxxJz0pfH/DcmsAoXHdB48=; b=lHv8qbOzq2mTAPK7Kz9abzgZmMscc7YNlJf/fLpSSC3dCYHpTBuHtWRdKb3BkB2D7m rScQwt6Q+U1MPsQaLb7/XmBesEJy/c185vg42b9CWPdPys/n+UyRai1pMHAS1lLKvHYx Xoht/0vox05N192vamLBMsNICfFYJT/UpUSZY3aYWmrxpAFu0sg1h1Q0UEiJbhhAesz+ oyqdMQY371RSC2mg5nEaHFncFJ3bmHM6JRcAlGPUxaDpiKIcsHUa4hou/4wPnM/CxlAq yM9sN4dJft4ZUHRtyoRA9fglh7tBTIi7Ywaz6N+l8hQO6ZzRA2HM2qvM1VV43ZCifSIB qBsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707125686; x=1707730486; 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=IuD4jOVymyzS+IMUJo9eXlxxJz0pfH/DcmsAoXHdB48=; b=YzW5DfBQeZXoSFEHL+szFn0frm07dFE76c0JKk5mjXiq6dZ948l2v8VJ5FTc0vlliS +YJhNTp0W1bYGKhGC5c5Jc2YEGl8/cwQ0YvjA/HG92Kh+2MPjXXbefqsYCB8NglUdsb0 LpkrWIHhoIM3FLmkpdxj1k82+aV8Akj/GvapF7bJd+u5MyGsnM29Ns1OKmrFM/WWn35W wo6+Ia7fNyFtJmt0T9wfuTggISVGsUjoU/p1ZNYzfICA/KA8Mn1am/vd7K2Lur1rkFsY C9LnkALhBr217LE87/eybHJhc/+1UX1XRzhdWJap/Tw/hGtZnTtcXY0Y20LIAcItwrlq kGxQ== X-Gm-Message-State: AOJu0Yx1sB7PHOga7ZZYFDjSiBP1+7wriSZyD+dze2ZSJqdmmXpe3tPw IQVdqyM9a17zXZCXa0Q1jDbEf4r2ryxjHLbFbcQ3iNZ4zYrYLtMMFM0gIonykTg= X-Google-Smtp-Source: AGHT+IEPB2Je0SCogU+2gBiEiwjBglfb7KBSZJDiXKT4w6QPedNh07U5ZXtAspIFMe6Orcy3j89JkQ== X-Received: by 2002:a05:6512:220b:b0:511:4df9:1949 with SMTP id h11-20020a056512220b00b005114df91949mr2488688lfu.41.1707125686310; Mon, 05 Feb 2024 01:34:46 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWTnt8FacEOq6jarDsKcu1MJgylOwFHQHyWfITCiQqSjZiNyiEEjTGyq/NHvbkGJ3OF/qrhyzqtMkON24A487SywNaoeMRpos6ffiHwIOw1HDtvNu1tmdtUS9SZP4piE/w0mjapU5+tBc84QAizizuLfpQb53U1YBDSpAMVbRWEbZYr99rZSCsyrh0LGbWsKTN1oEOTuEe4fYLSuz29qg1BwcmZ6zv4xAXNq3ozMHNuj7Tw+bgNrvAa6At858h1RHQC9d1ymtd2hS0xMWg943JNQSS6jdHVJMB8vQm/xfRvMmZMyb3Lejqwb373HK7T99A3s3nlDyg7gNIxr5oVJcchmSTrWDWAiw== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c154f00b0040fc771c864sm7980397wmg.14.2024.02.05.01.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:34:45 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 23/23] gpio: mark unsafe gpio_chip manipulators as deprecated Date: Mon, 5 Feb 2024 10:34:18 +0100 Message-Id: <20240205093418.39755-24-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205093418.39755-1-brgl@bgdev.pl> References: <20240205093418.39755-1-brgl@bgdev.pl> 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" From: Bartosz Golaszewski We still have some functions that return the address of the GPIO chip associated with the GPIO device. This is dangerous and the users should find a better solution. Let's add appropriate comments to the kernel docs. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index c7b039398e0d..dc00eeed6253 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -211,6 +211,11 @@ EXPORT_SYMBOL_GPL(desc_to_gpio); /** * gpiod_to_chip - Return the GPIO chip to which a GPIO descriptor belongs * @desc: descriptor to return the chip of + * + * *DEPRECATED* + * This function is unsafe and should not be used. Using the chip address + * without taking the SRCU read lock may result in dereferencing a dangling + * pointer. */ struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) { @@ -275,6 +280,7 @@ EXPORT_SYMBOL(gpio_device_get_label); * Returns: * Address of the GPIO chip backing this device. * + * *DEPRECATED* * Until we can get rid of all non-driver users of struct gpio_chip, we mu= st * provide a way of retrieving the pointer to it from struct gpio_device. = This * is *NOT* safe as the GPIO API is considered to be hot-unpluggable and t= he --=20 2.40.1