mirror of
https://git.proxmox.com/git/fwupd
synced 2025-05-09 20:15:54 +00:00
amt: Fix up a small memory leak and remove some goto's
This commit is contained in:
parent
35aebc838f
commit
166d42cada
@ -136,13 +136,12 @@ mei_send_msg (mei_context *ctx, const guchar *buffer,
|
|||||||
g_debug ("call write length = %zd", len);
|
g_debug ("call write length = %zd", len);
|
||||||
written = write (ctx->fd, buffer, len);
|
written = write (ctx->fd, buffer, len);
|
||||||
if (written < 0) {
|
if (written < 0) {
|
||||||
rc = -errno;
|
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
FWUPD_ERROR,
|
FWUPD_ERROR,
|
||||||
FWUPD_ERROR_WRITE,
|
FWUPD_ERROR_WRITE,
|
||||||
"write failed with status %zd %s",
|
"write failed with status %zd %s",
|
||||||
written, strerror(errno));
|
written, strerror(errno));
|
||||||
goto out;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
FD_ZERO(&set);
|
FD_ZERO(&set);
|
||||||
@ -150,23 +149,23 @@ mei_send_msg (mei_context *ctx, const guchar *buffer,
|
|||||||
rc = select (ctx->fd + 1 , &set, NULL, NULL, &tv);
|
rc = select (ctx->fd + 1 , &set, NULL, NULL, &tv);
|
||||||
if (rc > 0 && FD_ISSET(ctx->fd, &set)) {
|
if (rc > 0 && FD_ISSET(ctx->fd, &set)) {
|
||||||
g_debug ("write success");
|
g_debug ("write success");
|
||||||
} else if (rc == 0) {
|
return written;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* timed out */
|
||||||
|
if (rc == 0) {
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
FWUPD_ERROR,
|
FWUPD_ERROR,
|
||||||
FWUPD_ERROR_WRITE,
|
FWUPD_ERROR_WRITE,
|
||||||
"write failed on timeout with status");
|
"write failed on timeout with status");
|
||||||
goto out;
|
return 0;
|
||||||
} else { /* rc < 0 */
|
|
||||||
g_set_error (error,
|
|
||||||
FWUPD_ERROR,
|
|
||||||
FWUPD_ERROR_WRITE,
|
|
||||||
"write failed on select with status %zd", rc);
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = written;
|
/* rc < 0 */
|
||||||
out:
|
g_set_error (error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_WRITE,
|
||||||
|
"write failed on select with status %zd", rc);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,40 +275,23 @@ struct amt_host_if {
|
|||||||
static guint32
|
static guint32
|
||||||
amt_verify_code_versions (const struct amt_host_if_resp_header *resp)
|
amt_verify_code_versions (const struct amt_host_if_resp_header *resp)
|
||||||
{
|
{
|
||||||
guint32 status = AMT_STATUS_SUCCESS;
|
struct amt_code_versions *code_ver = (struct amt_code_versions *)resp->data;
|
||||||
struct amt_code_versions *code_ver;
|
gsize code_ver_len = resp->header.length - sizeof(guint32);
|
||||||
gsize code_ver_len;
|
guint32 ver_type_cnt = code_ver_len -
|
||||||
guint32 ver_type_cnt;
|
sizeof(code_ver->bios) -
|
||||||
guint32 len;
|
sizeof(code_ver->count);
|
||||||
guint32 i;
|
if (code_ver->count != ver_type_cnt / sizeof(struct amt_version_type))
|
||||||
|
return AMT_STATUS_INTERNAL_ERROR;
|
||||||
code_ver = (struct amt_code_versions *)resp->data;
|
for (guint32 i = 0; i < code_ver->count; i++) {
|
||||||
/* length - sizeof(status) */
|
guint32 len = code_ver->versions[i].description.length;
|
||||||
code_ver_len = resp->header.length - sizeof(guint32);
|
if (len > AMT_UNICODE_STRING_LEN)
|
||||||
ver_type_cnt = code_ver_len -
|
return AMT_STATUS_INTERNAL_ERROR;
|
||||||
sizeof(code_ver->bios) -
|
|
||||||
sizeof(code_ver->count);
|
|
||||||
if (code_ver->count != ver_type_cnt / sizeof(struct amt_version_type)) {
|
|
||||||
status = AMT_STATUS_INTERNAL_ERROR;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
for (i = 0; i < code_ver->count; i++) {
|
|
||||||
len = code_ver->versions[i].description.length;
|
|
||||||
|
|
||||||
if (len > AMT_UNICODE_STRING_LEN) {
|
|
||||||
status = AMT_STATUS_INTERNAL_ERROR;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
len = code_ver->versions[i].version.length;
|
len = code_ver->versions[i].version.length;
|
||||||
if (code_ver->versions[i].version.string[len] != '\0' ||
|
if (code_ver->versions[i].version.string[len] != '\0' ||
|
||||||
len != strlen(code_ver->versions[i].version.string)) {
|
len != strlen(code_ver->versions[i].version.string))
|
||||||
status = AMT_STATUS_INTERNAL_ERROR;
|
return AMT_STATUS_INTERNAL_ERROR;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
out:
|
return AMT_STATUS_SUCCESS;
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static guint32
|
static guint32
|
||||||
@ -350,11 +332,8 @@ amt_host_if_call (mei_context *mei_cl,
|
|||||||
struct amt_host_if_resp_header *msg_hdr;
|
struct amt_host_if_resp_header *msg_hdr;
|
||||||
|
|
||||||
in_buf_sz = mei_cl->buf_size;
|
in_buf_sz = mei_cl->buf_size;
|
||||||
*read_buf = (guint8 *) g_malloc (in_buf_sz);
|
*read_buf = (guint8 *) g_malloc0 (in_buf_sz);
|
||||||
if (*read_buf == NULL)
|
msg_hdr = (struct amt_host_if_resp_header *) *read_buf;
|
||||||
return AMT_STATUS_SDK_RESOURCES;
|
|
||||||
memset(*read_buf, 0, in_buf_sz);
|
|
||||||
msg_hdr = (struct amt_host_if_resp_header *)*read_buf;
|
|
||||||
|
|
||||||
written = mei_send_msg (mei_cl, command, command_sz, send_timeout, error);
|
written = mei_send_msg (mei_cl, command, command_sz, send_timeout, error);
|
||||||
if (written != command_sz)
|
if (written != command_sz)
|
||||||
@ -368,8 +347,7 @@ amt_host_if_call (mei_context *mei_cl,
|
|||||||
if (status != AMT_STATUS_SUCCESS)
|
if (status != AMT_STATUS_SUCCESS)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
status = amt_verify_response_header(rcmd,
|
status = amt_verify_response_header(rcmd, &msg_hdr->header, out_buf_sz);
|
||||||
&msg_hdr->header, out_buf_sz);
|
|
||||||
if (status != AMT_STATUS_SUCCESS)
|
if (status != AMT_STATUS_SUCCESS)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
@ -382,7 +360,7 @@ amt_host_if_call (mei_context *mei_cl,
|
|||||||
static guint32
|
static guint32
|
||||||
amt_get_provisioning_state (mei_context *mei_cl, guint8 *state, GError **error)
|
amt_get_provisioning_state (mei_context *mei_cl, guint8 *state, GError **error)
|
||||||
{
|
{
|
||||||
struct amt_host_if_resp_header *response = NULL;
|
g_autofree struct amt_host_if_resp_header *response = NULL;
|
||||||
guint32 status;
|
guint32 status;
|
||||||
|
|
||||||
status = amt_host_if_call (mei_cl,
|
status = amt_host_if_call (mei_cl,
|
||||||
@ -412,11 +390,12 @@ fu_plugin_amt_create_device (GError **error)
|
|||||||
guint32 status;
|
guint32 status;
|
||||||
guint8 state;
|
guint8 state;
|
||||||
struct amt_code_versions ver;
|
struct amt_code_versions ver;
|
||||||
struct amt_host_if_resp_header *response = NULL;
|
|
||||||
uuid_t uu;
|
uuid_t uu;
|
||||||
|
g_autofree struct amt_host_if_resp_header *response = NULL;
|
||||||
g_autoptr(FuDevice) dev = NULL;
|
g_autoptr(FuDevice) dev = NULL;
|
||||||
g_autoptr(mei_context) ctx = g_new0 (mei_context, 1);
|
g_autoptr(mei_context) ctx = g_new0 (mei_context, 1);
|
||||||
|
|
||||||
|
/* create context */
|
||||||
if (!mei_context_new (ctx, &MEI_IAMTHIF, 0, error))
|
if (!mei_context_new (ctx, &MEI_IAMTHIF, 0, error))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -446,8 +425,6 @@ fu_plugin_amt_create_device (GError **error)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memcpy (&ver, response->data, sizeof(struct amt_code_versions));
|
memcpy (&ver, response->data, sizeof(struct amt_code_versions));
|
||||||
if (response != NULL)
|
|
||||||
g_free (response);
|
|
||||||
|
|
||||||
dev = fu_device_new ();
|
dev = fu_device_new ();
|
||||||
fu_device_set_id (dev, "/dev/mei");
|
fu_device_set_id (dev, "/dev/mei");
|
||||||
|
Loading…
Reference in New Issue
Block a user