summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoungjae Cho <y0.cho@samsung.com>2021-06-18 11:15:01 +0900
committerYoungjae Cho <y0.cho@samsung.com>2021-06-18 11:15:01 +0900
commit261f67013bd80b63bf700d9c949ffc1d3cce2ab5 (patch)
tree5a7558e7c4e02aa82368564f7a741c5bc94f8fc9
parent7c32c3d2447aa78f8d5c34ad44306a7312b25a61 (diff)
downloaddevice-261f67013bd80b63bf700d9c949ffc1d3cce2ab5.tar.gz
device-261f67013bd80b63bf700d9c949ffc1d3cce2ab5.tar.bz2
device-261f67013bd80b63bf700d9c949ffc1d3cce2ab5.zip
Change-Id: Ib7f0f9635103def4a6cfa45328f380d480de2b2c Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
-rw-r--r--haltest/board.cpp9
-rw-r--r--include/backend/hal-board-interface.h2
-rw-r--r--include/hal-board.h2
-rw-r--r--src/board.c4
-rw-r--r--src/usb_gadget.c18
5 files changed, 19 insertions, 16 deletions
diff --git a/haltest/board.cpp b/haltest/board.cpp
index b28437a..6062a81 100644
--- a/haltest/board.cpp
+++ b/haltest/board.cpp
@@ -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)
diff --git a/include/backend/hal-board-interface.h b/include/backend/hal-board-interface.h
index 560105e..a70bb32 100644
--- a/include/backend/hal-board-interface.h
+++ b/include/backend/hal-board-interface.h
@@ -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;
diff --git a/include/hal-board.h b/include/hal-board.h
index 6a9b9a0..e7ed03a 100644
--- a/include/hal-board.h
+++ b/include/hal-board.h
@@ -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
diff --git a/src/board.c b/src/board.c
index b145b64..197a071 100644
--- a/src/board.c
+++ b/src/board.c
@@ -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)
diff --git a/src/usb_gadget.c b/src/usb_gadget.c
index 5db5509..da3537d 100644
--- a/src/usb_gadget.c
+++ b/src/usb_gadget.c
@@ -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;