Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp625546ybb; Wed, 25 Mar 2020 06:37:24 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtTLbb7XzGiBnf7zEfa6fq4fCnx8Kc/XO7Tfu3RQG2pozvu5s29CVZhZ5A94Z5u+zmvot33 X-Received: by 2002:a05:6830:1bc9:: with SMTP id v9mr2360065ota.169.1585143444564; Wed, 25 Mar 2020 06:37:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585143444; cv=none; d=google.com; s=arc-20160816; b=OXWTCsG/tdg1sZsQ5TCiNjcHfNz08KgcQobJRfsZu+intuAteH4JsxgGCUGFh1Bi+U LWyiL1o0tb6RMd2VUpn+Bffnzwx5IGFvvs6v4Zb0lwQ7gCTvAn8ww1u12IzUn7Llq94w B2gBmFaieZSxOe9lkFk8sggmD+6kUps+6nKArjqwcOgmIjamqOYDPjw7vFb3ZI0vjVT+ jFLLyy+OQ/miIBCfuxxbFU2Qfc2o3XBEJWnyS+AUu+9XsS8+Dnsr7fRdXCguR5LW38gP 1jAa+oUngA2qXPb2RudTjSfv1r4h8xU8MluVlBwCQunQbedQSTCeTR2WdFoCBIfDvz/N mdwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=LI5UIXinFqMN7wJbN7lwX4m5UTPjKMCd9LoS/Ul2gZ8=; b=AVubnzryKMWqUX7fEGlIWYChAp1at+Z9+2cQn2dK5fehxuG/0kBjlvGe9tlXMYMpDc n0xr0PlaxesKUNZDQ4ANz+52RIIQaPjcEMTV/spjM31CTm9SBYUZ6dwS8zR6MRIbxw7M hmZaWE853cESsZXRYFXxC04fVTqzZc1SQiSmStAug47OUcWGII0l4bA6xr50TNicuXAY gM1H7+yFZaN4kS3xZ4JYSoQAy1JGWjsuOEZ4GlPmtRIv5YNr6Lk/QOAZAB2wOuYGO97C wCC5vExd+WgIyvMS3oVwpxijs53lWvmcWbhBK7FJvncz0UHhmxt67J6nnowH7xwb9Rnu 8bRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7si4198836otr.95.2020.03.25.06.37.11; Wed, 25 Mar 2020 06:37:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727991AbgCYNgP (ORCPT + 99 others); Wed, 25 Mar 2020 09:36:15 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:4463 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727674AbgCYNgN (ORCPT ); Wed, 25 Mar 2020 09:36:13 -0400 IronPort-SDR: zrkj7TecQ9lyCs6f+qIXftghFMmV540mObqywNUMV0lxoK3s5TCXyol+/ysCTuy0bpoqpQmxxg BGqUQrl8+ZadwvJ3DHNt/F+0g0IQFG1XycXc/h2tsLQXtRNFyz5rcP+AMCGv8gVGVBjatCAg/C nh9mCIkIHPrNAWCqH6KuezWlpuSCY5/2BFwEH8QD+FqvV5zHGo33Js254klEiEnx+t4aCWB57O tWcSEIYY9aOTuB2/KYgn/BwMiBMWrSmhkYG+DfEWrzEgmrxABamZAlH4vGv61jCzvS+PeUpPiZ acE= X-IronPort-AV: E=Sophos;i="5.72,304,1580803200"; d="scan'208";a="49060142" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 25 Mar 2020 05:36:12 -0800 IronPort-SDR: LT5SlzatSVp5hQPs/vSJ4k5lJ9x9Ib8qAoH8a4owFPQwQZxUL64LjQDj4Sg7kSSMCPaEPlFmlq 5FXsQIlCQU6ICv2m5N/FGuqPx2srMG7L3vxrv78tpjKRUl+VJgvn4mKuKXazaxQcUUq3meA1aH YxKPu0d6JwygEP2qkL7f6mV+aESgcLqGc0b+S6lI7VTV7wfzL3EQJUchtfGCwKYO+C2JEzBluv vJVViP17f8nywRqhSaJb3ywXos50wEQpB35xlBixPeA6LG8dnitzR2ewI9FVQSUPX2YwjrrxTQ 35I= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v9 38/55] Input: atmel_mxt_ts - rely on calculated_crc rather than file config_crc Date: Wed, 25 Mar 2020 06:33:17 -0700 Message-ID: <20200325133334.19346-39-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200325133334.19346-1-jiada_wang@mentor.com> References: <20200325133334.19346-1-jiada_wang@mentor.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kautuk Consul We now prefer to rely on the calculated CRC and not on the CRC stored in the file. The new logic is as follows: 1) stored CRC of file != calculated CRC of file, then refuse the possible corrupted file 2) calculated CRC of file != CRC of configuration in controller, then update configuration in controller 3) calculated CRC of file == CRC of configuration in controller, then ignore configuration file Signed-off-by: Kautuk Consul Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 65 +++++++++++++----------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 860e8ddd4c6b..11e65f32b1a2 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -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); -- 2.17.1