From patchwork Tue Feb 13 09:31:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1898133 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=Fd7Rhiyl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-gpio+bounces-3228-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TYx0k4hR3z23hT for ; Tue, 13 Feb 2024 20:31:34 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C6D09B21EA3 for ; Tue, 13 Feb 2024 09:31:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06AF8225A9; Tue, 13 Feb 2024 09:31:17 +0000 (UTC) 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="Fd7Rhiyl" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.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 262A222319 for ; Tue, 13 Feb 2024 09:31:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707816676; cv=none; b=beOvH+ie5vJ6MpmfabqRvpOz7Iyd4nPj1HrrazN9NRKl3HYkZFKw+4MRJEp9BoSRelsICozQrFFn6jdg/QIOS7tz7EncRRqfj0xS7K1Osj7UX4YKDqvfRZ822JYwizK3d63Z4lsfQNIuWjh3OCf4ujgYJNNJM+wC37iRcrPM574= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707816676; c=relaxed/simple; bh=una9vqr9afr38wBVZw0pqukTIf2ij0dBOF7F5Fkbkck=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=etpqcTSdzOVXiYKAcX+GEDkYFfKkZlwHoWI22DUyIdHN2SRW8yFg+zwHVsbeT3g9y2S31lSIuHsb6qhRNAtkO9pD5f/bO19oFwE6PbxmAw1D/CHwuW7DmpA2I5LxCqpTaMh7Q3CeHO2wr54enEX4mblBV1iKJlLONXNzN4Iu37U= 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=Fd7Rhiyl; arc=none smtp.client-ip=209.85.221.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 Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-33ce0730e25so73906f8f.1 for ; Tue, 13 Feb 2024 01:31:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707816672; x=1708421472; 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=wG6v3UogFkM+UNCdDFGKO2I94s5BqeEYEkiY+5bnH8M=; b=Fd7RhiylHIo9uPmZ7YhBGmnlLqbgsyqGu+Bylz5c184pkmkMOpxSfxhyYM32Q4ZIUl wlE0VxOsTUBQ3MjgTnokL2KmzGLI3KXFgE19GnEZKbMFB+DjYU1CXbRFxiQx66yIoSkA Fnf+mWWc9e8xmw2JKoFSxbOSACS39Qp2WVbheCZrBCOAAyC30CfkpLwVXBn4d7+mft+B Ncax6JnMo+dQDUEKZwkw+8kzLjwkUcJNO22XNRZr34Vpq0WCDtgNJMjBzB7yFge9SVQe 7tJ15MOXAmIQ1Uks5bGJbuIAYQsmwwdwSRZZ/QSsjNO6uyyftB34VCcc+ZqOPEi/CPSu Nhpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707816672; x=1708421472; 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=wG6v3UogFkM+UNCdDFGKO2I94s5BqeEYEkiY+5bnH8M=; b=bKiKp5t/egFjiFhGySTHfe//h4DI3Z5mkCp+bmg/awMaUdRSVUuBxsjGsjxo8t/XoZ 4jjf/jOhj1p1b2HPJXbj21JHBwxMJEt5349ZFSr6XwG3guyrMKxayrsq1MQijYHla3sR gDLDmxZa2yuh35xTOX053oSSKAzfCAJ+HyQSJTZTMkLxafRXqDGOhy/Czex/57wSW9g9 cAG0hcUMygklQeC1eoBGIpSh4b/ndtxQSsEbk400WfM4sdKixp8aAbbDLTscMer9ZQmf Jl15bcyJBZQIH2rT9OuBdtK0G7izDp/RUn6TREE/Dfq7Uw6n1WMjXtV4Ch72y7c2BYyU IjRQ== X-Gm-Message-State: AOJu0YygMg3/YyyY4IOtv7gMB+hzrjbQDqnaAC6ovGLuw978hClW2h1n Zig69DE46UgcR5Uk+JdQ4OYBcKAa3fe/kj3FafiQkVOPMILv9LCYK1Tamo7HDYY= X-Google-Smtp-Source: AGHT+IHrGOprDXRDU7JOCzMSSH5ai8tt7kG/V3VKXT3yiXGl9NEsi00kOEQxL3WcZ+0+OI+DO65/Bg== X-Received: by 2002:adf:fd4e:0:b0:33c:e1ec:1963 with SMTP id h14-20020adffd4e000000b0033ce1ec1963mr74560wrs.64.1707816672453; Tue, 13 Feb 2024 01:31:12 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVDrLAvbks5O/HaHn03tFg6aPUQ5rLMoNBA4lCA8LPd5q0Qxkfzkhm0ucHBOyIJnKADycj5qtAhKGbpSIGFcPS8aZILTvcbC+L7TtIXphpiMpxB+tSKC+suPw+HRlf7QiOeuzD3Xd07BgTByqrngMxBOSuBCwf5H+uZxsiYUdGcLTygewrGk4IGuZKG4gSacqNCgqPf2MAjkra5tSRjDWtncG9YmBLRnYThmsygbJKpMqI6QsslPSWjEzkD+PPtD+13VyAss/bPdlk91p3wrgiLauwL8XNrMLs+Fo2ZBO6vdQm6LbKLiCUCwJJ2Gxn2tlzAkbphOG0yzFCePFG2tcYWnFwgDzV4LS2y3KmqUm0= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:f634:2e37:58a9:242a]) by smtp.gmail.com with ESMTPSA id p16-20020adfcc90000000b0033b2497fdaesm8980897wrj.95.2024.02.13.01.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 01:31:11 -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 , kernel test robot Subject: [PATCH 1/3] gpio: take the SRCU read lock in gpiod_hog() Date: Tue, 13 Feb 2024 10:31:06 +0100 Message-Id: <20240213093108.13922-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240213093108.13922-1-brgl@bgdev.pl> References: <20240213093108.13922-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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 82811d9a4477..c1391a9a0af6 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 = desc->gdev; struct gpio_desc *local_desc; int hwnum; int ret; + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; + if (test_and_set_bit(FLAG_IS_HOGGED, &desc->flags)) return 0; - gc = gpiod_to_chip(desc); hwnum = gpio_chip_hwgpio(desc); - local_desc = gpiochip_request_own_desc(gc, hwnum, name, + local_desc = gpiochip_request_own_desc(guard.gc, hwnum, name, lflags, dflags); if (IS_ERR(local_desc)) { clear_bit(FLAG_IS_HOGGED, &desc->flags); ret = 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; } From patchwork Tue Feb 13 09:31:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1898134 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=WpKIVIci; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-gpio+bounces-3229-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TYx0n38ZBz23hT for ; Tue, 13 Feb 2024 20:31:37 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D7398284BB2 for ; Tue, 13 Feb 2024 09:31:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A561225CD; Tue, 13 Feb 2024 09:31:17 +0000 (UTC) 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="WpKIVIci" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.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 6F30A2232A for ; Tue, 13 Feb 2024 09:31:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707816677; cv=none; b=mVOmu94xl9IRaSWLopeUrjeM0psdJjfa251TaBxnWGuD83PbzXVly8aKvezh9pBb59Jkdua+lMKPGLEADfrjA/Bkg+pcENCTd9f5QnjqJAepkNHo68Y0TIhY4pCVxf+2D9ouJ55c1Nt4QMiWxAg+LSHbY1GBywxRABgSBnScxLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707816677; c=relaxed/simple; bh=uiPH+suZkaL06kXCeEFh77vFLZuPv8neSgnWiG0ld20=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hnpy73Xvb2wrLawNs31bRoR1MCmk3i+jGZ90y3RzKvO4RVEsRER4veP0HOqjaEQ5X7tjTlKjxU4RBJyNnuwSx6N00eI3SlCOe8jRUagtZhZNOMF+SDmbvkoewBcWRTE2zU18D4lUhDCYcAdxSNpdZh6B5yRj9CxMeMEL/bdJpLA= 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=WpKIVIci; arc=none smtp.client-ip=209.85.221.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 Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-33aeb088324so2618904f8f.2 for ; Tue, 13 Feb 2024 01:31:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707816674; x=1708421474; 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=n9rnJQl4J3fWPBLaleaIS+OzS1vPICPuUXU9m4u+NCg=; b=WpKIVIcib8yds1G66N1njlEXgqIQXVLUGvPxVnaXRmVCT/74xGyCRA/szo0W1Azpm8 QhbJ60/UBxWUL/+uBJsNfR7W5nU2MXHk4POPaYcJUxmrgliXyeLJhAjq8/ynRb3udhYk qr5Tu+3P79rRVV6JE/Qb2toEBMDt+k8eWPx17/Vh3nDerXOQYWJ6u1DNNXP6JQUWJKo1 SPpyKJuuAou3cuQk5LCdUF6XD7jUI2v1GUKUunxQj3IyPSXgNHuZ6X57MNQxizgADXzf 27p1sIyeLYjqdCFttUoGJj1rzxQs/wGmYJ08r81D5hjpWgGBAX//ULFGL3xlftF0PzQN j+sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707816674; x=1708421474; 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=n9rnJQl4J3fWPBLaleaIS+OzS1vPICPuUXU9m4u+NCg=; b=hjF2zUq754+UT2YoZ0qW7MapHvLV2w8wdpHC4b00e6OgisWLizkiklrP68po7nOoQ2 VlJ8EiZ/qOL4SAIeHqwS7lJMOU+VMWTzr295NiCkBdVjDMxzhkFcu0lhRfEoW+ZaEKoX xl1iNEdQ69pCQ2g7x5afgOZA+Rv7zb+CyHOWKkqepjSe0xy10kZn1ofrJd2SYcgI7wJh sF7sDW+OEF4hZXOyh0R05cjIZ0dgJFFDvUdZEPCPlIgXo7L0ATgszCltPaCPydBTVIcx lcM6H/qDX5UzgsYlJin9qWC8UHZ4W/JaiPGS++N+dGxXiVUPl0ryJe9hRr81sayP3yZk V00Q== X-Gm-Message-State: AOJu0YwYwS6NKcT7oGhUmLP1mY7oBQ30ghXqbSMwiF6xoJidXi4ofUft 93Rt7OWeM9biQDg+xEpw+LpE1V/dy7a8DpPPWfW6tasEdgnwdUoGlQxtXHW+pvY= X-Google-Smtp-Source: AGHT+IHA8NduFh3S0lW3tT7CCz4qthUUvzFX/CHmspOBiF1yPKgUnBDscsjoDwIF9SDv6oCR4WUH5A== X-Received: by 2002:adf:e605:0:b0:33c:d310:73cb with SMTP id p5-20020adfe605000000b0033cd31073cbmr1260297wrm.19.1707816673613; Tue, 13 Feb 2024 01:31:13 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVCpzhdCyVsckx1DwQw+DQV3V0HJyofMCefoCgiQb7HwsBF6O+zIxb4U1RLfjD2YvfYXlQ0dQ2jcon/2CkK7mg6W2SEkeJKlIA3x/GLpEPJoE0UGPGcS69TncKIH73+GvG8mMPdsrtmdRBBt2/h4ZQaeu3sQ0mbUI2RJhzIymYrJr72dX3QRHaJV+JexU5my0a0LYSjUJB21OiGO26MsnRbkFDY2QnxJFgJgKtbVFRKLloC3BwIOQ5RZN+fGl24oVazKyLLMgnVANibhoscJ9YgUfDuNLS6DgxQmBEJXzEnaOWk0gleMpxIR+jOFt5UXPlN3BtIlG9A7q5UTzN01OZsfejXu0hTxvLvOjbAH1s= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:f634:2e37:58a9:242a]) by smtp.gmail.com with ESMTPSA id p16-20020adfcc90000000b0033b2497fdaesm8980897wrj.95.2024.02.13.01.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 01:31:13 -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 , kernel test robot Subject: [PATCH 2/3] gpio: cdev: use correct pointer accessors with SRCU Date: Tue, 13 Feb 2024 10:31:07 +0100 Message-Id: <20240213093108.13922-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240213093108.13922-1-brgl@bgdev.pl> References: <20240213093108.13922-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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, unsigned int cmd, guard(srcu)(&lh->gdev->srcu); - if (!rcu_dereference(lh->gdev->chip)) + if (!rcu_access_pointer(lh->gdev->chip)) return -ENODEV; switch (cmd) { @@ -1521,7 +1521,7 @@ static long linereq_ioctl(struct file *file, unsigned int cmd, guard(srcu)(&lr->gdev->srcu); - if (!rcu_dereference(lr->gdev->chip)) + if (!rcu_access_pointer(lr->gdev->chip)) return -ENODEV; switch (cmd) { @@ -1552,7 +1552,7 @@ static __poll_t linereq_poll(struct file *file, guard(srcu)(&lr->gdev->srcu); - if (!rcu_dereference(lr->gdev->chip)) + if (!rcu_access_pointer(lr->gdev->chip)) return EPOLLHUP | EPOLLERR; poll_wait(file, &lr->wait, wait); @@ -1574,7 +1574,7 @@ static ssize_t linereq_read(struct file *file, char __user *buf, guard(srcu)(&lr->gdev->srcu); - if (!rcu_dereference(lr->gdev->chip)) + if (!rcu_access_pointer(lr->gdev->chip)) return -ENODEV; if (count < sizeof(le)) @@ -1875,7 +1875,7 @@ static __poll_t lineevent_poll(struct file *file, guard(srcu)(&le->gdev->srcu); - if (!rcu_dereference(le->gdev->chip)) + if (!rcu_access_pointer(le->gdev->chip)) return EPOLLHUP | EPOLLERR; poll_wait(file, &le->wait, wait); @@ -1913,7 +1913,7 @@ static ssize_t lineevent_read(struct file *file, char __user *buf, guard(srcu)(&le->gdev->srcu); - if (!rcu_dereference(le->gdev->chip)) + if (!rcu_access_pointer(le->gdev->chip)) return -ENODEV; /* @@ -1996,7 +1996,7 @@ static long lineevent_ioctl(struct file *file, unsigned int cmd, guard(srcu)(&le->gdev->srcu); - if (!rcu_dereference(le->gdev->chip)) + if (!rcu_access_pointer(le->gdev->chip)) return -ENODEV; /* @@ -2510,7 +2510,7 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) guard(srcu)(&gdev->srcu); /* We fail any subsequent ioctl():s when the chip is gone */ - if (!rcu_dereference(gdev->chip)) + if (!rcu_access_pointer(gdev->chip)) return -ENODEV; /* Fill in the struct and pass to userspace */ @@ -2595,7 +2595,7 @@ static __poll_t lineinfo_watch_poll(struct file *file, guard(srcu)(&cdev->gdev->srcu); - if (!rcu_dereference(cdev->gdev->chip)) + if (!rcu_access_pointer(cdev->gdev->chip)) return EPOLLHUP | EPOLLERR; poll_wait(file, &cdev->wait, pollt); @@ -2618,7 +2618,7 @@ static ssize_t lineinfo_watch_read(struct file *file, char __user *buf, guard(srcu)(&cdev->gdev->srcu); - if (!rcu_dereference(cdev->gdev->chip)) + if (!rcu_access_pointer(cdev->gdev->chip)) return -ENODEV; #ifndef CONFIG_GPIO_CDEV_V1 @@ -2696,7 +2696,7 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file) guard(srcu)(&gdev->srcu); /* Fail on open if the backing gpiochip is gone */ - if (!rcu_dereference(gdev->chip)) + if (!rcu_access_pointer(gdev->chip)) return -ENODEV; cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); @@ -2796,8 +2796,7 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt) guard(srcu)(&gdev->srcu); - gc = rcu_dereference(gdev->chip); - if (!gc) + if (!rcu_access_pointer(gdev->chip)) return -ENODEV; chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id); From patchwork Tue Feb 13 09:31:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1898135 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=3JphTJhu; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.48.161; helo=sy.mirrors.kernel.org; envelope-from=linux-gpio+bounces-3230-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [147.75.48.161]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TYx104m2Rz23hT for ; Tue, 13 Feb 2024 20:31:48 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 3E9C4B224D2 for ; Tue, 13 Feb 2024 09:31:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 685ED22625; Tue, 13 Feb 2024 09:31:18 +0000 (UTC) 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="3JphTJhu" X-Original-To: linux-gpio@vger.kernel.org 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 926CD224E7 for ; Tue, 13 Feb 2024 09:31:16 +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=1707816678; cv=none; b=cup3yH00YJ4sRw1DgmofgKj13PjJT2+Qm4nz04hUPgPkUrBTqiHx1/B/fKtCdhKgD/Ee3ErvKUGlVvpgs9FbCRbIl0HT88sdxiER22Q0wFH8Om9HL4M+vzidXGVrJfJBlCNIemHRNr/ht61g/LDvjGGhQ5O6/d33kp19opM5cvA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707816678; c=relaxed/simple; bh=bA1DQr6eNnKSnBh6jQHkYSW2oFUilm3Qa6INtty5rTg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HM+JbVbf/8RjEgSrlNDrH4LArhYS2bAIy6pbPK3iCfcch4/0P+/RJFuiwf4ImSnGEnpt+qSITkhT66IiTC/8QgCy7LPZH3ukFgD+a11sjcCm7TrENslPpa1tupOR6cPr248FvPgEtvk1TNXOqpXH4pwP6klHf8aCO8WJBruhtu0= 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=3JphTJhu; 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 Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-411a5a8653aso9132585e9.2 for ; Tue, 13 Feb 2024 01:31:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707816675; x=1708421475; 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=Mgf3CLa998KoIkw7FSWo/gVoKncfOZNXGb2ZGFv5c5c=; b=3JphTJhul1nLTufgIkRV/OjKia16bvHmtq+WgflQWzu0wT9JCYwYUFtpDkN8AE+NE+ m1Nf5Xk1rkjGUeBZzCteTHI0pHK4WMqsxM7dvGsL2hTc1qNnMJETGifnzrrPZ2JU0eTk UNj7kG083YM//xu0RpEyyZFXnMeOsNGcEOk5WUlp/YCOvNodqaAU5oKXTjK2JtxlIfav i5TRT+n0gyVL/2jjKNvAK4UE7UyQszOafxUkImiatRXbMljod9KKwnav6Hw2BWLEsD8I Xn0gp+WTW6bnapmqp+TVt230gEysUwFr69N+DW/dHmTwLRLdxTutB5L1M/QTov8BxZWN pI+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707816675; x=1708421475; 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=Mgf3CLa998KoIkw7FSWo/gVoKncfOZNXGb2ZGFv5c5c=; b=kSZxnQC6DLdpmTFoX5FlD3JNDNC9ojpIg49AYw/uHsW3yhpQw7chw/Cczf2lsmxndQ q/1+799sK1GBTux+dJvSFsoO72PMGo+XCf3eqI+AUo1TdA/6xGXqpt/Wlo97aAcRX1wN rqdBXq00wACK8G7bburtDZsCgtGyEOanAkN5eu08nyCpWfX1c5BnsoxH5a7/YiVX0He+ SqXttk8aoDW3efu7ArO7YzxsLCVsPaiezPhyZc2zsLylRmLGMEZoyYO55yy/DR2dgzW+ aB3rnYFOuQrT+z0BKHxj2C3Vg3t5ngzUxk/ohh398hT0ezrd42I9Nsf7PJzEKF8Do7GW FPQA== X-Gm-Message-State: AOJu0Ywo0wi8Uov3x8u5rs/L/yQYOY3RcF0TS8aLSpf8b1vNGM+pifpB uQXKL4DWaS8FeUuhMDuZU2m9isbMT5ysOq4nvDXL5eoRW/X/YhDNrvkdsIWcHv4= X-Google-Smtp-Source: AGHT+IGu7AV2g+1a36De252fFR0xcNPrjo1k8rYbx+lJBpIvj5d/fm5Zh6zPQRv4el6GZ7jSXCC8kA== X-Received: by 2002:adf:f60d:0:b0:33c:dec9:a269 with SMTP id t13-20020adff60d000000b0033cdec9a269mr401577wrp.57.1707816674892; Tue, 13 Feb 2024 01:31:14 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWBfUUc+m/zso3LmxVL3ectj0GR5TFj6O0zYCe7BNEZt/73ERjArn95DGehdmTOb9lieFNOXZrX9X8WnhABHgbk6/acXcpquEdsU7HOXeUmZz7rY9LKQawaFqddadrkjFUP1jl9kl+7zVpiGOIAzCwqB1LjAcQP3Pb97eDroOD2RxGyrQV1MnFZ8w+uPwgve4vVnjRAHVFnPFyM5HLq+OeIWvFqFouqYyK5m5BZKuj4INOIxAKk2ahGE1lT0VfyHkR4VvEmNiRhQ/edZIfP7sYxq3B4hD88v+2wzhzI+G7WvlQk6yEeHd9vaGDe3aTmYgLYQ5+NejUO//U6pRCtA/JCd4lp33p1mLYFR1MtpM0= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:f634:2e37:58a9:242a]) by smtp.gmail.com with ESMTPSA id p16-20020adfcc90000000b0033b2497fdaesm8980897wrj.95.2024.02.13.01.31.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 01:31:14 -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 , kernel test robot Subject: [PATCH 3/3] gpio: use rcu_dereference_protected() to make lockdep happy Date: Tue, 13 Feb 2024 10:31:08 +0100 Message-Id: <20240213093108.13922-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240213093108.13922-1-brgl@bgdev.pl> References: <20240213093108.13922-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski Lockdep with CONFIG_PROVE_RCU enabled reports false positives about suspicious rcu_dereference() usage. Let's silence it by using rcu_dereference_protected(). 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 --- drivers/gpio/gpiolib.c | 12 ++++++++---- drivers/gpio/gpiolib.h | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index c1391a9a0af6..d7503376b918 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -109,7 +109,8 @@ const char *gpiod_get_label(struct gpio_desc *desc) return "interrupt"; return test_bit(FLAG_REQUESTED, &flags) ? - rcu_dereference(desc->label) : NULL; + rcu_dereference_protected(desc->label, + lockdep_is_held(&desc->srcu)) : NULL; } static int desc_set_label(struct gpio_desc *desc, const char *label) @@ -2978,7 +2979,8 @@ static int gpiod_get_raw_value_commit(const struct gpio_desc *desc) guard(srcu)(&gdev->srcu); - gc = rcu_dereference(gdev->chip); + gc = rcu_dereference_protected(gdev->chip, + lockdep_is_held(&gdev->srcu)); if (!gc) return -ENODEV; @@ -3012,7 +3014,8 @@ static bool gpio_device_chip_cmp(struct gpio_device *gdev, struct gpio_chip *gc) { guard(srcu)(&gdev->srcu); - return gc == rcu_dereference(gdev->chip); + return gc == rcu_dereference_protected(gdev->chip, + lockdep_is_held(&gdev->srcu)); } int gpiod_get_array_value_complex(bool raw, bool can_sleep, @@ -3593,7 +3596,8 @@ int gpiod_to_irq(const struct gpio_desc *desc) gdev = desc->gdev; /* FIXME Cannot use gpio_chip_guard due to const desc. */ guard(srcu)(&gdev->srcu); - gc = rcu_dereference(gdev->chip); + gc = rcu_dereference_protected(gdev->chip, + lockdep_is_held(&gdev->srcu)); if (!gc) return -ENODEV; diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 07443d26cbca..a857848b8955 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -14,6 +14,7 @@ #include #include /* for enum gpiod_flags */ #include +#include #include #include #include @@ -202,7 +203,8 @@ DEFINE_CLASS(gpio_chip_guard, _guard.gdev = desc->gdev; _guard.idx = srcu_read_lock(&_guard.gdev->srcu); - _guard.gc = rcu_dereference(_guard.gdev->chip); + _guard.gc = rcu_dereference_protected(_guard.gdev->chip, + lockdep_is_held(&_guard.gdev->srcu)); _guard; }),