mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-07 23:37:53 +00:00
elantp: Use fu_device_retry_full() to avoid a Coverity warning
This commit is contained in:
parent
58090ffc29
commit
be8fb81103
@ -591,55 +591,32 @@ fu_elantp_hid_haptic_device_prepare_firmware(FuDevice *device,
|
|||||||
return g_steal_pointer(&firmware);
|
return g_steal_pointer(&firmware);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
guint16 checksum;
|
||||||
|
guint idx_page_start;
|
||||||
|
GBytes *fw; /* noref */
|
||||||
|
FuProgress *progress; /* noref */
|
||||||
|
} FuElantpHaptictpWriteHelper;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
fu_elantp_hid_haptic_device_write_firmware(FuDevice *device,
|
fu_elantp_hid_haptic_device_write_chunks_cb(FuDevice *device, gpointer user_data, GError **error)
|
||||||
FuFirmware *firmware,
|
|
||||||
FuProgress *progress,
|
|
||||||
FwupdInstallFlags flags,
|
|
||||||
GError **error)
|
|
||||||
{
|
{
|
||||||
FuElantpHidDevice *parent;
|
FuElantpHaptictpWriteHelper *helper = (FuElantpHaptictpWriteHelper *)user_data;
|
||||||
FuElantpHidHapticDevice *self = FU_ELANTP_HID_HAPTIC_DEVICE(device);
|
FuElantpHidHapticDevice *self = FU_ELANTP_HID_HAPTIC_DEVICE(device);
|
||||||
gsize bufsz = 0;
|
FuElantpHidDevice *parent;
|
||||||
guint16 checksum = 0;
|
const guint16 eeprom_fw_page_size = 32;
|
||||||
guint16 checksum_device = 0;
|
|
||||||
guint16 eeprom_fw_page_size = 32;
|
|
||||||
guint16 retry_cnt = 0;
|
|
||||||
guint8 first_page[32] = {0x0};
|
|
||||||
const gchar *fw_ver;
|
|
||||||
const gchar *fw_ver_device;
|
|
||||||
const guint8 *buf;
|
|
||||||
g_autoptr(GBytes) fw = NULL;
|
|
||||||
g_autoptr(GPtrArray) chunks = NULL;
|
g_autoptr(GPtrArray) chunks = NULL;
|
||||||
g_autoptr(GError) error_local = NULL;
|
|
||||||
FuElantpHaptictpWaitFlashEEPROMChecksumHelper helper;
|
|
||||||
|
|
||||||
/* progress */
|
|
||||||
fu_progress_set_id(progress, G_STRLOC);
|
|
||||||
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_BUSY, 5, "detach");
|
|
||||||
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_WRITE, 80, NULL);
|
|
||||||
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_VERIFY, 10, NULL);
|
|
||||||
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_RESTART, 5, NULL);
|
|
||||||
|
|
||||||
/* simple image */
|
|
||||||
fw = fu_firmware_get_bytes(firmware, error);
|
|
||||||
if (fw == NULL)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
|
/* use parent */
|
||||||
parent = fu_elantp_haptic_device_get_parent(device, error);
|
parent = fu_elantp_haptic_device_get_parent(device, error);
|
||||||
if (parent == NULL)
|
if (parent == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* detach */
|
/* progress */
|
||||||
if (!fu_elantp_hid_haptic_device_detach(device, fu_progress_get_child(progress), error))
|
chunks = fu_chunk_array_new_from_bytes(helper->fw, 0x0, 0x0, eeprom_fw_page_size);
|
||||||
return FALSE;
|
fu_progress_set_id(helper->progress, G_STRLOC);
|
||||||
fu_progress_step_done(progress);
|
fu_progress_set_steps(helper->progress, chunks->len - helper->idx_page_start + 1);
|
||||||
|
for (guint i = helper->idx_page_start; i <= chunks->len; i++) {
|
||||||
/* write each block */
|
|
||||||
buf = g_bytes_get_data(fw, &bufsz);
|
|
||||||
chunks = fu_chunk_array_new(buf, bufsz, 0x0, 0x0, eeprom_fw_page_size);
|
|
||||||
for (guint i = 0; i <= chunks->len; i++) {
|
|
||||||
guint16 index = i * eeprom_fw_page_size;
|
|
||||||
FuChunk *chk;
|
FuChunk *chk;
|
||||||
guint16 csum_tmp;
|
guint16 csum_tmp;
|
||||||
gsize blksz = self->fw_page_size + 3;
|
gsize blksz = self->fw_page_size + 3;
|
||||||
@ -655,9 +632,10 @@ fu_elantp_hid_haptic_device_write_firmware(FuDevice *device,
|
|||||||
blk[0] = 0x0B; /* report ID */
|
blk[0] = 0x0B; /* report ID */
|
||||||
blk[1] = eeprom_fw_page_size + 5;
|
blk[1] = eeprom_fw_page_size + 5;
|
||||||
blk[2] = 0xA2;
|
blk[2] = 0xA2;
|
||||||
fu_memwrite_uint16(blk + 0x3, index, G_BIG_ENDIAN);
|
fu_memwrite_uint16(blk + 0x3, i * eeprom_fw_page_size, G_BIG_ENDIAN);
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
guint8 first_page[32] = {0x0};
|
||||||
memset(&first_page[0], 0xFF, sizeof(first_page));
|
memset(&first_page[0], 0xFF, sizeof(first_page));
|
||||||
csum_tmp = fu_sum16(first_page, eeprom_fw_page_size);
|
csum_tmp = fu_sum16(first_page, eeprom_fw_page_size);
|
||||||
if (!fu_memcpy_safe(blk,
|
if (!fu_memcpy_safe(blk,
|
||||||
@ -709,10 +687,6 @@ fu_elantp_hid_haptic_device_write_firmware(FuDevice *device,
|
|||||||
if (!fu_elantp_hid_haptic_device_ensure_eeprom_iap_ctrl(FU_DEVICE(parent),
|
if (!fu_elantp_hid_haptic_device_ensure_eeprom_iap_ctrl(FU_DEVICE(parent),
|
||||||
self,
|
self,
|
||||||
&error_iapctrl)) {
|
&error_iapctrl)) {
|
||||||
if (g_error_matches(error_iapctrl, G_IO_ERROR, G_IO_ERROR_BUSY)) {
|
|
||||||
i -= 1;
|
|
||||||
retry_cnt++;
|
|
||||||
if (retry_cnt >= 3) {
|
|
||||||
g_set_error(error,
|
g_set_error(error,
|
||||||
FWUPD_ERROR,
|
FWUPD_ERROR,
|
||||||
FWUPD_ERROR_WRITE,
|
FWUPD_ERROR_WRITE,
|
||||||
@ -721,24 +695,66 @@ fu_elantp_hid_haptic_device_write_firmware(FuDevice *device,
|
|||||||
error_iapctrl->message);
|
error_iapctrl->message);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
g_set_error(error,
|
|
||||||
FWUPD_ERROR,
|
|
||||||
FWUPD_ERROR_WRITE,
|
|
||||||
"bootloader reports failed write: 0x%x (%s)",
|
|
||||||
self->iap_ctrl,
|
|
||||||
error_iapctrl->message);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
retry_cnt = 0;
|
|
||||||
|
|
||||||
/* update progress */
|
/* update progress */
|
||||||
checksum += csum_tmp;
|
helper->checksum += csum_tmp;
|
||||||
fu_progress_set_percentage_full(fu_progress_get_child(progress),
|
helper->idx_page_start = i + 1;
|
||||||
(gsize)i + 1,
|
fu_progress_step_done(helper->progress);
|
||||||
(gsize)chunks->len + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* success */
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
fu_elantp_hid_haptic_device_write_firmware(FuDevice *device,
|
||||||
|
FuFirmware *firmware,
|
||||||
|
FuProgress *progress,
|
||||||
|
FwupdInstallFlags flags,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
FuElantpHidDevice *parent;
|
||||||
|
FuElantpHidHapticDevice *self = FU_ELANTP_HID_HAPTIC_DEVICE(device);
|
||||||
|
guint16 checksum_device = 0;
|
||||||
|
const gchar *fw_ver;
|
||||||
|
const gchar *fw_ver_device;
|
||||||
|
g_autoptr(GBytes) fw = NULL;
|
||||||
|
g_autoptr(GError) error_local = NULL;
|
||||||
|
FuElantpHaptictpWaitFlashEEPROMChecksumHelper helper = {0x0};
|
||||||
|
FuElantpHaptictpWriteHelper helper_write = {0x0};
|
||||||
|
|
||||||
|
/* progress */
|
||||||
|
fu_progress_set_id(progress, G_STRLOC);
|
||||||
|
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_BUSY, 5, "detach");
|
||||||
|
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_WRITE, 80, NULL);
|
||||||
|
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_VERIFY, 10, NULL);
|
||||||
|
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_RESTART, 5, NULL);
|
||||||
|
|
||||||
|
/* simple image */
|
||||||
|
fw = fu_firmware_get_bytes(firmware, error);
|
||||||
|
if (fw == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* use parent */
|
||||||
|
parent = fu_elantp_haptic_device_get_parent(device, error);
|
||||||
|
if (parent == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* detach */
|
||||||
|
if (!fu_elantp_hid_haptic_device_detach(device, fu_progress_get_child(progress), error))
|
||||||
|
return FALSE;
|
||||||
|
fu_progress_step_done(progress);
|
||||||
|
|
||||||
|
/* write each block */
|
||||||
|
helper_write.fw = fw;
|
||||||
|
helper_write.progress = fu_progress_get_child(progress);
|
||||||
|
if (!fu_device_retry_full(device,
|
||||||
|
fu_elantp_hid_haptic_device_write_chunks_cb,
|
||||||
|
3,
|
||||||
|
100,
|
||||||
|
&helper_write,
|
||||||
|
error))
|
||||||
|
return FALSE;
|
||||||
fu_progress_step_done(progress);
|
fu_progress_step_done(progress);
|
||||||
|
|
||||||
if (!fu_elantp_hid_haptic_device_write_cmd(FU_DEVICE(parent),
|
if (!fu_elantp_hid_haptic_device_write_cmd(FU_DEVICE(parent),
|
||||||
@ -760,12 +776,12 @@ fu_elantp_hid_haptic_device_write_firmware(FuDevice *device,
|
|||||||
g_prefix_error(error, "read device checksum fail: ");
|
g_prefix_error(error, "read device checksum fail: ");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (checksum != checksum_device) {
|
if (helper_write.checksum != checksum_device) {
|
||||||
g_set_error(error,
|
g_set_error(error,
|
||||||
FWUPD_ERROR,
|
FWUPD_ERROR,
|
||||||
FWUPD_ERROR_WRITE,
|
FWUPD_ERROR_WRITE,
|
||||||
"checksum failed 0x%04x != 0x%04x",
|
"checksum failed 0x%04x != 0x%04x",
|
||||||
checksum,
|
helper_write.checksum,
|
||||||
checksum_device);
|
checksum_device);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user