From: Michal Bloch Date: Tue, 3 Aug 2021 18:05:53 +0000 (+0200) Subject: Fix some miscellaneous flaws in the code. X-Git-Tag: submit/tizen/20210813.142813~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cf08f0cf30c480a4f7d5d5c803efac7485e200bf;p=platform%2Fcore%2Fapi%2Fperipheral-io.git Fix some miscellaneous flaws in the code. Change-Id: I031b94add3465970352700a4ac8596e30b7f89ec Signed-off-by: Michal Bloch --- diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index 17644c5..29bbc0b 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -281,18 +281,10 @@ int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_b ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret != 0); - /* set stop bit */ - switch (stop_bits) { - case PERIPHERAL_UART_STOP_BITS_1BIT: + if (stop_bits == PERIPHERAL_UART_STOP_BITS_1BIT) tio.c_cflag &= ~CSTOPB; - break; - case PERIPHERAL_UART_STOP_BITS_2BIT: + else // PERIPHERAL_UART_STOP_BITS_2BIT tio.c_cflag |= CSTOPB; - break; - default: - _E("Invalid parameter stop_bits"); - return PERIPHERAL_ERROR_INVALID_PARAMETER; - } peripheral_uart_flush(uart); @@ -320,17 +312,13 @@ int peripheral_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_sof if (hw_flow_control == PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS) tio.c_cflag |= CRTSCTS; - else if (hw_flow_control == PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE) + else // PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE tio.c_cflag &= ~CRTSCTS; - else - return PERIPHERAL_ERROR_INVALID_PARAMETER; if (sw_flow_control == PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF) tio.c_iflag |= (IXON | IXOFF | IXANY); - else if (sw_flow_control == PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE) + else // PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE tio.c_iflag &= ~(IXON | IXOFF | IXANY); - else - return PERIPHERAL_ERROR_INVALID_PARAMETER; peripheral_uart_flush(uart); diff --git a/test/peripheral-io-test.c b/test/peripheral-io-test.c index 7e55ea8..44478b1 100644 --- a/test/peripheral-io-test.c +++ b/test/peripheral-io-test.c @@ -48,7 +48,7 @@ static int fail_count = 0; static int pass_count = 0; static int skip_count = 0; -char *model_name = NULL; +static char *model_name = NULL; typedef struct { diff --git a/test/src/test_peripheral_adc.c b/test/src/test_peripheral_adc.c index 72645e7..c7b8088 100644 --- a/test/src/test_peripheral_adc.c +++ b/test/src/test_peripheral_adc.c @@ -50,9 +50,10 @@ int test_peripheral_io_adc_peripheral_adc_open_p(void) if (g_feature == false) { ret = peripheral_adc_open(device, channel, &adc_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) { + peripheral_adc_close(adc_h); return ret; - + } } else { ret = peripheral_adc_open(device, channel, &adc_h); if (ret != PERIPHERAL_ERROR_NONE) diff --git a/test/src/test_peripheral_gpio.c b/test/src/test_peripheral_gpio.c index 70b139d..ec855dd 100644 --- a/test/src/test_peripheral_gpio.c +++ b/test/src/test_peripheral_gpio.c @@ -47,8 +47,10 @@ int test_peripheral_io_gpio_peripheral_gpio_open_p(void) if (g_feature == false) { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) { + peripheral_gpio_close(gpio_h); return ret; + } } else { ret = peripheral_gpio_open(pin, &gpio_h); diff --git a/test/src/test_peripheral_i2c.c b/test/src/test_peripheral_i2c.c index 1afb104..12e4266 100644 --- a/test/src/test_peripheral_i2c.c +++ b/test/src/test_peripheral_i2c.c @@ -95,8 +95,10 @@ int test_peripheral_io_i2c_peripheral_i2c_open_p(void) if (g_feature == false) { ret = peripheral_i2c_open(bus, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) { + peripheral_i2c_close(i2c_h); return ret; + } } else { ret = peripheral_i2c_open(bus, address, &i2c_h); diff --git a/test/src/test_peripheral_pwm.c b/test/src/test_peripheral_pwm.c index 32dd422..77ecfe7 100644 --- a/test/src/test_peripheral_pwm.c +++ b/test/src/test_peripheral_pwm.c @@ -51,8 +51,10 @@ int test_peripheral_io_pwm_peripheral_pwm_open_p(void) if (g_feature == false) { ret = peripheral_pwm_open(chip, pin, &pwm_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) { + peripheral_pwm_close(pwm_h); return ret; + } } else { ret = peripheral_pwm_open(chip, pin, &pwm_h); diff --git a/test/src/test_peripheral_spi.c b/test/src/test_peripheral_spi.c index 36f607e..56d2761 100644 --- a/test/src/test_peripheral_spi.c +++ b/test/src/test_peripheral_spi.c @@ -58,8 +58,10 @@ int test_peripheral_io_spi_peripheral_spi_open_p(void) if (g_feature == false) { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) { + peripheral_spi_close(spi_h); return ret; + } } else { ret = peripheral_spi_open(bus, cs, &spi_h); diff --git a/test/src/test_peripheral_uart.c b/test/src/test_peripheral_uart.c index 801afb8..c32bb34 100644 --- a/test/src/test_peripheral_uart.c +++ b/test/src/test_peripheral_uart.c @@ -50,8 +50,10 @@ int test_peripheral_io_uart_peripheral_uart_open_p(void) if (g_feature == false) { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) { + peripheral_uart_close(uart_h); return ret; + } } else { ret = peripheral_uart_open(port, &uart_h);