board: fix parameter of get_device_serial_number() 42/260042/1 accepted/tizen/unified/20210621.123208 submit/tizen/20210618.075427 submit/tizen/20210621.095917
authorYoungjae Cho <y0.cho@samsung.com>
Fri, 18 Jun 2021 02:15:01 +0000 (11:15 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Fri, 18 Jun 2021 02:15:01 +0000 (11:15 +0900)
Change-Id: Ib7f0f9635103def4a6cfa45328f380d480de2b2c
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
haltest/board.cpp
include/backend/hal-board-interface.h
include/hal-board.h
src/board.c
src/usb_gadget.c

index b28437a..6062a81 100644 (file)
@@ -1,6 +1,8 @@
 #include "haltest.h"
 #include "hal-board.h"
 
+#define BUFFER_MAX    128
+
 class BOARD : public testing::Test {
        protected:
                void SetUp() override {}
@@ -19,20 +21,17 @@ TEST_F(BOARD, GetBackendP)
 TEST_F(BOARD, GetDeviceSerialP)
 {
        int ret_val;
-       char *serial = nullptr;
+       char serial[BUFFER_MAX] = {0, };
 
-       ret_val = hal_device_board_get_device_serial_number(&serial);
+       ret_val = hal_device_board_get_device_serial_number(serial, sizeof(serial));
        if (ret_val == -ENODEV) {
                SKIP_MESSAGE("Not supported HAL");
                return;
        }
        EXPECT_EQ(ret_val, 0) << "Failed to get device serial (" << ret_val << ")";
-       EXPECT_NE(serial, nullptr) << "Failed to get device serial (nullptr)";
 
        if (ret_val == 0 && serial)
                DEBUG_MESSAGE("Serial=%s", serial);
-
-       free(serial);
 }
 
 TEST_F(BOARD, GetDeviceRevisionP)
index 560105e..a70bb32 100644 (file)
@@ -24,7 +24,7 @@ extern "C" {
 
 typedef struct _hal_backend_board_funcs {
        /* Serial number of this device */
-       int (*get_device_serial_number)(char **serial);
+       int (*get_device_serial_number)(char *buffer, int len);
        int (*get_device_revision)(int *revision);
 } hal_backend_board_funcs;
 
index 6a9b9a0..e7ed03a 100644 (file)
@@ -26,7 +26,7 @@ extern "C" {
 
 int hal_device_board_get_backend(void);
 int hal_device_board_put_backend(void);
-int hal_device_board_get_device_serial_number(char **serial);
+int hal_device_board_get_device_serial_number(char *buffer, int len);
 int hal_device_board_get_device_revision(int *revision);
 
 #ifdef __cplusplus
index b145b64..197a071 100644 (file)
@@ -58,7 +58,7 @@ int hal_device_board_put_backend(void)
        return 0;
 }
 
-int hal_device_board_get_device_serial_number(char **serial)
+int hal_device_board_get_device_serial_number(char *buffer, int len)
 {
        int ret ;
 
@@ -71,7 +71,7 @@ int hal_device_board_get_device_serial_number(char **serial)
            !hal_board_funcs->get_device_serial_number)
                return -ENODEV;
 
-       return hal_board_funcs->get_device_serial_number(serial);
+       return hal_board_funcs->get_device_serial_number(buffer, len);
 }
 
 int hal_device_board_get_device_revision(int *revision)
index 5db5509..da3537d 100644 (file)
@@ -22,6 +22,8 @@
 #include "hal-board.h"
 #include "hal-usb_gadget-interface.h"
 
+#define SERIAL_MAX    128
+
 static hal_backend_usb_gadget_funcs *hal_usb_gadget_funcs;
 /*
 -1 : failed to initialize
@@ -46,18 +48,20 @@ static int usb_gadget_is_valid(hal_backend_usb_gadget_funcs *usb_gadget_funcs)
 
 static int get_board_serial(hal_backend_usb_gadget_funcs *usb_gadget_funcs)
 {
-       char *board_serial = NULL;
+       char board_serial[SERIAL_MAX] = {0, };
+       int retval;
 
        if (!usb_gadget_funcs)
                return -EINVAL;
 
-       if (hal_device_board_get_device_serial_number(&board_serial))
-               _E("Failed to get board serial for USB");
-
-       if (!board_serial)
-               board_serial = strdup(DEFAULT_SERIAL);
+       retval = hal_device_board_get_device_serial_number(board_serial, SERIAL_MAX);
+       if (retval == 0) {
+               usb_gadget_funcs->board_serial = strndup(board_serial, SERIAL_MAX);
+       } else {
+               _E("Failed to get board serial for USB, use default serial=%s", DEFAULT_SERIAL);
+               usb_gadget_funcs->board_serial = strndup(DEFAULT_SERIAL, SERIAL_MAX);
+       }
 
-       usb_gadget_funcs->board_serial = board_serial;
        if (!usb_gadget_funcs->board_serial)
                return -ENOMEM;