fix gpio number init and fd closing
fix gpio number init and fd closing

export() expects pin->no is already set. Since pin->no was set
after export(), export() was working with uninitialized data.
This patch fixes that by setting pin->no first.

In several places pin->fd is closed, but the value of pin->fd
was left alone. All functions expect pin->fd to be -1 if the
file descriptor is not open. This patch fixes this by setting
-1 after each close(pin->fd).

In gpio_irq_timed_wait() pin->fd was closed at the end in a
non-error situation. This is not necessary since all functions
will work with an already opened file descriptor.

Signed-off-by: John Ogness <57a85e5e217a72610aef6535ec391bc819cb0f3f@linutronix.de>
Signed-off-by: Manuel Traut <5b9fefc5e24c8c0032a4b1b435e37d15daf2b05f@linutronix.de>

Linutronix/libgpio,Linutronix/libgpio