From patchwork Mon Feb 9 18:31:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Fuzzey X-Patchwork-Id: 5802791 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 783099F30C for ; Mon, 9 Feb 2015 19:12:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 131D72010B for ; Mon, 9 Feb 2015 19:12:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A0AC320109 for ; Mon, 9 Feb 2015 19:12:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760976AbbBITMM (ORCPT ); Mon, 9 Feb 2015 14:12:12 -0500 Received: from ip83.parkeon.com ([213.152.31.83]:47861 "EHLO mta2.parkeon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760210AbbBITML (ORCPT ); Mon, 9 Feb 2015 14:12:11 -0500 X-Greylist: delayed 2469 seconds by postgrey-1.27 at vger.kernel.org; Mon, 09 Feb 2015 14:12:11 EST Received: from time001.besancon.parkeon.com ([10.32.16.23] helo=mail.besancon.parkeon.com) by mta2.parkeon.com with esmtp (Exim 4.82) (envelope-from ) id 1YKt7Y-0006Cc-Kl; Mon, 09 Feb 2015 19:31:44 +0100 Received: from [10.32.51.181] (port=35690 helo=[127.0.0.1]) by mail.besancon.parkeon.com with esmtp (Exim 4.71) (envelope-from ) id 1YKt7b-0007lS-GN; Mon, 09 Feb 2015 19:31:47 +0100 Subject: [PATCH] Input: atmel_mxt_ts: Fix random configuration load failure To: Henrik Rydberg , Nick Dyer , linux-input@vger.kernel.org From: Martin Fuzzey Date: Mon, 09 Feb 2015 19:31:47 +0100 Message-ID: <20150209183147.26132.22331.stgit@localhost> User-Agent: StGit/0.16 MIME-Version: 1.0 X-Spam-Score: -2.0 (--) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Sometimes configuration fails to load with: Bad format: failed to parse object This can occur because the firmware loader does not ensure that the configuration data is null terminated. The scanf() therefore reads arbitrary garbage at the end of file. If one item of garbage happens to be parsable the error occurs. By skipping control characters (line endings) before scanning each line rather than relying on the white space skipping of sscanf we correctly detect end of file. Signed-off-by: Martin Fuzzey --- drivers/input/touchscreen/atmel_mxt_ts.c | 7 +++++++ 1 file changed, 7 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 0666759..29f9b9d 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1086,6 +1086,13 @@ static int mxt_prepare_cfg_mem(struct mxt_data *data, u8 val; while (data_pos < cfg->size) { + if (cfg->data[data_pos] < 0x20) { + /* firmware loading does not ensure null termination + * which is required by scanf */ + data_pos++; + continue; + } + /* Read type, instance, length */ ret = sscanf(cfg->data + data_pos, "%x %x %x%n", &type, &instance, &size, &offset);