From nobody Sat Feb 7 12:33:11 2026 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.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 7B4CC6119 for ; Wed, 14 Feb 2024 08:44:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707900267; cv=none; b=kH216RVWgXLku6DNy2JvpjP9yMdvSWfLMfGrSVKYxCjYXa5kbt84/784GM8/jQn1oX5cphVe0dIQeHAfhpBcTDlRrZuN8/ZivFXig4DiUNmQlzEAry8unBajADPELOYsR40XhoY2xhpOlZ5C8dHuVVX7FSoLmN4nAubsg01AXzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707900267; c=relaxed/simple; bh=vke7f3mLqY80iPgnYphdJxXUsg/yewlt1JSSwQTi6Cg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LK3MouA7TMK/Mruooldci89CVlRjTPZ6ttE0hzGdRZ80Md6CdAJiF9ZHP75HltdAzRmZtNu6NEEcjXjtPuBPpn4YFWdk7x0xWSOsazfSeBOxw67UVVmkFZjaximXQtPT8aWkbn7TEZUq8yDhoCwHUmWNv1Ij4xlVxG8CoMpXpOg= 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=jenTWXeo; arc=none smtp.client-ip=209.85.221.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="jenTWXeo" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-33ce55ab993so385614f8f.1 for ; Wed, 14 Feb 2024 00:44:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707900264; x=1708505064; 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=rFhXojJ7DlXYIGKFbQSUazUJNMfgGXQm2JYyxUYo77w=; b=jenTWXeo4DV9oaCUaaRKp2pzLkc+cHEacyh+YR7k9vSvAkYxVTCsEzfKTudo17CyHk B8f9shbC8/4/4L8KrzwMFQ8txCwXR05zy67Dv7BQ/vnReROPyys3Hr62erj7kdNDPIfZ MNxEvS8OreD95VxRgSTOqtgEiV69xMEEgTb5gKqvtGobY0izqorqdNMuA6Iwu14ZzJbL LOlmvGGdEc5svoV3VETX66XRa+PMjn6CZW8ZqqAVxykjjg16H1esDpBQgL6yn8UJpp1k 24AyIOrLY9DvJdnlZPmnx4TjRUcD5OkwLASF9LZI/ew1ACo80tLBNcbk6095pWGEe2XI Bx6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707900264; x=1708505064; 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=rFhXojJ7DlXYIGKFbQSUazUJNMfgGXQm2JYyxUYo77w=; b=V2Y+d0OO5CdFOiyf9mx0HKzLtRA27PNogxGlf+WC3S/rLkTT50uS4gXRjt7oeeJ/2D ZAp3GZwYVrV63Vd1gQBIACsL3bHei3khUbfIalB81j8kAj5kBdOze18skaGPo5W0Sr8Q UjJJ9rL1pbenk3jJ5tFkgVxJpbi5D/drSVb2n8EJ/6/WH+1umuzDyk5CPZwQfbXcA4IW 9gUffqJ4ig4ugsLjQnNYLBKK1IblisCUYxIPoWGni0fW5xalmauh1PfOhV+UAYB0m+o2 9OYK2dKgpdCsfzHugiRLGEGMya9csaZW52qVPMa0MJEqWgIfTiurBnhFs/8ul0XCty6Q cm9A== X-Forwarded-Encrypted: i=1; AJvYcCVLBResVIoCseWFo3Lb/3Zwi6RBL9x+eznGrZjNzAwJ6nyoVVT8eSUNj/DczUxwSTnTcfQAI6J0BJLeT4M0eujZ2R0hkr65ieRy0tHd X-Gm-Message-State: AOJu0Yznt+XYm9EUFw1Jxj1ZQTk5s9hX/Bxd+KmCvQSKG/PtN7747rwG Jo+6Y5R3rLevMdPvNE8426Ao3j59qwhlrQVuvy5zo1QIui1jKTx4pkftU++thI4= X-Google-Smtp-Source: AGHT+IFxVOr2z8lh02p1KypI83zJK641TmMZKxXM0gQR0S7z8ej1eJxPwM4bGrmcDVHicTcjK0kCgQ== X-Received: by 2002:adf:f3c5:0:b0:33c:cfc5:5ff1 with SMTP id g5-20020adff3c5000000b0033ccfc55ff1mr1185222wrp.65.1707900263847; Wed, 14 Feb 2024 00:44:23 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUdJ4z9AjPLf2LNcKSfUHNX/4gUscA5BP0k1QLWWNrl4ulc4N73hAaTqVofvZt6sKOB1BXOp39wp7SKvB0yt8pt6aFxV+Y3ztAMSHp89eA8tzlPacuKog7KxkLe2kIIn3leLdMfNrToRVM8w5xp4cqMZq4ow7l7cyC6TtBKB2uL9DoRLmG2VwMHSOuyW36eEsdoM3sgUMAE9io4i7h7Mzoh2zmVz3D1ZRJYZI/HARByZoM+ZJdC3e3tZB3NaCSnusFYiiOuhMCXBl7gLIQp/gZ1y7XCZswK/dbRxCBCCKS7ULEVT3b1d/kDGvqH5XeUPfx1zzLrD7hejdDOcdSGw3TvwoTnrKFdN3vX1EmKtsqOI0aQdiwRN5f2S6ClCH+0fC290UK8gKuBjMxlMVSsgsTCGxVb8mQ13IfCeIA7 Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:cfee:a5b6:1f9b:9c9b]) by smtp.gmail.com with ESMTPSA id fa1-20020a056000258100b0033b79d385f6sm9494731wrb.47.2024.02.14.00.44.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 00:44:23 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang , Mark Brown , Dan Carpenter Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , kernel test robot Subject: [PATCH v2 1/4] gpio: take the SRCU read lock in gpiod_hog() Date: Wed, 14 Feb 2024 09:44:16 +0100 Message-Id: <20240214084419.6194-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240214084419.6194-1-brgl@bgdev.pl> References: <20240214084419.6194-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 gpiod_hog() may be called without the gpio_device SRCU read lock taken so we need to do it here as well. It's alright if someone else is already holding the lock as SRCU read critical sections can be nested. Fixes: d83cee3d2bb1 ("gpio: protect the pointer to gpio_chip in gpio_device= with SRCU") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202402122234.d85cca9b-lkp@intel.com Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij Acked-by: Paul E. McKenney --- drivers/gpio/gpiolib.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f5434e559382..439d32d5aa38 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -4492,24 +4492,27 @@ EXPORT_SYMBOL_GPL(gpiod_get_index_optional); int gpiod_hog(struct gpio_desc *desc, const char *name, unsigned long lflags, enum gpiod_flags dflags) { - struct gpio_chip *gc; + struct gpio_device *gdev =3D desc->gdev; struct gpio_desc *local_desc; int hwnum; int ret; =20 + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; + if (test_and_set_bit(FLAG_IS_HOGGED, &desc->flags)) return 0; =20 - gc =3D gpiod_to_chip(desc); hwnum =3D gpio_chip_hwgpio(desc); =20 - local_desc =3D gpiochip_request_own_desc(gc, hwnum, name, + local_desc =3D gpiochip_request_own_desc(guard.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); + name, gdev->label, hwnum, ret); return ret; } =20 --=20 2.40.1 From nobody Sat Feb 7 12:33:11 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 9B6E46FB6 for ; Wed, 14 Feb 2024 08:44:26 +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=1707900268; cv=none; b=THjseH9ATF1e07+jKi+8ZuK1udd0NsqUWi8FCxdUZq7gmjlWP/wzkhcJMpHQ4f9xMUzM9CgazNBzFkcjDHqF1FBucTy0V20m+gM67OBMduEodYV5bayfMnMTe6msfnZ4tU1oVKm7f7YmH+PQvSLfuQTbsLIkIHN7LauG6gN6XWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707900268; c=relaxed/simple; bh=eHN5AciwJywXX0m6TsYOtY6ESMLvZ8fD9s43NIeL+yo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rWCvHZ5Z0LHuvfZB57fYpcvb+CVDialjBCTr+Rj3rF3FjKoAU3IvlQ8OyulPwZ6JPnIE4o7TCc/dq0uD1ZvaR3lBuBJvnWVJD930JsPAgBtt27gIW5oB16U1UaQQ6nCdvyF7aahFBrRfA0nvjXn3N8AVSukj/wUpNBPCOqLzPLM= 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=K2kq0q/W; 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="K2kq0q/W" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-411c2f76308so10553875e9.3 for ; Wed, 14 Feb 2024 00:44:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707900265; x=1708505065; 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=LlRaYTHTwVLuz49BQFz01SyvMwXYPLiItdhT/I/i6Zw=; b=K2kq0q/WYe599EKhJ1soeKgfSsfd+AT0WcsN1LJYcq3UlkkXMBoNgvW7PZoO7aIkDn OPPFkdIoKWp5ltH+1gHwbraYREKuExRfgx/R5o5pB1GFbOtxK1pQp/VmqjeU+/BpGqCe VCfb1YAlsetONNJDjNOCpBJJM67yaliuMKPhy1ED+7r0yhxb6w823ozrm4dsHPo5HOI+ 9Z9px+cpTASePhg9Srvh+VXJ2wcFwzrAMMuXsMPPj5NCDNI1VKH5L4Espr9Dmc/GyB0W 9IahnMSFIxqds925LuyJMPI+5OW05L5px4b8yujZcRrxtAZ/2xGF3Euj0TKRTNXbU3Vc ioCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707900265; x=1708505065; 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=LlRaYTHTwVLuz49BQFz01SyvMwXYPLiItdhT/I/i6Zw=; b=kyM/mCxUy4VhZMymjNiiaxQEuHYPLwQI6C7CYGrCBUwmAOrCsA6pbc0h82jp30Obg5 U+nnnHyJ+d14GQ087OT//TWOvVGb4JCYC5q5LQKJogSO0RromJrgNanYFtL9LDGK8q9O Ai3LOXnZNB9EFzBLfoKxAiI7yM635If2bAEN7h3vU7YRqLQo0jXJfemFzh/H6krhfBiI l18/5BNtaQ3b0+S2Udp4riXYJJ9f4TlKM+c6HlI3gknJhMjW+s0YsD3VQis5GH5sqmod d7Wn7on5Zy9MiUSbu6xcMol/PQ4m/vlVN5r2OzEv27bGrTZBDQB0Nvx1rgK+JUyqlS6R KD4g== X-Forwarded-Encrypted: i=1; AJvYcCVWwW3X2hTcSutsQ9oXmIMbpt1L72RfBWR8HMaJUSM09oYQa8D7PLljNTFhJ8COYarewQhFU915VIPl0ukLs0tlLg6eK+qdsMQ/ks4i X-Gm-Message-State: AOJu0YxgM/tdcD6H1HZDQXGetlzjoCMjvOfr8og46OueeC6Ossf4ufIA he//bZrFa11Lly1zEEYNX25AeTwYYRoBT166nm07Pgzh6uOM6LfeIRlL+MQAyoI= X-Google-Smtp-Source: AGHT+IE9Y0aDThi0m9FCFrZ2H0WgSTwbVQ87NKAxgxch35L/9BGa6QjKFs3y3Iq6+Fc5CS5VDIsL4w== X-Received: by 2002:adf:f045:0:b0:33c:dda0:769f with SMTP id t5-20020adff045000000b0033cdda0769fmr1309649wro.31.1707900264940; Wed, 14 Feb 2024 00:44:24 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWdI49F1wLkvPpe1eeM7hCZ9ooqpYJNUeF9/P4R+2xyjXh+U97RIFK1/yqqldvbX443WJz0H3+whFgrPSpbpnN7qKl0/xvCX9MWRexo9LttF3GNs+3mmjpB3N2rrNQ+KevxVfruRtikGlPzl5Wm/EYEJlFGgpiVc9iIVp/TRhvNAF+v0Tz5fjmdMuIEoQCMSgdd7PTLIVEkQq8G1GSKzDeQTHPS3OdVH3xMN6VNMMbHBMQZV8bYrsKZQT2t9PbzVjIUBBtA1Bma/uOrNOlXeNlqmlSZEoYeqM4LfnV60YkhGA+Jwe9kVjsjHcsTwNIEqL48fAiWt1YTpgGZFzWnmTFMf+aD/kcrQUo/cc2VWDzXFmoWWybfDmxkOtlv4/AnJln5EUiYQu9WUutWu1z+TxtTi4mqjp1c99uaSGwO Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:cfee:a5b6:1f9b:9c9b]) by smtp.gmail.com with ESMTPSA id fa1-20020a056000258100b0033b79d385f6sm9494731wrb.47.2024.02.14.00.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 00:44:24 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang , Mark Brown , Dan Carpenter Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , kernel test robot Subject: [PATCH v2 2/4] gpio: cdev: use correct pointer accessors with SRCU Date: Wed, 14 Feb 2024 09:44:17 +0100 Message-Id: <20240214084419.6194-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240214084419.6194-1-brgl@bgdev.pl> References: <20240214084419.6194-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 never dereference the chip pointer in character device code so we can use the lighter rcu_access_pointer() helper. This also makes lockep happier as it no longer complains about suspicious rcu_dereference() usage. Fixes: d83cee3d2bb1 ("gpio: protect the pointer to gpio_chip in gpio_device= with SRCU") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202402122234.d85cca9b-lkp@intel.com Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij Acked-by: Paul E. McKenney --- drivers/gpio/gpiolib-cdev.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 9323b357df43..85037fa4925e 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -206,7 +206,7 @@ static long linehandle_ioctl(struct file *file, unsigne= d int cmd, =20 guard(srcu)(&lh->gdev->srcu); =20 - if (!rcu_dereference(lh->gdev->chip)) + if (!rcu_access_pointer(lh->gdev->chip)) return -ENODEV; =20 switch (cmd) { @@ -1521,7 +1521,7 @@ static long linereq_ioctl(struct file *file, unsigned= int cmd, =20 guard(srcu)(&lr->gdev->srcu); =20 - if (!rcu_dereference(lr->gdev->chip)) + if (!rcu_access_pointer(lr->gdev->chip)) return -ENODEV; =20 switch (cmd) { @@ -1552,7 +1552,7 @@ static __poll_t linereq_poll(struct file *file, =20 guard(srcu)(&lr->gdev->srcu); =20 - if (!rcu_dereference(lr->gdev->chip)) + if (!rcu_access_pointer(lr->gdev->chip)) return EPOLLHUP | EPOLLERR; =20 poll_wait(file, &lr->wait, wait); @@ -1574,7 +1574,7 @@ static ssize_t linereq_read(struct file *file, char _= _user *buf, =20 guard(srcu)(&lr->gdev->srcu); =20 - if (!rcu_dereference(lr->gdev->chip)) + if (!rcu_access_pointer(lr->gdev->chip)) return -ENODEV; =20 if (count < sizeof(le)) @@ -1875,7 +1875,7 @@ static __poll_t lineevent_poll(struct file *file, =20 guard(srcu)(&le->gdev->srcu); =20 - if (!rcu_dereference(le->gdev->chip)) + if (!rcu_access_pointer(le->gdev->chip)) return EPOLLHUP | EPOLLERR; =20 poll_wait(file, &le->wait, wait); @@ -1913,7 +1913,7 @@ static ssize_t lineevent_read(struct file *file, char= __user *buf, =20 guard(srcu)(&le->gdev->srcu); =20 - if (!rcu_dereference(le->gdev->chip)) + if (!rcu_access_pointer(le->gdev->chip)) return -ENODEV; =20 /* @@ -1996,7 +1996,7 @@ static long lineevent_ioctl(struct file *file, unsign= ed int cmd, =20 guard(srcu)(&le->gdev->srcu); =20 - if (!rcu_dereference(le->gdev->chip)) + if (!rcu_access_pointer(le->gdev->chip)) return -ENODEV; =20 /* @@ -2510,7 +2510,7 @@ static long gpio_ioctl(struct file *file, unsigned in= t cmd, unsigned long arg) guard(srcu)(&gdev->srcu); =20 /* We fail any subsequent ioctl():s when the chip is gone */ - if (!rcu_dereference(gdev->chip)) + if (!rcu_access_pointer(gdev->chip)) return -ENODEV; =20 /* Fill in the struct and pass to userspace */ @@ -2595,7 +2595,7 @@ static __poll_t lineinfo_watch_poll(struct file *file, =20 guard(srcu)(&cdev->gdev->srcu); =20 - if (!rcu_dereference(cdev->gdev->chip)) + if (!rcu_access_pointer(cdev->gdev->chip)) return EPOLLHUP | EPOLLERR; =20 poll_wait(file, &cdev->wait, pollt); @@ -2618,7 +2618,7 @@ static ssize_t lineinfo_watch_read(struct file *file,= char __user *buf, =20 guard(srcu)(&cdev->gdev->srcu); =20 - if (!rcu_dereference(cdev->gdev->chip)) + if (!rcu_access_pointer(cdev->gdev->chip)) return -ENODEV; =20 #ifndef CONFIG_GPIO_CDEV_V1 @@ -2696,7 +2696,7 @@ static int gpio_chrdev_open(struct inode *inode, stru= ct file *file) guard(srcu)(&gdev->srcu); =20 /* Fail on open if the backing gpiochip is gone */ - if (!rcu_dereference(gdev->chip)) + if (!rcu_access_pointer(gdev->chip)) return -ENODEV; =20 cdev =3D kzalloc(sizeof(*cdev), GFP_KERNEL); @@ -2796,8 +2796,7 @@ int gpiolib_cdev_register(struct gpio_device *gdev, d= ev_t devt) =20 guard(srcu)(&gdev->srcu); =20 - gc =3D rcu_dereference(gdev->chip); - if (!gc) + if (!rcu_access_pointer(gdev->chip)) return -ENODEV; =20 chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id); --=20 2.40.1 From nobody Sat Feb 7 12:33:11 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 B1D0E79DC for ; Wed, 14 Feb 2024 08:44:27 +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=1707900269; cv=none; b=jcFK1hX61y6wfsaD0Y4xmioYlCfB4VvOD0vhcTDsGFH7DrlEo/dxG1txVszLrvnoNwa/EZrQlOV0/lf1Q6pE4SpIWFog6uVXf3RSkHXt2w6IObeR9XIZcDRvc4bCb42rCWsNRIZiTLRdru6Bb0EuQ2QSTUvCAwIPKIdRpCThZj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707900269; c=relaxed/simple; bh=p11uFDAy9kr8AJil/h/KV/gIH0eHT2jZGPO4Cr//nBI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hz7lLNwm/5rTuV997MuwVwIdrR95xlf3w+v3grUwrN9Ds/b7kgyCedkeByTnQnTHmnoYcUpU9i59QYpSFFLkxynwnd01z2l5yst6Qx55Asn2C3gMJkhHsS8W5XuvkQ6fmVhh/Oo74+C/z4/7/d5KHgVZaMQKDY9OLWsv/Y4kmQw= 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=tphwpPST; 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="tphwpPST" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-411e5f21c0bso3267305e9.0 for ; Wed, 14 Feb 2024 00:44:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707900266; x=1708505066; 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=X3eth2TSBr+10lk6fCyMvSDVfbmqhMKDjUVfag1zzhw=; b=tphwpPSTePp5K4zCZETxL+jPaSxMOXPV7akSvCft+mcqRoqp76Y4MaXCfuYsnSZHTO p1Lfu36BMdkh7pmiR/WALoSwSjEGE8ZNseIFo7IIcrHKg2DyBPjI9X3zse8XYrLXa9nA WNWeRMc3W4XL8J2kF83chG3d3mG8zEwjvAK6oRznFkhZ4mlX7ogPJEiTfJXHlAX0d7MA 4RC4rhTztO7f8doUcI8YkBQiAu0mb/QuxCW9Lfxew8l4tqq0RC1+4PRtbE0IQ2g1X4AF mde4zAGGqfAtLRGi2dP3r3yR1bWVaqch5W7kjRswUUhJ08wSsAq37BByuMU+v9eIS8hN 9A9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707900266; x=1708505066; 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=X3eth2TSBr+10lk6fCyMvSDVfbmqhMKDjUVfag1zzhw=; b=gBnNszRnl53TZGHTgfHolWOf/i78AWpLsescFH0VuclGibLk6q37nWvs97r6cYsMvH DVEbPYfikrNAFSfurtogUAlBnP74aWBUrTKxcZB959ucFZXp1cFWyjd4n4jvP3ffzNOQ lx7dkwEYJbiuwY6ETuETkPs11RlLW4EOkOcg9rzO/DWejvHG76bWoZ0lxL8/xtldJ3D1 JZlTU0QLorG1tPUn/1s5m/DjEmkq7cz9lQNI2ZfaO/0L88d1I7EKv3cayH+Xgq1an7e1 rVkZJ+f6dhgz7gV8pG5bQhiIUKsxl/iYA7LF9JadoYfDymc526z7aGpRSiO3DmcT6Vff KjeA== X-Forwarded-Encrypted: i=1; AJvYcCUYzbs3uG6Ll/ujTOJRf52w0ZsWbFVFWy0ljaE633aSPoALon/e9J+qSbbVkzbsJdkwL8XQdtcISxbYnU2Isk0DM7kYPNYVJP7e4QUS X-Gm-Message-State: AOJu0YzNi30xuUREHoFu3myp9QQV1IUAwWeoNNNOVYG7GY6zNluAlq+c zLwnmR6RZfxyaTEyJseLfYZyayiHxEiu69FHvhuLBRci66xaWSxHmPZqBpXO3lU= X-Google-Smtp-Source: AGHT+IGRBXN2kxQwLtZCvWWyvloxumofGlzfk7C9aKvbB+3YAsKfrBDO9B0MVoxtX5oL8wX8BRX19g== X-Received: by 2002:a5d:55d2:0:b0:33c:eca2:c59d with SMTP id i18-20020a5d55d2000000b0033ceca2c59dmr724048wrw.45.1707900265928; Wed, 14 Feb 2024 00:44:25 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUt5BDLK4r1+Y4riz/yiaqEuNCX19R2dR5JZJDkaNpw+qEGfPIiEOf3LYWZLQyeDhYUr9orz0WrswVOSjzMmZGGED8u3oiBwjQXxKCwRS5iE6liZyS7h78Brq3ANzvP43T1N5uhD8vUbgJy3aFcjiQHUb+q8NcLk1RlU3vdErHE4Nm11gh9fP5+Etl3/1HprRbbWPkHXDGkKDI8fbT3qC6wzkAoqzlfP3GS8MKJb8MbLYAS5HTKbzXhiWpdsvXTJvzl/CKMNZMwkId9ulnzpKk8L/O/v3wC9yBDWQFr0G//v0Py3pw4UenCEHtYE1xSOuUXImaLUqYKGXlJL+pHfmFyNr+Z+0gLa4TLKEOKHDD5dzn5Y4SaQ5dGkjFl6dBgPFglfqAirdAQOXejWx6Ite/imxcNAGvxfgTs+wHp Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:cfee:a5b6:1f9b:9c9b]) by smtp.gmail.com with ESMTPSA id fa1-20020a056000258100b0033b79d385f6sm9494731wrb.47.2024.02.14.00.44.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 00:44:25 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang , Mark Brown , Dan Carpenter Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , kernel test robot Subject: [PATCH v2 3/4] gpio: use srcu_dereference() with SRCU-protected pointers Date: Wed, 14 Feb 2024 09:44:18 +0100 Message-Id: <20240214084419.6194-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240214084419.6194-1-brgl@bgdev.pl> References: <20240214084419.6194-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 Lockdep with CONFIG_PROVE_RCU enabled reports false positives about suspicious rcu_dereference() usage. Let's silence it by using srcu_dereference() which is the correct helper with SRCU. Fixes: d83cee3d2bb1 ("gpio: protect the pointer to gpio_chip in gpio_device= with SRCU") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202402122234.d85cca9b-lkp@intel.com Signed-off-by: Bartosz Golaszewski Acked-by: Paul E. McKenney --- drivers/gpio/gpiolib-sysfs.c | 5 +++-- drivers/gpio/gpiolib.c | 16 ++++++++-------- drivers/gpio/gpiolib.h | 3 ++- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 6285fa5afbb1..71ba2a774197 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include =20 @@ -756,7 +757,7 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) =20 guard(srcu)(&gdev->srcu); =20 - chip =3D rcu_dereference(gdev->chip); + chip =3D srcu_dereference(gdev->chip, &gdev->srcu); if (!chip) return -ENODEV; =20 @@ -800,7 +801,7 @@ void gpiochip_sysfs_unregister(struct gpio_device *gdev) =20 guard(srcu)(&gdev->srcu); =20 - chip =3D rcu_dereference(gdev->chip); + chip =3D srcu_dereference(gdev->chip, &gdev->srcu); if (chip) return; =20 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 439d32d5aa38..b095f475805f 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -109,7 +109,7 @@ const char *gpiod_get_label(struct gpio_desc *desc) return "interrupt"; =20 return test_bit(FLAG_REQUESTED, &flags) ? - rcu_dereference(desc->label) : NULL; + srcu_dereference(desc->label, &desc->srcu) : NULL; } =20 static int desc_set_label(struct gpio_desc *desc, const char *label) @@ -447,7 +447,7 @@ static struct gpio_desc *gpio_name_to_desc(const char *= const name) srcu_read_lock_held(&gpio_devices_srcu)) { guard(srcu)(&gdev->srcu); =20 - gc =3D rcu_dereference(gdev->chip); + gc =3D srcu_dereference(gdev->chip, &gdev->srcu); if (!gc) continue; =20 @@ -1190,7 +1190,7 @@ struct gpio_device *gpio_device_find(void *data, srcu_read_lock_held(&gpio_devices_srcu)) { guard(srcu)(&gdev->srcu); =20 - gc =3D rcu_dereference(gdev->chip); + gc =3D srcu_dereference(gdev->chip, &gdev->srcu); =20 if (gc && match(gc, data)) return gpio_device_get(gdev); @@ -2978,7 +2978,7 @@ static int gpiod_get_raw_value_commit(const struct gp= io_desc *desc) =20 guard(srcu)(&gdev->srcu); =20 - gc =3D rcu_dereference(gdev->chip); + gc =3D srcu_dereference(gdev->chip, &gdev->srcu); if (!gc) return -ENODEV; =20 @@ -3012,7 +3012,7 @@ static bool gpio_device_chip_cmp(struct gpio_device *= gdev, struct gpio_chip *gc) { guard(srcu)(&gdev->srcu); =20 - return gc =3D=3D rcu_dereference(gdev->chip); + return gc =3D=3D srcu_dereference(gdev->chip, &gdev->srcu); } =20 int gpiod_get_array_value_complex(bool raw, bool can_sleep, @@ -3593,7 +3593,7 @@ int gpiod_to_irq(const struct gpio_desc *desc) gdev =3D desc->gdev; /* FIXME Cannot use gpio_chip_guard due to const desc. */ guard(srcu)(&gdev->srcu); - gc =3D rcu_dereference(gdev->chip); + gc =3D srcu_dereference(gdev->chip, &gdev->srcu); if (!gc) return -ENODEV; =20 @@ -4787,7 +4787,7 @@ static void gpiolib_dbg_show(struct seq_file *s, stru= ct gpio_device *gdev) =20 guard(srcu)(&gdev->srcu); =20 - gc =3D rcu_dereference(gdev->chip); + gc =3D srcu_dereference(gdev->chip, &gdev->srcu); if (!gc) { seq_puts(s, "Underlying GPIO chip is gone\n"); return; @@ -4872,7 +4872,7 @@ static int gpiolib_seq_show(struct seq_file *s, void = *v) =20 guard(srcu)(&gdev->srcu); =20 - gc =3D rcu_dereference(gdev->chip); + gc =3D srcu_dereference(gdev->chip, &gdev->srcu); if (!gc) { seq_printf(s, "%s%s: (dangling chip)", priv->newline ? "\n" : "", diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 07443d26cbca..ada36aa0f81a 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -202,7 +202,8 @@ DEFINE_CLASS(gpio_chip_guard, =20 _guard.gdev =3D desc->gdev; _guard.idx =3D srcu_read_lock(&_guard.gdev->srcu); - _guard.gc =3D rcu_dereference(_guard.gdev->chip); + _guard.gc =3D srcu_dereference(_guard.gdev->chip, + &_guard.gdev->srcu); =20 _guard; }), --=20 2.40.1 From nobody Sat Feb 7 12:33:11 2026 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.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 98AC6B651 for ; Wed, 14 Feb 2024 08:44:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707900270; cv=none; b=UjAyfWW4H5on9/hdGvXL9w+1YJfwCkNYTJeyNr/+8NdafRkHT5Hf18T/NO0BPgsin4jvK5KhyZ58/86wUhPWCR3DXGwaTE5tha7l8CTjvisAd2KinGGcGOKblpnJsAfk/bETd/Uim3IEpqX4WgLQ9KWGp+sSpL6eja7B2HB9nvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707900270; c=relaxed/simple; bh=nI1sU4z1CFEN5Iy/28K2xqVSyRcEQoCVuY9LCoaM61Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eMoHbQHS+epX9mJCw54ZiTv9KIkOeaSkYmDno6TJVwZRd1X8ww8ARnCy3NkF6eK4k3hnx5AiqgzKGdMRhXJfdNIImTWfGdG/zxhCDXSZqt+u4xYI6oCpAbxY5ux4Ix2mLalcP4YyOxjwdAiRtfP5qveq8wBavu7NwqLilkV5uMg= 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=F3LNjgJj; arc=none smtp.client-ip=209.85.221.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="F3LNjgJj" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-33ce55ab993so385635f8f.1 for ; Wed, 14 Feb 2024 00:44:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707900267; x=1708505067; 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=hFhIIzAiY74bCQSacBGTi9CNjb/LwvQSA/13OOoGG+s=; b=F3LNjgJjE3Gtl+wbyos0mkRY16B7WgdRSnxDCeT+Z2K6WEPJfdrpr8P5N5jiIJr2lS m+wt7uYap0fKsF6QGUEucE+TZodp36dKW1BFdMsawXAyHgshLW7wMoj78kOqSSn1i+rZ YoyjNtSmoi2yQ3sZ2zhFP3iTi/GraVBqZ8hPnwx8cJ4KfptLfizWXfEA9uDJXR9j6O7h e71MxmFouwTiXXQjfmjXA78M6VTZ1fZ4q/E+vzA9g09SgZIRP5+ftgNRQfjhwpXIjpTZ JgC98+PdXpF/OC6CsDDAb4nRP2dAxCCzTjkKDfgw9gq0gqDdfHAE4Gsr5C9XpYGtfo03 MRJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707900267; x=1708505067; 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=hFhIIzAiY74bCQSacBGTi9CNjb/LwvQSA/13OOoGG+s=; b=EoalK3AlNR+pIZ9ozV/rqhEhlEJp+LO7av2XF76kHLbqZtsrY94CIqFXUH8Y09sxbt x41B86IvYR0mp9gGVv88JKNUasIbZEI9sD6MJaXC5U5/TVCtNs58UaxPleBt6TwuoIMg VurxovB9PmESPvq5292RVTqmsPNS125T1sa5VEGHRH8/FBXZ6mEeSx6xd8ESO7t/HTvd vutsR56ry5PA1VT2v96Z6POW0qahc1zcAMtgIdXvtsLJyb4LObCZLzRLoeT0NNRc9nnh +pyzHcHk6JkfpfNn7oc3debcMF4K0H6Cpo4woKTreWv6oy2KDhsHjUp/y3eBSQXSJWFW Z3nA== X-Forwarded-Encrypted: i=1; AJvYcCU35tRR441XK9+leRQpeMa8YpxFZDLneh39nvEE1vUxoYrs02LLPt4fklM58rNqQOsmv75rJ89af0B/Q6vzkAdrINNDwFWkiVR+bTQR X-Gm-Message-State: AOJu0Yzb6NSzcZNqwjvmuKn2ztsGQwwdaJzUzXa+/KDzUhrWU7vgIdH3 usyeHVUtjt1yCFAvPDKq5XMGYtFfKTrLa0iYSgGzlXjivL/k7fwTJaRnfp5/v+Q= X-Google-Smtp-Source: AGHT+IF/YAUk1OG52T8jc3CcxwlwaMSDlCc32WrAAgr48Qwu9fO5aNWtZ0rbDX9MsEQNdE+jJNtkfQ== X-Received: by 2002:a05:6000:128a:b0:33b:1b72:e7ed with SMTP id f10-20020a056000128a00b0033b1b72e7edmr1115836wrx.53.1707900266947; Wed, 14 Feb 2024 00:44:26 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWoPbcCe6PNsTWj8h/GSUEFbxQElEGZMLqXu2DHrW5EMLtMHnzCKCV6kFHaYNCE185mAbTN5QQ0qKZi2liMUyV/cDZD3U8o0HlsRCdwP6HVkjUWLmmH4nISVt6x/PLaW2REw/cuSX4WQaapjkuE8G2sA425R5PHzJtOfevPgfAT6cU3o8QncN9u5kH9FvNOaGNsK7cS3pWVEMOscJRMYo/MWxTk75Fe1tyPuRbE5vI6QCTGfunG4M92REVX184vLt35v1G2UOLp2H4ow59f+DRFRtT86vt3hkGV2f1tWGZoR3be/ajbm1ze/8s7QKNayPOl62Jb+Uc/o/GHa1/rVx41WVCmmkdvKn9n8iCBa+2RN3RBT46gEkT/4QQn0Rtp3xCxkaCWZghMD88G4pytqj9vsoaz6CFDloHHuDyn Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:cfee:a5b6:1f9b:9c9b]) by smtp.gmail.com with ESMTPSA id fa1-20020a056000258100b0033b79d385f6sm9494731wrb.47.2024.02.14.00.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 00:44:26 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , Alex Elder , Geert Uytterhoeven , "Paul E . McKenney" , Andy Shevchenko , Wolfram Sang , Mark Brown , Dan Carpenter Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , kernel test robot Subject: [PATCH v2 4/4] gpio: don't let lockdep complain about inherently dangerous RCU usage Date: Wed, 14 Feb 2024 09:44:19 +0100 Message-Id: <20240214084419.6194-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240214084419.6194-1-brgl@bgdev.pl> References: <20240214084419.6194-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 There are two legacy, deprecated functions - gpiod_to_chip() and gpio_device_get_chip() - that still have users in tree. They return the address of the SRCU-protected chip outside of the read-only critical sections. They are inherently dangerous and the users should convert to safer alternatives. Let's explicitly silence lockdep warnings by using rcu_dereference_check(ptr, 1). While at it: reuse gpio_device_get_chip() in gpiod_to_chip(). Fixes: d83cee3d2bb1 ("gpio: protect the pointer to gpio_chip in gpio_device= with SRCU") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202402122234.d85cca9b-lkp@intel.com Signed-off-by: Bartosz Golaszewski Acked-by: Paul E. McKenney --- drivers/gpio/gpiolib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index b095f475805f..02be0ba1a402 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -221,7 +221,8 @@ struct gpio_chip *gpiod_to_chip(const struct gpio_desc = *desc) { if (!desc) return NULL; - return rcu_dereference(desc->gdev->chip); + + return gpio_device_get_chip(desc->gdev); } EXPORT_SYMBOL_GPL(gpiod_to_chip); =20 @@ -291,7 +292,7 @@ EXPORT_SYMBOL(gpio_device_get_label); */ struct gpio_chip *gpio_device_get_chip(struct gpio_device *gdev) { - return rcu_dereference(gdev->chip); + return rcu_dereference_check(gdev->chip, 1); } EXPORT_SYMBOL_GPL(gpio_device_get_chip); =20 --=20 2.40.1