From patchwork Wed Feb 14 08:44:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1898616 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=jenTWXeo; 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-3256-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) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TZWwM1813z23hY for ; Wed, 14 Feb 2024 19:44:51 +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 BC258B2511A for ; Wed, 14 Feb 2024 08:44:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 16FA679EF; Wed, 14 Feb 2024 08:44:28 +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="jenTWXeo" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.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 700955CBD for ; Wed, 14 Feb 2024 08:44:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707900267; cv=none; b=Ef3d+EHPYkKJH9dZm1PaFcC9pGbM6UwruEWpa3ecahxmy2LXC3+m1jNOKyaYX1EmqQ6UqoobmR7GGnngVubH/fVrI9kFk+GM4AG7rbFRUl7YuPReYAayJbBurlKAZBUTWFXS/kZUP6kCgJCPvHYN0TEbZngFKIiRDErJ4QdJ0k0= 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.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-wr1-f48.google.com with SMTP id ffacd0b85a97d-33cd57b7eabso909080f8f.2 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=c/4FsJ40CUIhMA26MZhRNnXtnAQkrlA7AbeN4tDcnlT/CvcRuGoLvDPAjF0YDsffGV Lr5Mi2GTySEi9bbsJTqeyYrOFs0UktszOUXv+GN2gpCPKHJ9d4FRKwhyuq4srwIwHQyN eR+7WHj4J8dSuHSQFJ5WbxSyWPNbpip3NW5CWAKqSxV2XoaWIolwGEUiP5jBVYGt89oZ afP9MPhwHGhsx6x0H21uY8ll8CfaFAIT5UodWiyj9HlZfJumxkf/3ijQf0zfe4PYNgq2 1UufdjCqCp/KEf58mhNVkEcYsNNU6WD9j3PpeqyRrqqgwG9GoyPpALl0XNwf+jV2sD8G jMAg== X-Gm-Message-State: AOJu0YwleiBVBlxn7AFOa5QgY4m/7LGK4cWSkBZhlB4rrY4TdFba+c5+ 09CdM9z6dHEdHsE9g3FbFBzm2NM/d5iDkvBSW0tzi1lm4tGnb930AauPnsHrCmQ= 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-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 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 = 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 Wed Feb 14 08:44:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1898617 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=K2kq0q/W; 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-3257-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 4TZWwS3h1Sz23j8 for ; Wed, 14 Feb 2024 19:44:56 +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 1BA85B25374 for ; Wed, 14 Feb 2024 08:44:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 84CB4AD4B; Wed, 14 Feb 2024 08:44:28 +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="K2kq0q/W" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.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 989D96FAD for ; Wed, 14 Feb 2024 08:44:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707900268; cv=none; b=TrLBFj9ph5V8g7qb8QcAYZL8rPiX46TDqDXGhTfUbB+atb9HqQ8zS8eNbLsQ32lE5z1ITd1hy6n/4ZdXYx5+SlW0c2IE/TnVlm5AVzueBqvzafvyocvHybgRL9mFywPJlcY4XsbzPWNAXQk0QiBoKQ0y8iKFXjSEdnVLWZwRomI= 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.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 Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-411e698e679so2807425e9.1 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=CoouxXgqxfhMqNkE2ZRKBT9TfKFgOKRCbgUTMzeCIaOJXsa3vsHlVCXXD99VGPN+1+ 3SKVyQZNEmNg9FyHQNGr32o5gvpkITW+lwdPg3xgmMu/pzLFrNQDATihSkAajjlijCPE U6NJUW+Z6s6iR7L82IGAJydvB4QDCGN3qje4B9kgR51j/JeMg31eUP+sN93uhCU2OmWJ 0CfPGtSt6aokyDPvrN3Yh48VvCwPet4YXjEi5PKTlzieFrh+6Gd8qw34G8vGJL6CnRmd R+irrdFfY9Jh6izyeRZeaWH/Cym6z9LCWvjEEWNZKaSDScJ5oF3j1pQIebXTUZpJ5IdJ aIUA== X-Gm-Message-State: AOJu0YyQF5i2uicaws26z53Z8zLPX+UdKv5ne0zXQiSZ55PD2ot5FUw/ eW50fEnmtIcPUPEkagMNd2phUjdUu15W4Y8LM8Q8tCkT2Kz5UckorEi1yR4xsnE= 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-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 Wed Feb 14 08:44:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1898618 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=tphwpPST; 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-3258-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) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TZWwj0hNmz23hM for ; Wed, 14 Feb 2024 19:45:09 +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 572F728C5DD for ; Wed, 14 Feb 2024 08:45:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A6B512B60; Wed, 14 Feb 2024 08:44:29 +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="tphwpPST" X-Original-To: linux-gpio@vger.kernel.org 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 ADC9E79D2 for ; Wed, 14 Feb 2024 08:44:27 +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=1707900269; cv=none; b=Imru1l5EWiXtpkw8fwywpkEvOzKiZm6xEZhnnUyQyEEhjUzN4gXm3GSK/rBNgep/wdoYjK8u9TRRrfnT62SCUX8OGwlgK1BvUSK9ZI8LwE4Sgib/uJ2P3U6KTtr5rFR2eszuO5Y5eLnxdrD1+HnAJ1mpjwtfZczE8ozIIpT2AN0= 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.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 Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-411ebf81294so2119345e9.3 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=ZfjYZ0u80DjwfDqqR4zUtUionTqvQpBHyBVCO3UqS0iQj3RKh6mYZe9zECy/nCY3eC Hsya8JPdqQGQ5FF7+F58W8X/V7IZYrwrzQ+tKEGqXDIz8KWAjDRipsvkfozDnICcSDhr 1lsRFN5D0qpJVr617mIFvhY+321eHwn7WMy8LkKJXKf/tva8QyBJbkpm0vru42499MEt fN5J7e9bEhWGIunrNpBJpzyfnORGdzE18lwosP3L0xEQaoGxPu0uNS+XBDr+cE/LZ/in qdro4QWknOT14RdwlhZMtubW3BHGpw3RXahkJdQKzI2bdZ//U9U9UiooFWNdwfxuyW9s ojNg== X-Gm-Message-State: AOJu0YzPAAwJW+gCKcu+7dP8soiiKh25Q5S70LIvTr4kFf5GU8WmPaOm ZppuWEXfJSfhT9QoHZep9Zq1Oa1VkcNEUhSeGMO/D0W68AwaEwg0Itcx4qVXGns= 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-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 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 --- 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 @@ -756,7 +757,7 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) guard(srcu)(&gdev->srcu); - chip = rcu_dereference(gdev->chip); + chip = srcu_dereference(gdev->chip, &gdev->srcu); if (!chip) return -ENODEV; @@ -800,7 +801,7 @@ void gpiochip_sysfs_unregister(struct gpio_device *gdev) guard(srcu)(&gdev->srcu); - chip = rcu_dereference(gdev->chip); + chip = srcu_dereference(gdev->chip, &gdev->srcu); if (chip) return; 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"; return test_bit(FLAG_REQUESTED, &flags) ? - rcu_dereference(desc->label) : NULL; + srcu_dereference(desc->label, &desc->srcu) : NULL; } 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); - gc = rcu_dereference(gdev->chip); + gc = srcu_dereference(gdev->chip, &gdev->srcu); if (!gc) continue; @@ -1190,7 +1190,7 @@ struct gpio_device *gpio_device_find(void *data, srcu_read_lock_held(&gpio_devices_srcu)) { guard(srcu)(&gdev->srcu); - gc = rcu_dereference(gdev->chip); + gc = srcu_dereference(gdev->chip, &gdev->srcu); if (gc && match(gc, data)) return gpio_device_get(gdev); @@ -2978,7 +2978,7 @@ static int gpiod_get_raw_value_commit(const struct gpio_desc *desc) guard(srcu)(&gdev->srcu); - gc = rcu_dereference(gdev->chip); + gc = srcu_dereference(gdev->chip, &gdev->srcu); if (!gc) return -ENODEV; @@ -3012,7 +3012,7 @@ 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 == srcu_dereference(gdev->chip, &gdev->srcu); } 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 = desc->gdev; /* FIXME Cannot use gpio_chip_guard due to const desc. */ guard(srcu)(&gdev->srcu); - gc = rcu_dereference(gdev->chip); + gc = srcu_dereference(gdev->chip, &gdev->srcu); if (!gc) return -ENODEV; @@ -4787,7 +4787,7 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev) guard(srcu)(&gdev->srcu); - gc = rcu_dereference(gdev->chip); + gc = 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) guard(srcu)(&gdev->srcu); - gc = rcu_dereference(gdev->chip); + gc = 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, _guard.gdev = desc->gdev; _guard.idx = srcu_read_lock(&_guard.gdev->srcu); - _guard.gc = rcu_dereference(_guard.gdev->chip); + _guard.gc = srcu_dereference(_guard.gdev->chip, + &_guard.gdev->srcu); _guard; }), From patchwork Wed Feb 14 08:44:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1898619 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=F3LNjgJj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-gpio+bounces-3259-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (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 4TZWx25YrWz23hM for ; Wed, 14 Feb 2024 19:45:26 +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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5AE461C26548 for ; Wed, 14 Feb 2024 08:45:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E1BC12E44; Wed, 14 Feb 2024 08:44:30 +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="F3LNjgJj" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.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 DDAB9BE5A for ; Wed, 14 Feb 2024 08:44:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707900270; cv=none; b=H2X/zJ5nrba4GkAaWcs1YtEZNSnSvtbHq2cb4x32gE3tOcbWGh1shD9P7CNRB9oAFLhWLBmGwm68wx6pENIFsi6c61UHY8Gqz7i1F6qCRSXomZulN213sL+pvhnmxSp6qFxFMSZlD1YdhTA9F82sEP6j4Qb8Lx92ZwHxOYlWXGE= 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.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 Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-337d05b8942so4225578f8f.3 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=rSpo6grKSZxKYzbufRc2IUpaSqnrB3lCj1PtpdH28pO4wTvXQZ2MstZvCgPmzLYTM8 sIA24bIy2lOw/b+MC21Z7I1Vz+mhrk6ZncJrekVDMl0th2KTYIvVzsf06IE4DasUed57 EAQIeUN8AtlmWhil6gRsQYCJgg4h25p83yz0TJ+yywQtD2OA+zqMknFUBhFUilRAjoPy Lbm3pZg64Fd7f30mqYeVYNPFuLqwbkVF+8aRMPQHAppIxadQzOQwatrixSl8FU8eQR5F 0VdkJn50TIsMc6oBH+0V3oSSrREm9lBRKvACAQUBZZuxARRlYlzmXgYIZVoLpSe8W7Zy p6sg== X-Gm-Message-State: AOJu0Ywe+RZB7RS6ebZI5FFDNO0Xc6PifQKVPPhv24PaNkj+rZmqtYCX cyfSkcbDD1gpHO6CWulZlANa/DaS6L/eNrBeb5VnmEvl55oHADu7kQ6yEZHX2Dk= 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-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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); @@ -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);