From eb63fb88512fdb567262b78e930e8dd3441efa34 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 8 Apr 2021 14:30:46 +0200 Subject: [PATCH] gpioset: fix a segfault with default mode The default mode (exit) doesn't have a callback so we need to check if the callback funtion pointer isn't NULL. Fixes: 9b6e6d268671 ("ctxless: drop all context-less interfaces") Signed-off-by: Bartosz Golaszewski --- tools/gpio-tools-test.bats | 8 ++++++++ tools/gpioset.c | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/gpio-tools-test.bats b/tools/gpio-tools-test.bats index b35a36e..a5b97e1 100755 --- a/tools/gpio-tools-test.bats +++ b/tools/gpio-tools-test.bats @@ -599,6 +599,14 @@ teardown() { output_regex_match ".*can't specify wait time in this mode" } +@test "gpioset: default mode" { + gpio_mockup_probe 8 8 8 + + run_tool gpioset "$(gpio_mockup_chip_name 1)" 0=1 + + test "$status" -eq "0" +} + @test "gpioset: invalid mapping" { gpio_mockup_probe 8 8 8 diff --git a/tools/gpioset.c b/tools/gpioset.c index a088ec6..7882b53 100644 --- a/tools/gpioset.c +++ b/tools/gpioset.c @@ -302,7 +302,8 @@ int main(int argc, char **argv) if (rv) die_perror("unable to request lines"); - mode->callback(&cbdata); + if (mode->callback) + mode->callback(&cbdata); gpiod_line_release_bulk(lines); gpiod_chip_unref(chip); -- 2.30.2