Hi Simon,

On 1/15/21 3:04 PM, Simon Glass wrote:
Adjust the terminology in this driver to reflect that fact that all flags
are handled, not just direction flags.

Create a new access function to get the full GPIO state, not just the
direction flags. Drop the static invalid_dir_flags since we can rely on a
segfault if something is wrong.


If I remember, I add this static vairable  to avoid crash during normal pytest....

But it is more the case with the serie, it is better to drop it.



Signed-off-by: Simon Glass <s...@chromium.org>
---

  arch/sandbox/include/asm/gpio.h |  8 ++--
  drivers/gpio/sandbox.c          | 65 ++++++++++++++++++---------------
  test/dm/gpio.c                  | 18 ++++-----
  3 files changed, 49 insertions(+), 42 deletions(-)

diff --git a/arch/sandbox/include/asm/gpio.h b/arch/sandbox/include/asm/gpio.h
index df4ba4fb5f3..20d78296551 100644
--- a/arch/sandbox/include/asm/gpio.h
+++ b/arch/sandbox/include/asm/gpio.h
@@ -69,17 +69,17 @@ int sandbox_gpio_set_direction(struct udevice *dev, 
unsigned int offset,
   * @param offset      GPIO offset within bank
   * @return dir_flags: bitfield accesses by GPIOD_ defines
   */
-ulong sandbox_gpio_get_dir_flags(struct udevice *dev, unsigned int offset);
+ulong sandbox_gpio_get_flags(struct udevice *dev, unsigned int offset);


(...)

-/* Access routines for GPIO dir flags */
-static ulong *get_gpio_dir_flags(struct udevice *dev, unsigned int offset)
+/* Access routines for GPIO info */
+static struct gpio_state *get_gpio_state(struct udevice *dev, uint offset)
  {
        struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
        struct gpio_state *state = dev_get_priv(dev);
if (offset >= uc_priv->gpio_count) {
-               static ulong invalid_dir_flags;
                printf("sandbox_gpio: error: invalid gpio %u\n", offset);
-               return &invalid_dir_flags;
+               return NULL;
        }
- return &state[offset].dir_flags;
+       return &state[offset];
+}
+
+/* Access routines for GPIO dir flags */

/* Access routines for GPIO flags */


+static ulong *get_gpio_flags(struct udevice *dev, unsigned int offset)
+{
+       struct gpio_state *state = get_gpio_state(dev, offset);
+
+       if (!state)
+               return NULL;
+
+       return &state->flags;
}

(...)

With comment


Reviewed-by: Patrick Delaunay <patrick.delau...@foss.st.com>

Thanks

Patrick

Reply via email to