Fix some miscellaneous flaws in the code. 26/262226/2
authorMichal Bloch <m.bloch@samsung.com>
Tue, 3 Aug 2021 18:05:53 +0000 (20:05 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 12 Aug 2021 15:03:11 +0000 (15:03 +0000)
Change-Id: I031b94add3465970352700a4ac8596e30b7f89ec
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/peripheral_uart.c
test/peripheral-io-test.c
test/src/test_peripheral_adc.c
test/src/test_peripheral_gpio.c
test/src/test_peripheral_i2c.c
test/src/test_peripheral_pwm.c
test/src/test_peripheral_spi.c
test/src/test_peripheral_uart.c

index 17644c5599182fad6e57f0d55af99ef86d8f8713..29bbc0bfa26a7a806ea6b89f58b6ae4aa5fb5110 100644 (file)
@@ -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);
 
index 7e55ea884821803f5f7ef93f74498cedaca98719..44478b150cecabdd006554eeaced6528f92806bb 100644 (file)
@@ -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
 {
index 72645e7e3af84ed7ed85d98dba5c1f2dcfafb749..c7b8088ed8fc047da95d985cfa1558aeecb0d3d7 100644 (file)
@@ -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)
index 70b139d1aef13c91e7f1f294251370d576f2ba34..ec855dd02977c4b7687ad4baa8631bfcd63c37e0 100644 (file)
@@ -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);
index 1afb104c38851ba373c58533130cc743277aa672..12e4266c676875b05e1da2fbd78808d9b4f80789 100644 (file)
@@ -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);
index 32dd422e35990f1accf67d5e7ebb2e8da990bb35..77ecfe75c69654b6cf3abb7fd595d16417f7daad 100644 (file)
@@ -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);
index 36f607e47e4fc137e026644ebb12a661ba14bb77..56d2761f61cc0d08f4b5ed1ef819333abcb7e762 100644 (file)
@@ -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);
index 801afb85188c4d25e4bc7b350840c4a99117dc04..c32bb34741b74abb2a38fb05e8ed5ee94c0f9a7e 100644 (file)
@@ -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);