From nobody Sun Feb 8 17:03:30 2026 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 824B0226D1B for ; Wed, 26 Feb 2025 10:12:37 +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=1740564760; cv=none; b=PdGanAYrBjaNicoxLvBVqejKrKAAlek9tekHdcttoNdpUP03VjtpkhKnaSgMHNZC/+MxG/FtP7EgzdWqUUwIa7kPK4xxyq7RJ7u+dmb1lkfQkzl9C+s2HhMR1eypc0VnLgWAt9VGB0FLNK3AZmXoRcpe44D7e2yj8J/g/gefzGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740564760; c=relaxed/simple; bh=T+DvWoJ3d600gaZLdiqHUPv0OxB+F9ErVNNtwPoM0so=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Uvxf3CE1wJmQKSxszhqbrnhpfRp5b2TIT73Qy/QsgN8A/8yH4YHpTmCoN0jPNXLIfTOEC7W8TlrGPM2lMkYuSdx1B60ZoxWFAqmOZCLKfGc9yKJIQoMWJzRuTEwomHknjrMYhRtzj5lJzAPmyKDApxxrrRI5r+oms7kRe126IV8= 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=oykU5rVV; 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 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="oykU5rVV" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-390dc0a7605so182869f8f.1 for ; Wed, 26 Feb 2025 02:12:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1740564756; x=1741169556; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=qBuSqv8U6oPt+UruofT1eAcRQvGHYTW9Mm81Y61uXjQ=; b=oykU5rVV2nxoCJOvurNAeAOZea2b3Ku6BOry2i7nKHZzN6L3plJD/sfVyqifkcdk/g i1hfmmugKG+7w8q85BK/eHd8Abc46EDsv0QA55NoAVy7Xy6qRu8bFYPOB+03QZfjJmTu TycL6KA8kmmFP41MU0F13gOmuF1EYmOqQ0Ott9GR0/MoIkNRBqUYWxxKGHMym9/uS0dz raxaIxweYgyi3seojouRLDQ2B7fumyClwZswNkyXo7WMUASDOJEIysmLK+ibfUFc5rNx Xbc0yZEAHpxEcWO8NeBJZuXD/lK3rbpIE/DJ41uxzuAyMhp/8AAL8BENG+TUKBK4JvR8 42GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740564756; x=1741169556; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qBuSqv8U6oPt+UruofT1eAcRQvGHYTW9Mm81Y61uXjQ=; b=nx+xlnz1RWWDhypLaTs8s/pvR2VDpLZWK7KuN/ItkHB+vH7xTkdATsOTJdpS6EMeUt Anggb5Vfl0ElDLt/C1CQS/JC2tzNRYf6+iRHvM5+kOCAe76gYuWrGY0W7GZemrDZE1Ls nzl+zq6fNoG2c8Jx0eIUhpwz5dUdEEOYxwMF229gWRqtzZu2kUV8v/2n2BJcw31UqPf6 6xEYwppGn6kVs246RG+CHH5ZAIaSUuftQ13XzK56sbGR9Yt1bRPbIuIQH/LFGgGypMAk mIhR3Oyi1zpnoCI85mu8IASbtr3KHPc63jrYS/zYUpd6q3vQESqUuuwgBJBRmZ+aa2UB KM+g== X-Forwarded-Encrypted: i=1; AJvYcCUBaYkqKKDPcloXErhikpU4Wv6lJbw6Zn2PlhjdfX9FhJaQSKjHyWanZEVwdojlcn1U2Yq5C1GXpsqEOvU=@vger.kernel.org X-Gm-Message-State: AOJu0YydLq1DT8i1Ejd7+6LzmJBC6h3H0t6FhaCxIzoAdXf9g4T8rDw9 HiNWRUDWaEo1oiTv6JxfbTb4reDuSRAOzB2G7pH8PnWLKa3GqMer7a9G7FldSNU= X-Gm-Gg: ASbGncsiZEXe9kgK3urn18ldYst/kXsU5Hi9vKwr78g5JvP2VZ9eU+Ku3BjQbojgqv7 JqzEY8/Fbk9bEMvjQP/rsr9JS0uzBK5tD/uvH/mricAaAoELI/puKTW8MoO9gpWlz5wjECfMSCE /ThrC0QUjPJxPq3xMQL6thPoM5yIeQfmRD5M65HSHuzc2cQPZqbn3JDwZZSXtHgZWnA1ORosxe1 05DdDWR6WC/HAWayCRC8Xn19y1NO9LrY5e3NFWPYyQaxDibSn21rsqp/Vh9Uz9Ix+loPpF/DY9w 72jlBwD7ybNdjbxC X-Google-Smtp-Source: AGHT+IGXahza8+pgZHBEcw1zePUFK+hWBCP+n/Guhk4nkRUypakh/M2YyW49+Qbm0D3vBistdRcyPw== X-Received: by 2002:a05:6000:4026:b0:38d:e3e2:27e5 with SMTP id ffacd0b85a97d-390cc5f5cc8mr5148096f8f.5.1740564755790; Wed, 26 Feb 2025 02:12:35 -0800 (PST) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:7d02:26:5770:658c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390d649cd17sm1483971f8f.79.2025.02.26.02.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 02:12:35 -0800 (PST) From: Bartosz Golaszewski Date: Wed, 26 Feb 2025 11:12:29 +0100 Subject: [PATCH v2 1/3] gpiolib: don't use gpiochip_get_direction() when registering a chip Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250226-retval-fixes-v2-1-c8dc57182441@linaro.org> References: <20250226-retval-fixes-v2-0-c8dc57182441@linaro.org> In-Reply-To: <20250226-retval-fixes-v2-0-c8dc57182441@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Marek Szyprowski , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , Andy Shevchenko X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2606; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=T0U7zjnCJI5TuBh0FRLafeo2x7uRS6C7bNJUfU7L0Jo=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnvukR0zWoGJb1QaqisH627aepIT6mvQ8MiFtUw 2MpuzffGEqJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZ77pEQAKCRARpy6gFHHX cvhRD/9Y6xIIcxHUuGIo5YT71HKxn5aN04sPKG5awKJX7eZ0TBA18ifJJ66R5EUZs7pAzBQvnKx 4vpUaJ+P8cUm91Ah6eGtOWy71tmB8J96aASVF9qLfB63LKdyJ2/r39KIgD2ZJVFs4Nq4avi/o+K voZ0FEP7GyX2AQuoqueKHMBHmrLxML8kuL8104AUeMlGDQ1olTPKXoO8/bMIbwJTgCRfiWtvZfU IeUCndz6TnI//ruZt7eVqD4y43lAMMlGJRV/WxC3RYn1lKedpVxaHLk25QS1T0+KpsM9upffHTT ZxzREAdYKag4TgoB+VWQR6Iua7u5jOi7Dx2O620k2fC9l0B771Kw08F6n1ruSvv9y/269iBrAFK Xj3j+GSsOlYAIWY+RaoXGXI9Jr2ouYBr98B54BSWzPTwHI/bcRAbaKICCQlflAseMnHx0zIrJBz g+4SunMsmXbOXOaVwqj7aH6R9dwXQFRIGnTroBMCXeK632mBAmVpGK52EG/5yt4wl2ls/khtyNl Fde/jmVJD/ye+0f6xV0XzDmhxEmIKm4Wul9RWRq9xuxGcn2RKtNbYDOJmGQh9gjouvgbuGVGCr7 IFjcZcHAh/0mMU6xL7w5Lzk4IUbKC6l7p4UsdMYgE+P5/LUm6Mmrq7jnKFPZJJPT1FF0PJIRJ6P X3hMKkGo7HVgE0g== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski During chip registration we should neither check the return value of gc->get_direction() nor hold the SRCU lock when calling it. The former is because pin controllers may have pins set to alternate functions and return errors from their get_direction() callbacks. That's alright - we should default to the safe INPUT state and not bail-out. The latter is not needed because we haven't registered the chip yet so there's nothing to protect against dynamic removal. In fact: we currently hit a lockdep splat. Revert to calling the gc->get_direction() callback directly and *not* checking its value. Fixes: 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_dir= ection()") Fixes: e623c4303ed1 ("gpiolib: sanitize the return value of gpio_chip::get_= direction()") Reported-by: Marek Szyprowski Closes: https://lore.kernel.org/all/81f890fc-6688-42f0-9756-567efc8bb97a@sa= msung.com/ Reviewed-by: Andy Shevchenko Tested-by: Marek Szyprowski Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index e8678a6c82ea..0d325cc41af3 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1082,24 +1082,19 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc= , void *data, =20 desc->gdev =3D gdev; =20 - if (gc->get_direction && gpiochip_line_is_valid(gc, desc_index)) { - ret =3D gpiochip_get_direction(gc, desc_index); - if (ret < 0) - /* - * FIXME: Bail-out here once all GPIO drivers - * are updated to not return errors in - * situations that can be considered normal - * operation. - */ - dev_warn(&gdev->dev, - "%s: get_direction failed: %d\n", - __func__, ret); - - assign_bit(FLAG_IS_OUT, &desc->flags, !ret); - } else { + /* + * We would typically want to use gpiochip_get_direction() here + * but we must not check the return value and bail-out as pin + * controllers can have pins configured to alternate functions + * and return -EINVAL. Also: there's no need to take the SRCU + * lock here. + */ + if (gc->get_direction && gpiochip_line_is_valid(gc, desc_index)) + assign_bit(FLAG_IS_OUT, &desc->flags, + !gc->get_direction(gc, desc_index)); + else assign_bit(FLAG_IS_OUT, &desc->flags, !gc->direction_input); - } } =20 ret =3D of_gpiochip_add(gc); --=20 2.45.2 From nobody Sun Feb 8 17:03:30 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 2D0E624DFFB for ; Wed, 26 Feb 2025 10:12:38 +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=1740564760; cv=none; b=NXKQvxY57TIEM0tO64+kuuG23fdxt593k9gHbVw73ZhNTIegmKtKhjQZmynJRHnTRymPVkkVRCwh92cSzebbL/X0SOV18XOGlvPA50usYxOwNmx4ZxAKav+Ga2VshShOnvKQVdEul3plYDHKK52nJCauRQmx4jmjNnQEdIYUFOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740564760; c=relaxed/simple; bh=AOtsqlOUd+Q3nrmqeeuq8/tgBq1NpytDTQzjNybTiww=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=plRYKhfggwS+/6aYiT6ZbpqM51hK6JuajqSmk6Uv8FlJNJlCiuS+Q5vU7N7L3p4g4wCuxOhltGkP7aWDWX0epaxqGUi4DC3xtV9EdPqaG/kUF2jaoPo2zSQhoalPyo/7QQ9oy0QfFOczWKmCAFs9k9Wv41BuLOJUywBt7Wyn02o= 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=ufXRY/Un; 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="ufXRY/Un" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4397e5d5d99so41476545e9.1 for ; Wed, 26 Feb 2025 02:12:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1740564757; x=1741169557; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Gf7zrHqAdgnbRAeeIHqjXUoytiZ19dAcrK1RDj790h0=; b=ufXRY/UnBPhppJT5aYf8fpuUhSmUHQT9sjD5sOWAbT8iMae54twrfJGmBuHT3Ur2Yr k56fuzhMbjuLk5+ok9Z2GnCKxSVVOw/n/c7CiEGFbvRR+vj3W+/AlejFLFaJhWC6vIhn 6J1SSsAdzECZkW+mqMIRJ9dWmE9J3cetj1L/LPtlQ7Pyfjm8AFzbZXHFGt5znNt0E62+ PqZg/4woy5R430X0p1xD1xwvQv9qZTm200ZPg8yb4nocQdJNKnCyoqswQn3lP11HNNS8 i4kgataGulv6s6WItgFwAvPO9GNYJwg7Eo1VbmVJjEOUWrnLW7rNwEvLRqzMHxVTCm1G jk8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740564757; x=1741169557; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gf7zrHqAdgnbRAeeIHqjXUoytiZ19dAcrK1RDj790h0=; b=FaYmcscsolJriWJGjJ5yvTBn4y99VYMOJlVQx7ZnH6mXi0gRvlEWKLs9a23DRbnEFY sb5qWQ7SU7Q7s17iYr7j6Y926tYgAKGkAVw4Jy/QrxbZVs/Wwl+MAmHGOisL+8RScBYd rFEpbXixAT+cRbXVWtwNPOjDSNSr9ddxcWGiBWbLrztVvTVLiL+9DMtO39ImNsS+NrGy ALj4/WGTfsP9upC/QmWf+DJ/U9NCed4gNcIeWuE6jAQcaDinXuypgmReJhjVZrTzJ7v9 YB4081HMsEYYfpozH+JbJskdXPIFp0msG2g145qrO6vIGOLU2Ld6M2jlTeY8zJxC9J+C fY8w== X-Forwarded-Encrypted: i=1; AJvYcCXFVRU3L/HtTGOziDeKL0lPkPdbgQacp2HJcTq2Byl2KNqzNxSai9PoniO4iYn4FjCYiZ634FV97NgHSWk=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2afA+esn7CTO+mS4ws1+QU4F2O+9jZRAQehQMLgyhGNhcVDup dUZMi05ACcuqhUI6paFfnXDAHwyCARhBIOUazm02xc5uk8xJNtZAeuSno8Roa+o= X-Gm-Gg: ASbGnct/2kgpFgyJSMTSo1LwJM3fayGGhXuLfrhceD6RTaZrQgroa2ZU5bXNPxo+83U RBQtlzN2oSWEQ6+nItH34ELrpzCpvY2tydAnMzXYTpSRqIIELSOnNLFVbYnsEzFViFG2KxlsCvQ 013uZbi5tKv8CpmpFSUq5BzLAh+Blu0VBgQ/0kMKTkrTEiJYLTS+R0s5ZGnanJXV/2JUi9GtjTO SxEWZ26S0TSNkLGkjacuMVQpC5r87SuF5BLUR81U9j2BfVTZDKfFWuWTHtRHtsZA8guKJyB2EDo duErHdluOdr8gkPu X-Google-Smtp-Source: AGHT+IGEaNiDzOSieP71Ur9Z89WNZbFkGIfzR9lLcxLKiZmPznX1O0XMm0LCjDQo7uBizOeM3s/rAg== X-Received: by 2002:a05:6000:1f82:b0:38f:2113:fba0 with SMTP id ffacd0b85a97d-390cc63cf15mr5755133f8f.50.1740564756809; Wed, 26 Feb 2025 02:12:36 -0800 (PST) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:7d02:26:5770:658c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390d649cd17sm1483971f8f.79.2025.02.26.02.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 02:12:36 -0800 (PST) From: Bartosz Golaszewski Date: Wed, 26 Feb 2025 11:12:30 +0100 Subject: [PATCH v2 2/3] gpiolib: use a more explicit retval logic in gpiochip_get_direction() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250226-retval-fixes-v2-2-c8dc57182441@linaro.org> References: <20250226-retval-fixes-v2-0-c8dc57182441@linaro.org> In-Reply-To: <20250226-retval-fixes-v2-0-c8dc57182441@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Marek Szyprowski , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , Andy Shevchenko X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1207; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=mqJk5RX1yeclgYqC4arydwTfWo3zYHbBnoSeksuNJvk=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnvukRgYaEPCh7qqnfMzCFxviPlkm5aT7bVUnTR +XWoAPxKAKJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZ77pEQAKCRARpy6gFHHX cgRqD/9IhwDCta6+RtlkqzzyGimA0gsF8Sdeb8/gADVc2d6rgFwk5/c1NICXL81zhA6U4zjsVF8 DcKKoiW+WL/i0Vshix0yPqX5nP/pRFkyAd5vwujmRCViUuuzmKiag5aISU5+AEJGk8mltndzjBY Xu1p/oi9DVloQDygDH/UKPTcqzBx0/lWF5GR8S4tnB5W5vWzq3JOyX86H90F63BuLOl5Qk6YPJa Z1H15WJXbrPipUf1cuVlNP5VSrpMNgFFndUg9CLbS6++WCwmr+ExMcM3TUzw5TQXPheGadcqoh+ 2CFhshj6e2atxYB1UVt+HzykZsb/f0Nfv8AITpgWroa/xmM+0gxG3XcpkrKZsWShKmpptxtM1Ja snCIrRVHlHXL6tt49NgFMQSzNKj3cDDr+57Lel2sUChD5wvwgpPReXH86jRk/PAi6+f/1al5PHL dWVGLfzjRBPJ2Rw3SaoVc5ZTMcGmp8s52v8q8mJVibd9p2XUkD1Ijue5yqc7eiGYnFprwIZlvaH to818oa3445E3pwR452lDP+qNLpaRQv+ZJHvg+bJWRcoji9XZCyVgjj6lvXTgEkMxvYEt+kuxNK igGKicPIWU+s3dJwdUOpwf/naSnfhVP1MN2ZO7f/Tx0ZAJaj7/TI62MnA24MFp654dYBirR2fe+ MrEh95t9BZnBayw== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski We have existing macros for direction settings so we don't need to rely on the magic value of 1 in the retval check. Use readable logic that explicitly says we expect INPUT, OUTPUT or a negative errno and nothing else in gpiochip_get_direction(). Fixes: e623c4303ed1 ("gpiolib: sanitize the return value of gpio_chip::get_= direction()") Suggested-by: Andy Shevchenko Closes: https://lore.kernel.org/all/Z7yfTggRrk3K6srs@black.fi.intel.com/ Reviewed-by: Andy Shevchenko Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 0d325cc41af3..6f4efab237e6 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -352,7 +352,10 @@ static int gpiochip_get_direction(struct gpio_chip *gc= , unsigned int offset) return -EOPNOTSUPP; =20 ret =3D gc->get_direction(gc, offset); - if (ret > 1) + if (ret < 0) + return ret; + + if (ret !=3D GPIO_LINE_DIRECTION_OUT && ret !=3D GPIO_LINE_DIRECTION_IN) ret =3D -EBADE; =20 return ret; --=20 2.45.2 From nobody Sun Feb 8 17:03:30 2026 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5417224DFFC for ; Wed, 26 Feb 2025 10:12:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740564761; cv=none; b=Pvg5nAEDc/RchM4y9UJrEgmNKJGVj8EF79K4D1HFtZkvKLZ2xdm8l+Plnc6L+PwwFMFgjwcQbyUHQZTpesrM1Fa2YyGFyH3TwkqzTK1h/vHpaKrNjloRSPXMzoGVnBS8/x+OW1Igo2hpgML1eU8s1+0ZfmBpBp2Kxz1dP64OfaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740564761; c=relaxed/simple; bh=yl4u373flK8LJfjWUsP2xVHNgE+51/Hq8Uvf8MU1tjA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sR5SPr+uGCyeoAJiff6Ya1yY1fF6EaZzzN5iYqavWO+OWd1t+4oNjZJC64o6WN6psUDBmrIVM0/YZHbZ2W07kHgX2Yl8PukStNP5D7AdGcE7Cv5RG3PbtPofcAl1z2VdI+GgDuauudaHSYHxueKmV5zZm0mCLaomb5ZodTFJzI0= 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=wtjJgX6m; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="wtjJgX6m" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-38dcac27bcbso439703f8f.0 for ; Wed, 26 Feb 2025 02:12:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1740564757; x=1741169557; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=RPAblM/ytVXYD0FxHSQbshSRnztgL04mI7LHXRwbPuA=; b=wtjJgX6md7DIvKYdLF3LoVXjcgfHU3tZqcbgkecSlYGXl8ZH5XvK0qWW56JVKkdRM5 JxdPB6TljzOEIPdp2Ld8yxscRBXiBwuKudcAZMeMS9PE3QhyP+gvsblTS0VaCqh8iMOC k/ksTbs54Ay6a7oFjFrTjcuaHYip5jEDIyE9JgD3LctGQaWmXmMCgSWvhQfw0FbJnGo1 Urcr7q2wU55BkxcstEOZh5knSroCNwDfyaXDMIANuADlPFm3wyw3bq+GilP0krtWdg+0 6+O5m9FfMYUP9FmZqnzWgsK3YnUXqvuDdsvTD3dn56uf45THamdQrOd0as0VTJXkfmKO i42w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740564758; x=1741169558; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RPAblM/ytVXYD0FxHSQbshSRnztgL04mI7LHXRwbPuA=; b=CEwN2/huPXITWayksszmv8kLM7cTmBMckDoNkO3bbMrnEH/45WcfmuadapPPnxO5Cs BFWRl6dblROz4WjSfU3vSEDNgWUfW2iNgP5qAhn5TR+Jo88uWDLTjkEWaRw1LP815g9A 7IL822C88Q6oJMAscUF5onnIIKekxwM5YmYj6GuPZZzXULfyY3y06xLrbloGSnXH4YbL 4gb1tvTUqXCQWnTPgugx+BlS53kaDxDm6NPmROr1jNICyUi1rW2ivAiAkHmEoukRoafE /U6QrO1EOza7XBIcwq18YhMOFtcmyy9zukiKQ5Tiqg91/qkyqJcc5SwdvoYko6rF3YMG q3bA== X-Forwarded-Encrypted: i=1; AJvYcCUZWeoQy+Vw0hzfXeu2odaip70PHw4NSoXV1jcvbfklWFN5mWI6/nx9GeBBQxdc8KsArTmzZWY9KHZW0j0=@vger.kernel.org X-Gm-Message-State: AOJu0YyuwfedhnqVyja+osHSL7gLEsqb1elhEUFELqoiW7Y4wT3plepp 7RnEdV8NncfueefRArO3dDrjocrFWvh33JM7N0FUT/JNqHrO0hQOUV2jACIoPhY= X-Gm-Gg: ASbGncv9rXT3PGCG5WG37xVocgweK2kb4axQKtELIT5Tmw6R7tjrIRgwKpkbjkP8wm9 6T8dFn5EdMSHR5T2iCf1T38NUuoQhkxYbSG8H8JUcHy/GgU0Vmk0fcPZ9vZT44OlNNdWf9LmiOR qf8rydg+VszD1teqehkoSi2djY1HxdMtivJUE/QdgVCBUviRwVP/VV2EQ3qVXoLTbdHMjLM9D0T G4pZSR75yLd07Np8N5RDWL+VIa/tgzXdq+YdDWzjLHNbvrzim4bujFchWMlPNqmYUVU11YFsxnT 8K0cjA43fqNC/c1+ X-Google-Smtp-Source: AGHT+IHw+bfS7gpMnzsf2DgNmUri32seSJz1+dPSYtDo9d0ITkyKGqVomiEoZhjVURuzeKQ9X02AOA== X-Received: by 2002:a05:6000:1f87:b0:38d:ae4e:2267 with SMTP id ffacd0b85a97d-38f6f3cd3cbmr15942757f8f.11.1740564757589; Wed, 26 Feb 2025 02:12:37 -0800 (PST) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:7d02:26:5770:658c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390d649cd17sm1483971f8f.79.2025.02.26.02.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 02:12:37 -0800 (PST) From: Bartosz Golaszewski Date: Wed, 26 Feb 2025 11:12:31 +0100 Subject: [PATCH v2 3/3] gpiolib: don't double-check the gc->get callback's existence Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250226-retval-fixes-v2-3-c8dc57182441@linaro.org> References: <20250226-retval-fixes-v2-0-c8dc57182441@linaro.org> In-Reply-To: <20250226-retval-fixes-v2-0-c8dc57182441@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Marek Szyprowski , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , Andy Shevchenko X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1560; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=L6UhmUffsmnJ8WOjgKKZG7Z+1T8Z55OqnZX+P3gqo14=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnvukRT1APi8R4HYEl7lqYNlvJr3sIjTg26NOQz pE42xfJ8FqJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZ77pEQAKCRARpy6gFHHX cl8fD/4kEkdnFtjtgtYKMBJ0MqwAAwprVYwFXpEpoVTBWEnrkfRVpJPuscxNFGLE0z1ky5ASyge 5bV3S+XTmZ6qJquvkExLqpl6GprNOr9xfWC5dYJogA7aQCi4AEMvUYFuI2AIwJubMSnq4eHsEwz sZYCMag4n0Eu3oUCdN+zgnj/0S2zUFfNAsKySLJ2/lEPYXH2BXfIqrZTKEfetM1OJo/TFJF4vay 0shro278EkfnTIES3lm8kMqv56JS2SZrh4XkIS1CdWnrrwOb1NhkytzVlpt22KEwaPBy1Q2KE8e vVSun3el3Sb7yatNIFY+vfY5BR68/lUvxgCmSWPsky7Pph8aQ6EiQJN1SVNUFcoVBUBuhbnrogt sEhZVqVcsvdCCloKBNC1Esh7v7COwScYUFmeJ82Jg+Zu4tR7zGtTODVho/IcOY8YLUECD+R60v/ g84tWR6ajnc+c6V8iGMQD2oVqlTns9Nc5AwdM5JFYRtS+OF/nxKt3x4++QRhTaG29ZVzD0gpdKI 15hWMGowbXB0g5NW6QtiiRii4opyvLN6q7eWf+d66hQQk61gfIU321GIBavGvoCaiitsAvhFNvh XmilhYkNYq12CvIO+5vx6pkZ7Fs+jnELcGpZuFaHmKjl41ovKGP0CXTB36JuvRpkHvAvQ3XxTGk J0yNwM83f2Sr48w== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski gpiochip_get() is called only in two places: in gpio_chip_get_value() and in gpiochip_get_multiple() where the existence of the gc->get() callback is already checked. It makes sense to unduplicate the check by moving it one level up the stack. Fixes: 86ef402d805d ("gpiolib: sanitize the return value of gpio_chip::get(= )") Suggested-by: Andy Shevchenko Closes: https://lore.kernel.org/all/Z7yekJ8uRh8dphKn@black.fi.intel.com/ Reviewed-by: Andy Shevchenko Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6f4efab237e6..855373eb11a8 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -3167,9 +3167,7 @@ static int gpiochip_get(struct gpio_chip *gc, unsigne= d int offset) =20 lockdep_assert_held(&gc->gpiodev->srcu); =20 - if (!gc->get) - return -EIO; - + /* Make sure this is called after checking for gc->get(). */ ret =3D gc->get(gc, offset); if (ret > 1) ret =3D -EBADE; @@ -3179,7 +3177,7 @@ static int gpiochip_get(struct gpio_chip *gc, unsigne= d int offset) =20 static int gpio_chip_get_value(struct gpio_chip *gc, const struct gpio_des= c *desc) { - return gpiochip_get(gc, gpio_chip_hwgpio(desc)); + return gc->get ? gpiochip_get(gc, gpio_chip_hwgpio(desc)) : -EIO; } =20 /* I/O calls are only valid after configuration completed; the relevant --=20 2.45.2