mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lin Tzu Yang <rongh7426@gmail.com>
To: Linus Walleij <linusw@kernel.org>,
	Andrea della Porta <andrea.porta@suse.com>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] pinctrl: rp1: Return -EINVAL for pin settings that are not enabled
Date: Mon, 30 Nov 2026 14:30:13 +0800	[thread overview]
Message-ID: <20261130063013.830741-1-rongh7426@gmail.com> (raw)

struct pinconf_ops says that pin_config_get() should return -EINVAL for
a setting that is supported but not enabled. rp1_pinconf_get() returns
0 with an argument of 0 instead, so callers can't tell an enabled
setting from a disabled one.

This shows up in debugfs, where the generic pinconf dump lists every
bias setting for every pin. With a pull-up set on GPIO17 of a Raspberry
Pi 5, pinconf-pins shows:

  pin 17 (gpio17): input bias disabled, input bias pull down (0 ohms),
  input bias pull up (1 ohms), output drive strength (4 mA), input
  enabled, input schmitt enabled, output enabled, slew rate (0x0)

Return -EINVAL when a boolean setting is not enabled. The slew rate is
reported as a value, and 0 (slow) is a valid one, so leave it as is.

Tested on a Raspberry Pi 5 with the Raspberry Pi OS 6.18.39 kernel,
whose rp1_pinconf_get() has the same structure, by setting each bias on
GPIO17 through gpiolib and reading pinconf-pins:
- before: all 54 pins list all three bias settings, and all list both
  input and output enabled
- after: GPIO17 lists only the bias that was set, no pin lists more
  than one bias, and the 26 pins that list both input and output
  enabled really have both enabled
The mainline change is build tested.

The bug was found and the patch written with the help of an AI coding
assistant (Claude). I tested it on hardware and reviewed the change.

Fixes: e3ce7b897388 ("pinctrl: rp1: Implement RaspberryPi RP1 pinmux/pinconf support")
Signed-off-by: Lin Tzu Yang <rongh7426@gmail.com>
---
 drivers/pinctrl/pinctrl-rp1.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-rp1.c b/drivers/pinctrl/pinctrl-rp1.c
index dd0e85c2ca..7fabd61de5 100644
--- a/drivers/pinctrl/pinctrl-rp1.c
+++ b/drivers/pinctrl/pinctrl-rp1.c
@@ -1545,6 +1545,13 @@ static int rp1_pinconf_get(struct pinctrl_dev *pctldev, unsigned int offset,
 		return -ENOTSUPP;
 	}
 
+	/*
+	 * A boolean setting that is supported but not enabled must return
+	 * -EINVAL. The slew rate is a value, and 0 (slow) is valid.
+	 */
+	if (!arg && param != PIN_CONFIG_SLEW_RATE)
+		return -EINVAL;
+
 	*config = pinconf_to_config_packed(param, arg);
 
 	return 0;
-- 
2.47.3


                 reply	other threads:[~2026-11-30  6:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130063013.830741-1-rongh7426@gmail.com \
    --to=rongh7426@gmail.com \
    --cc=andrea.porta@suse.com \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®