Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1370165ybj; Thu, 7 May 2020 23:04:10 -0700 (PDT) X-Google-Smtp-Source: APiQypI9d+dfrOIFYXJplS8STdaNTbRGWocnrlnIZG/0f+f+38bOYQrQt7r7KH5Q/o/eYdikmJ2+ X-Received: by 2002:a17:906:4048:: with SMTP id y8mr517672ejj.258.1588917849894; Thu, 07 May 2020 23:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588917849; cv=none; d=google.com; s=arc-20160816; b=NnuXUw/n7otaEdzBpFswB7cPHsGslwgPBQQvpk0+OdLrTeHHqWlOWJXXX4VkJPR12C dBaT5oEJ/VWUdhht22K83bxA+8DzqWy3S+RWmCMaOlNPcNfRcmhmEI5+Uf7rTuO1xFsq j5QNC7j/vfittRjE3GjhoQqYdH9qiHAVywonjrkh/ckUqdtj+umfMD8FnO9OOI0pCdGw B4id7IVYDjpHYfVg64CA7niY8L3Stjcd6ALVrK+uXC2IGI2QAvv5koQSvb+9hXw3z9Y4 8QcWl5uwK6tb1+v+/BW8LTcpiwYp7GszJb+sX0ZMN8OsMPFsnlk1FIpDGFrtxo8CeHcC ymlQ== 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=mVXzEFiBQ8hAduVX9vcsmnj9a/hC7UgDSCActjYPot0=; b=0W6dV4HYaAXRvMiPkQZ76pZv391pkuoxEhpd2xbwje5XEZrCpHe9zjEvsmITk3RBVf b4i4FJHLkp2tbrEYdIjx99k3s1i/ljmU5uNrETZWzC0b3LkBXmzQX3sWosDj2rZRGDr3 t5ky1qawPsM4f4Hbr/68Iw0muJCldppGhx6JK6akB0/8Hp3DS9z5mHQahpJbmtm1yC/y HzXeGiB+GN+cGYJoU/bC6m5u5X8A5PEebm6YR0/mpFbcV5ec6Sp578t7iCQ4Qt91yKB5 6rxVUFs6SWOTk0AzmQwpzZL6VN2wgfUxlZjD9npANrEm4D048g8QzfxacfUTzV+jFbT0 Gm+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si365080eja.20.2020.05.07.23.03.47; Thu, 07 May 2020 23:04:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726776AbgEHF7g (ORCPT + 99 others); Fri, 8 May 2020 01:59:36 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:22062 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728204AbgEHF7d (ORCPT ); Fri, 8 May 2020 01:59:33 -0400 IronPort-SDR: 9FXnISG8iVIz06Ci1hq+aym5kY0bW4FQxxKZ1sbZKttlRFNDRSmOkrGPSdwh/33vrV8huYS+9N CWwkXkmL6e45m0k7m6KObnfNDo9hMY+mqvKz2hHcCeY8Y9Tu/sGOKBWUqqaC+5RS/hwxZkcBBz e8ZVvvMO06XDVsDcA9TSsQqoOTfOG3jlQeJ46ZghatoiEaBWqooN8H5NEBTmTMuo5td2MCtgSF +piphqFwWmO5oKKniN5L2J9NkOraVfh4F2rL7UiTibKg9ESRl/EBgRiBZQT6BI94YcF3uPy0da lmM= X-IronPort-AV: E=Sophos;i="5.73,366,1583222400"; d="scan'208";a="48589131" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 07 May 2020 21:59:32 -0800 IronPort-SDR: 8NF/PDMjkJXD1+qb8TXq/zbB285WiIfPmyl29LuEh94wRHstxvWjbeaH+qRHY3APDZAGVlLWTE WXk/jmvVaA/XhayR3t9KjiwMNOP5+J3u48vzQF6IUXKuLFyHexI64AsD1WWVF0xtFYWtu8D/xu Qb8t7epXFvFLhkIo6fCz+6mr/CjHSNVZCSF01aUurD3PJvtXckPrwBnIAT1U4JkxzbT6SwpwRM vZWS/Ko6DFzFsueW2madt+EmuZPVJE6XWfFylEHcGiTBwSeEeDTTIMj/IWBn800H3KWUgjTgMM HLg= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v11 40/56] Input: atmel_mxt_ts - rely on calculated_crc rather than file config_crc Date: Thu, 7 May 2020 22:56:40 -0700 Message-ID: <20200508055656.96389-41-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200508055656.96389-1-jiada_wang@mentor.com> References: <20200508055656.96389-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 9281a574ca80..75329f87927b 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1891,7 +1891,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 */ @@ -1954,30 +1954,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) + @@ -2001,14 +1977,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