misc: make gpiod_is_gpiochip_device() not set errno
Subsystems (2)
PATCH v2 1/1 misc: make gpiod_is_gpiochip_device() not set errno
This function should just report whether the file indicated by path is a GPIO chip or not. Let's rework it to not set errno. Failure to open a chip should still report errro numbers like before.
--- lib/chip.c | 2 +- lib/internal.c | 65 +++++++++++++++++++++++++++++++++++++++++++++- lib/internal.h | 2 ++ lib/misc.c | 62 ++----------------------------------------- tests/tests-misc.c | 2 ++ 5 files changed, 71 insertions(+), 62 deletions(-)
lib/chip.c +1 -1
@@ -21,7 +21,7 @@ GPIOD_API struct gpiod_chip *gpiod_chip_open(const char *path)struct gpiod_chip *chip;int fd; -if (!gpiod_is_gpiochip_device (path)) +if (!gpiod_check_gpiochip_device (path, true))return NULL ; fd =open (path,O_RDWR |O_CLOEXEC |O_NONBLOCK );
lib/internal.c +64 -1
76 lines not on this page · raw message
lib/internal.h +2 -0
@@ -18,6 +18,8 @@#define GPIOD_BIT (nr) (1UL << (nr)) +bool gpiod_check_gpiochip_device (const char *path,bool set_errno); +struct gpiod_chip_info *gpiod_chip_info_from_uapi (struct gpiochip_info *uapi_info); struct gpiod_line_info *
lib/misc.c +2 -60
73 lines not on this page · raw message
tests/tests-misc.c +2 -0
@@ -15,7 +15,9 @@GPIOD_TEST_CASE (is_gpiochip_bad) {g_assert_false (gpiod_is_gpiochip_device ("/dev/null" )); + g_assert_cmpint(errno, ==, 0);g_assert_false (gpiod_is_gpiochip_device ("/dev/nonexistent" )); + g_assert_cmpint(errno, ==, 0); }GPIOD_TEST_CASE (is_gpiochip_good)
Signature · 1 line
2.34.1
Quoted 4 lines · Bartosz Golaszewski
This function should just report whether the file indicated by path is a GPIO chip or not. Let's rework it to not set errno. Failure to open a chip should still report errro numbers like before.
errrrrrrr!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 4 lines · Bartosz Golaszewski
This function should just report whether the file indicated by path is a GPIO chip or not. Let's rework it to not set errno. Failure to open a chip should still report errro numbers like before.
This is will break my tool patch, for sure.
My gpiodetect uses the errno behaviour to give a clue as to why a chip might not be available to a user, and that work was already done in gpiod_is_gpiochip_device().
There might be other places the errno was propagated as well, but whatever, I'll sort something out.
Cheers,
Kent.
Quoted 7 lines · Kent Gibson
Quoted 4 lines · Bartosz Golaszewski
This function should just report whether the file indicated by path is a GPIO chip or not. Let's rework it to not set errno. Failure to open a chip should still report errro numbers like before.
Quoted 7 lines
This is will break my tool patch, for sure.
My gpiodetect uses the errno behaviour to give a clue as to why a chip might not be available to a user, and that work was already done ingpiod_is_gpiochip_device().
There might be other places the errno was propagated as well, but whatever, I'll sort something out.
Doesn't it make more sense to call gpiod_is_gpiochip_device() and then if it returns true, just try to open it and then report failure?
Bart
Quoted 16 lines · Bartosz Golaszewski
Quoted 7 lines · Kent Gibson
Quoted 4 lines · Bartosz Golaszewski
This function should just report whether the file indicated by path is a GPIO chip or not. Let's rework it to not set errno. Failure to open a chip should still report errro numbers like before.
Quoted 7 lines
This is will break my tool patch, for sure.
My gpiodetect uses the errno behaviour to give a clue as to why a chip might not be available to a user, and that work was already done ingpiod_is_gpiochip_device().
There might be other places the errno was propagated as well, but whatever, I'll sort something out.
Quoted 3 lines
Doesn't it make more sense to call
gpiod_is_gpiochip_device()and then if it returns true, just try to open it and then report failure?
Not for the case where the chip doesn't exist - gpiod_is_gpiochip_device() has already worked that out.
But don't worry - I'll sort something out.
Cheers,
Kent.