From: Bartosz Golaszewski Date: Thu, 8 Apr 2021 12:30:46 +0000 (+0200) Subject: gpioset: fix a segfault with default mode X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=eb63fb88512fdb567262b78e930e8dd3441efa34;p=qemu-gpiodev%2Flibgpiod.git 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 --- 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);