This series improves diagnosability of GPIO offset collisions and fixes
four related bugs in the gpio-delay driver that were uncovered while
debugging such a collision.
Patch 1 logs, at dev_dbg() level, which label already holds a GPIO
offset when a new request collides with it, from within
dm_gpio_request() itself, so a collision can be root-caused from the
uclass layer when actively debugging.
Patch 2 adds the same diagnostic to the "gpio" command, at printf()
level. -EBUSY from gpio_request() is a normal, expected result there (a
pin already owned by a driver or hog), so the command already tolerates
it silently; this patch only prints which label holds the pin on that
already-tolerated path.
Patch 3 fixes gpio_delay_probe()/gpio_delay_xlate() to size and
validate against the driver's actual GPIO count (from its "gpios"
property) instead of a hardcoded 32, correctly sizing the claimed/name
tracking arrays and matching the pattern used by the generic uclass
xlate implementation.
Patch 4 fixes gpio_delay_xlate() to propagate the requested index into
desc->offset. Previously every consumer's descriptor came back with
offset 0 regardless of which index was requested, so on boards where
gpio-delay wraps more than one real GPIO line, every consumer past the
first silently collided with the first consumer's already-claimed
offset 0 and was never toggled. This was the root cause behind the
series; the other patches are diagnostic and robustness fixes found
along the way.
Patch 5 adds a .remove hook to gpio-delay to release the real GPIOs it
wraps. The driver requests them via gpio_request_by_name_nodev(), which
strdup()s a label into the wrapped device's own uc_priv->name[]; with
no .remove, those requests and labels were never released on teardown.
Patch 6 fixes a related pre-existing leak: gpio_delay_probe() bailed
out on the first failed GPIO request without freeing the ones it had
already requested, and patch 5's new .remove hook doesn't cover this
either since .remove is only called for devices that finished probing.
Patches 3-6 are tagged Fixes: c866f2f197e2 ("gpio: Add GPIO delay
driver").
Changes in v2:
- Patch 1: downgraded from dev_warn() to dev_dbg(), since -EBUSY is a
normal/expected result for some callers (e.g. cmd/gpio.c, and sandbox
tests that deliberately exercise this path), and warning there fired
on legitimate operations, not just misconfiguration (Simon)
- New patch 2: moved the user-facing diagnostic into the "gpio" command
instead, where -EBUSY is already known to be expected (Simon)
- New patch 5: additional related fix found while further exercising
the driver
Changes in v3:
- Patch 5: added an in-code comment explaining why the device_active()
guard is needed, so a future reader doesn't need the commit message
to understand it (Simon)
- New patch 6: fixes gpio_delay_probe()'s partial-request leak on
failure, reusing the free helper factored out of patch 5's .remove
hook (Suggested-by: Simon)
Sandbox coverage for the gpio-delay fixes in patches 3-5 (exercising
the offset-propagation, gpio_count/bounds, and remove-path fixes) is
posted as a separate, dependent series:
https://patchwork.ozlabs.org/project/uboot/list/?series=516335
Pranav Sanwal (6):
gpio: uclass: log when a gpio offset is already claimed
gpio: cmd: warn when a gpio offset is already claimed
gpio: delay: set gpio_count and validate index against it
gpio: delay: fix offset propagation in gpio_delay_xlate()
gpio: delay: free wrapped real GPIOs on remove
gpio: delay: free already-requested GPIOs on probe failure
cmd/gpio.c | 11 +++++++++--
drivers/gpio/gpio-delay.c | 40 ++++++++++++++++++++++++++++++++++++--
drivers/gpio/gpio-uclass.c | 5 ++++-
3 files changed, 51 insertions(+), 5 deletions(-)
--
2.43.7