From: Bartosz Golaszewski Date: Thu, 2 Mar 2017 10:30:04 +0000 (+0100) Subject: tests: remove gu_release_line() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=1264747fc886f26662d40d6573d502004f1eedd1;p=qemu-gpiodev%2Flibgpiod.git tests: remove gu_release_line() There cannot be any memory leaks if we don't release a line as long as we close the gpiochip handle. Remove all code releasing lines on errors. Signed-off-by: Bartosz Golaszewski --- diff --git a/tests/unit/gpiod-unit.c b/tests/unit/gpiod-unit.c index 6550577..b28512f 100644 --- a/tests/unit/gpiod-unit.c +++ b/tests/unit/gpiod-unit.c @@ -485,12 +485,6 @@ void gu_free_chip_iter_noclose(struct gpiod_chip_iter **iter) gpiod_chip_iter_free_noclose(*iter); } -void gu_release_line(struct gpiod_line **line) -{ - if (*line) - gpiod_line_release(*line); -} - const char * gu_chip_path(unsigned int index) { check_chip_index(index); diff --git a/tests/unit/gpiod-unit.h b/tests/unit/gpiod-unit.h index bd6fe9f..4a79ebf 100644 --- a/tests/unit/gpiod-unit.h +++ b/tests/unit/gpiod-unit.h @@ -106,7 +106,6 @@ void gu_close_chip(struct gpiod_chip **chip); void gu_free_str(char **str); void gu_free_chip_iter(struct gpiod_chip_iter **iter); void gu_free_chip_iter_noclose(struct gpiod_chip_iter **iter); -void gu_release_line(struct gpiod_line **line); #define GU_ASSERT(statement) \ do { \ diff --git a/tests/unit/tests-line.c b/tests/unit/tests-line.c index ae1f3d0..8ab4c1b 100644 --- a/tests/unit/tests-line.c +++ b/tests/unit/tests-line.c @@ -13,8 +13,8 @@ static void line_request_output(void) { GU_CLEANUP(gu_close_chip) struct gpiod_chip *chip = NULL; - GU_CLEANUP(gu_release_line) struct gpiod_line *line_0 = NULL; - GU_CLEANUP(gu_release_line) struct gpiod_line *line_1 = NULL; + struct gpiod_line *line_0; + struct gpiod_line *line_1; int status; chip = gpiod_chip_open(gu_chip_path(0)); @@ -32,6 +32,9 @@ static void line_request_output(void) GU_ASSERT_EQ(gpiod_line_get_value(line_0), 0); GU_ASSERT_EQ(gpiod_line_get_value(line_1), 1); + + gpiod_line_release(line_0); + gpiod_line_release(line_1); } GU_DEFINE_TEST(line_request_output, "gpiod_line_request_output() - good", @@ -41,14 +44,14 @@ static void line_request_bulk_output(void) { GU_CLEANUP(gu_close_chip) struct gpiod_chip *chipA = NULL; GU_CLEANUP(gu_close_chip) struct gpiod_chip *chipB = NULL; - GU_CLEANUP(gu_release_line) struct gpiod_line *lineA0 = NULL; - GU_CLEANUP(gu_release_line) struct gpiod_line *lineA1 = NULL; - GU_CLEANUP(gu_release_line) struct gpiod_line *lineA2 = NULL; - GU_CLEANUP(gu_release_line) struct gpiod_line *lineA3 = NULL; - GU_CLEANUP(gu_release_line) struct gpiod_line *lineB0 = NULL; - GU_CLEANUP(gu_release_line) struct gpiod_line *lineB1 = NULL; - GU_CLEANUP(gu_release_line) struct gpiod_line *lineB2 = NULL; - GU_CLEANUP(gu_release_line) struct gpiod_line *lineB3 = NULL; + struct gpiod_line *lineA0; + struct gpiod_line *lineA1; + struct gpiod_line *lineA2; + struct gpiod_line *lineA3; + struct gpiod_line *lineB0; + struct gpiod_line *lineB1; + struct gpiod_line *lineB2; + struct gpiod_line *lineB3; struct gpiod_line_bulk bulkA; struct gpiod_line_bulk bulkB = GPIOD_LINE_BULK_INITIALIZER; int status; @@ -123,9 +126,6 @@ static void line_request_bulk_output(void) gpiod_line_release_bulk(&bulkA); gpiod_line_release_bulk(&bulkB); - - lineA0 = lineA1 = lineA2 = lineA3 = NULL; - lineB0 = lineB1 = lineB2 = lineB3 = NULL; } GU_DEFINE_TEST(line_request_bulk_output, "gpiod_line_request_bulk_output() - good", @@ -136,10 +136,10 @@ static void line_request_bulk_different_chips(void) GU_CLEANUP(gu_close_chip) struct gpiod_chip *chipA = NULL; GU_CLEANUP(gu_close_chip) struct gpiod_chip *chipB = NULL; struct gpiod_line_request_config req; - struct gpiod_line *lineA0 = NULL; - struct gpiod_line *lineA1 = NULL; - struct gpiod_line *lineB0 = NULL; - struct gpiod_line *lineB1 = NULL; + struct gpiod_line *lineA0; + struct gpiod_line *lineA1; + struct gpiod_line *lineB0; + struct gpiod_line *lineB1; struct gpiod_line_bulk bulk; int status; @@ -179,7 +179,7 @@ GU_DEFINE_TEST(line_request_bulk_different_chips, static void line_set_value(void) { GU_CLEANUP(gu_close_chip) struct gpiod_chip *chip = NULL; - GU_CLEANUP(gu_release_line) struct gpiod_line *line = NULL; + struct gpiod_line *line; int status; chip = gpiod_chip_open(gu_chip_path(0)); @@ -195,6 +195,8 @@ static void line_set_value(void) GU_ASSERT_EQ(gpiod_line_get_value(line), 1); GU_ASSERT_RET_OK(gpiod_line_set_value(line, 0)); GU_ASSERT_EQ(gpiod_line_get_value(line), 0); + + gpiod_line_release(line); } GU_DEFINE_TEST(line_set_value, "gpiod_line_set_value() - good",