From: Hyotaek Shim Date: Fri, 18 Jun 2021 10:45:49 +0000 (+0900) Subject: board: fix parameter of get_deviec_serial_number() X-Git-Tag: accepted/tizen/unified/20210621.123228^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=198b243d72907f43d5f056db536427cdf2151761;p=platform%2Fcore%2Fsystem%2Fdeviced.git board: fix parameter of get_deviec_serial_number() Change-Id: I4c9d3adbe0226afafd35c8597cb1d8787b70f428 Signed-off-by: Hyotaek Shim --- diff --git a/src/board/board-info.c b/src/board/board-info.c index b656596..1ab3986 100644 --- a/src/board/board-info.c +++ b/src/board/board-info.c @@ -23,6 +23,7 @@ #include "core/devices.h" #include +#define SERIAL_MAX 128 static bool board_dev_available = false; static GVariant *dbus_revision_handler(GDBusConnection *conn, @@ -58,9 +59,9 @@ static GVariant *dbus_num_handler(GDBusConnection *conn, { int ret; GVariant *result; - char *serial = NULL; + char serial[SERIAL_MAX] = {0, }; - ret = hal_device_board_get_device_serial_number(&serial); + ret = hal_device_board_get_device_serial_number(serial, SERIAL_MAX); if (!board_dev_available || (ret == -ENODEV)) { _E("GetSerial not supported."); ret = -ENOTSUP; @@ -75,13 +76,10 @@ static GVariant *dbus_num_handler(GDBusConnection *conn, _D("Num(%s) len(%zu).", serial, strlen(serial)); num_out: - if (serial == NULL) - serial = strdup(""); - - result = g_variant_new("(si)", serial, ret); - - if (serial) - free(serial); + if (ret < 0) + result = g_variant_new("(si)", strdup(""), ret); + else + result = g_variant_new("(si)", serial, ret); return result; } @@ -93,9 +91,9 @@ static GVariant *dbus_serial_handler(GDBusConnection *conn, int ret; char *p; GVariant *result; - char *num = NULL; + char serial[SERIAL_MAX] = {0, }; - ret = hal_device_board_get_device_serial_number(&num); + ret = hal_device_board_get_device_serial_number(serial, SERIAL_MAX); if (!board_dev_available || (ret == -ENODEV)) { _E("GetNum not supported."); ret = -ENOTSUP; @@ -107,20 +105,17 @@ static GVariant *dbus_serial_handler(GDBusConnection *conn, goto seiral_out; } - p = strchr(num, ','); + p = strchr(serial, ','); if (p) *p = '\0'; - _D("Serial(%s) len(%zu).", num, strlen(num)); + _D("Serial(%s) len(%zu).", serial, strlen(serial)); seiral_out: - if (num == NULL) - num = strdup(""); - - result = g_variant_new("(si)", num, ret); - - if (num) - free(num); + if (ret < 0) + result = g_variant_new("(si)", strdup(""), ret); + else + result = g_variant_new("(si)", serial, ret); return result; }