@@ -1905,7 +1905,7 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw)
int ret;
int offset;
int i;
- u32 info_crc, config_crc, calculated_crc;
+ u32 info_crc, config_crc, calculated_crc = 0;
u16 crc_start = 0;
/* Make zero terminated copy of the OBP_RAW file */
@@ -1968,30 +1968,6 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw)
}
cfg.raw_pos += offset;
- /*
- * The Info Block CRC is calculated over mxt_info and the object
- * table. If it does not match then we are trying to load the
- * configuration from a different chip or firmware version, so
- * the configuration CRC is invalid anyway.
- */
- if (info_crc == data->info_crc) {
- if (config_crc == 0 || data->config_crc == 0) {
- dev_info(dev, "CRC zero, attempting to apply config\n");
- } else if (config_crc == data->config_crc) {
- dev_dbg(dev, "Config CRC 0x%06X: OK\n",
- data->config_crc);
- ret = 0;
- goto release_raw;
- } else {
- dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n",
- data->config_crc, config_crc);
- }
- } else {
- dev_warn(dev,
- "Warning: Info CRC error - device=0x%06X file=0x%06X\n",
- data->info_crc, info_crc);
- }
-
/* Malloc memory to store configuration */
cfg.start_ofs = MXT_OBJECT_START +
data->info->object_num * sizeof(struct mxt_object) +
@@ -2015,14 +1991,45 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw)
else
dev_warn(dev, "Could not find CRC start\n");
- if (crc_start > cfg.start_ofs) {
+ if (crc_start > cfg.start_ofs)
calculated_crc = mxt_calculate_crc(cfg.mem,
crc_start - cfg.start_ofs,
cfg.mem_size);
- if (config_crc > 0 && config_crc != calculated_crc)
- dev_warn(dev, "Config CRC in file inconsistent, calculated=%06X, file=%06X\n",
- calculated_crc, config_crc);
+ /* If the CRC stored in the file is not the same as what
+ * was calculated by mxt_calculate_crc, this means we
+ * have to refuse the config file and abort download.
+ */
+ if (config_crc != calculated_crc) {
+ dev_warn(dev,
+ "Config CRC in file inconsistent, calculated=%06X, file=%06X\n",
+ calculated_crc, config_crc);
+ ret = 0;
+ goto release_mem;
+ }
+
+ /*
+ * The Info Block CRC is calculated over mxt_info and the object
+ * table. If it does not match then we are trying to load the
+ * configuration from a different chip or firmware version, so
+ * the configuration CRC is invalid anyway.
+ */
+ if (info_crc == data->info_crc) {
+ if (config_crc == 0 || data->config_crc == 0) {
+ dev_info(dev, "CRC zero, attempting to apply config\n");
+ } else if (config_crc == data->config_crc) {
+ dev_dbg(dev, "Config CRC 0x%06X: OK\n",
+ data->config_crc);
+ ret = 0;
+ goto release_mem;
+ } else {
+ dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n",
+ data->config_crc, config_crc);
+ }
+ } else {
+ dev_warn(dev,
+ "Warning: Info CRC error - device=0x%06X file=0x%06X\n",
+ data->info_crc, info_crc);
}
ret = mxt_upload_cfg_mem(data, &cfg);