From patchwork Sun Dec 11 08:03:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9469693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 832F660760 for ; Sun, 11 Dec 2016 08:04:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65B6E283E8 for ; Sun, 11 Dec 2016 08:04:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48BC028409; Sun, 11 Dec 2016 08:04:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D403283E8 for ; Sun, 11 Dec 2016 08:03:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752272AbcLKIDx (ORCPT ); Sun, 11 Dec 2016 03:03:53 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35432 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751244AbcLKIDw (ORCPT ); Sun, 11 Dec 2016 03:03:52 -0500 Received: by mail-pg0-f67.google.com with SMTP id p66so7312694pga.2; Sun, 11 Dec 2016 00:03:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=YSScHmZJRpSkVMusx5kN62OSwhmdMaJv55nqTzXBADc=; b=wyZOsDmahRFITANlL5R8K8d6aHcwDP5NVFre4cjunmzfxPSiDGWmAQbtxeR4zK53NK 9AN+9jGp5+h9JM470Po/Hs1oQzAwka4vKTFIWIqUM3HfKPhyjOas5aYB6XFnX5tJtfKR 6km0lIUngob5Qcox15LqzemEW4+0pDQtwcn4DLY1OrbD0zfLKDfqemyAP7XMY+aIifsY otzNwbBAe7Xw5zNNUHdj/Ewsbs6ziIdyq/6LbRjBig9/ciMqV0sP9mEkPW7nhnc3xCyj uuS9Fh9QpJ2kcP3X8ZPQTQpzt+IskqeLxEeQQ68+gmV5BQqFe1KUK4yfxlSzHgWMxh67 4AbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=YSScHmZJRpSkVMusx5kN62OSwhmdMaJv55nqTzXBADc=; b=BnhCMJ31E4J8O/kaoK0rw4D7FufAo1bxVErvB+m013DGFflNVKIZbMY3+DRX9luHbG CZVx3s8gcxmqJIjDwMl6uaYr4zlEJrcfUKGlWQJyf8rYfnNXKBgr89weWo2OVJ3bxkQM xjHvMf/lMYr5d4Fx6gLT5SU1qogPsLWWWLO+MqS+gVghnciVOO9xZNj+GVnRvtnKQK98 3uIae5480g+7JsAkIi+Qx2Xmmu/QfwmXP0hWajZaPK+44SiDU8oRlkAsQu30X5QHuG8C beVIH5W41K6L0NzDPKU6U0IaTY2zW6bBmFoa/BR1lsZBBq2wvxgFskwxdjI8+t1T9yjm FGzQ== X-Gm-Message-State: AKaTC03GIIT+eeZWZFVnkdX0LvzjRWQj1jpFOEK69KU3J4ip42OIKXKEdr5TOekYnEdJuA== X-Received: by 10.84.173.195 with SMTP id p61mr174639795plb.158.1481443432081; Sun, 11 Dec 2016 00:03:52 -0800 (PST) Received: from dtor-ws ([2620:0:1000:1311:15ac:abf1:7d17:cd34]) by smtp.gmail.com with ESMTPSA id k67sm68368028pfk.69.2016.12.11.00.03.50 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sun, 11 Dec 2016 00:03:51 -0800 (PST) Date: Sun, 11 Dec 2016 00:03:49 -0800 From: Dmitry Torokhov To: Nick Dyer Cc: Andrew Duggan , Chris Healy , Henrik Rydberg , Benjamin Tissoires , Linus Walleij , Bjorn Andersson , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v9] Input: synaptics-rmi4 - add support for F34 V7 bootloader Message-ID: <20161211080349.GB39300@dtor-ws> References: <1481415506-5152-1-git-send-email-nick@shmanahar.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1481415506-5152-1-git-send-email-nick@shmanahar.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi NIck, On Sun, Dec 11, 2016 at 12:18:26AM +0000, Nick Dyer wrote: > +static void rmi_f34v7_parse_img_header_10_bl_container(struct f34_data *f34, > + const u8 *image) > +{ > + int i; > + int num_of_containers; > + unsigned int addr; > + unsigned int container_id; > + unsigned int length; > + const u8 *content; > + struct container_descriptor *descriptor; > + > + BUG_ON(f34->v7.img.bootloader.size < 4); Killing the box because you got bad firmware is not very nice... > + > + num_of_containers = (f34->v7.img.bootloader.size - 4) / 4; Wouldn't num_of_containes = f34->v7.img.bootloader.size / 4 - 1; give the same result but be less "suspicious". The variable is 'int' so for size < 4 we'll get a negative and the loop won't execute. > + > + for (i = 1; i <= num_of_containers; i++) { > + addr = get_unaligned_le32(f34->v7.img.bootloader.data + i*4); > + descriptor = (struct container_descriptor *)(image + addr); This casts away constness, which is not nice. DOes it still work if you apply the below on top? Thanks! Tested-by: Nick Dyer diff --git a/drivers/input/rmi4/rmi_f34.h b/drivers/input/rmi4/rmi_f34.h index 12827f4..2c21056 100644 --- a/drivers/input/rmi4/rmi_f34.h +++ b/drivers/input/rmi4/rmi_f34.h @@ -145,7 +145,7 @@ struct f34v7_data_1_5 { } __packed; struct block_data { - const u8 *data; + const void *data; int size; }; @@ -290,8 +290,8 @@ struct f34v7_data { struct physical_address phyaddr; struct image_metadata img; - const u8 *config_data; - const u8 *image; + const void *config_data; + const void *image; }; struct f34_data { diff --git a/drivers/input/rmi4/rmi_f34v7.c b/drivers/input/rmi4/rmi_f34v7.c index f7b6c0a..ca31f95 100644 --- a/drivers/input/rmi4/rmi_f34v7.c +++ b/drivers/input/rmi4/rmi_f34v7.c @@ -348,7 +348,7 @@ static int rmi_f34v7_read_f34v7_partition_table(struct f34_data *f34) } static void rmi_f34v7_parse_partition_table(struct f34_data *f34, - const u8 *partition_table, + const void *partition_table, struct block_count *blkcount, struct physical_address *phyaddr) { @@ -356,11 +356,11 @@ static void rmi_f34v7_parse_partition_table(struct f34_data *f34, int index; u16 partition_length; u16 physical_address; - struct partition_table *ptable; + const struct partition_table *ptable; for (i = 0; i < f34->v7.partitions; i++) { index = i * 8 + 2; - ptable = (struct partition_table *)&partition_table[index]; + ptable = partition_table + index; partition_length = le16_to_cpu(ptable->partition_length); physical_address = le16_to_cpu(ptable->start_physical_address); rmi_dbg(RMI_DEBUG_FN, &f34->fn->dev, @@ -503,7 +503,7 @@ static int rmi_f34v7_read_queries(struct f34_data *f34) f34->v7.block_size = le16_to_cpu(query_1_7.block_size); f34->v7.flash_config_length = - le16_to_cpu(query_1_7.flash_config_length); + le16_to_cpu(query_1_7.flash_config_length); f34->v7.payload_length = le16_to_cpu(query_1_7.payload_length); rmi_dbg(RMI_DEBUG_FN, &f34->fn->dev, "%s: f34->v7.block_size = %d\n", @@ -812,7 +812,7 @@ static int rmi_f34v7_read_f34v7_blocks(struct f34_data *f34, u16 block_cnt, } static int rmi_f34v7_write_f34v7_blocks(struct f34_data *f34, - const u8 *block_ptr, u16 block_cnt, + const void *block_ptr, u16 block_cnt, u8 command) { int ret; @@ -915,17 +915,10 @@ static int rmi_f34v7_write_dp_config(struct f34_data *f34) static int rmi_f34v7_write_guest_code(struct f34_data *f34) { - u16 blk_count; - int ret; - - blk_count = f34->v7.img.guest_code.size / f34->v7.block_size; - - ret = rmi_f34v7_write_f34v7_blocks(f34, f34->v7.img.guest_code.data, - blk_count, v7_CMD_WRITE_GUEST_CODE); - if (ret < 0) - return ret; - - return 0; + return rmi_f34v7_write_f34v7_blocks(f34, f34->v7.img.guest_code.data, + f34->v7.img.guest_code.size / + f34->v7.block_size, + v7_CMD_WRITE_GUEST_CODE); } static int rmi_f34v7_write_flash_config(struct f34_data *f34) @@ -1025,14 +1018,14 @@ static void rmi_f34v7_compare_partition_tables(struct f34_data *f34) return; } - if (f34->v7.has_display_cfg - && f34->v7.phyaddr.dp_config != f34->v7.img.phyaddr.dp_config) { + if (f34->v7.has_display_cfg && + f34->v7.phyaddr.dp_config != f34->v7.img.phyaddr.dp_config) { f34->v7.new_partition_table = true; return; } - if (f34->v7.has_guest_code - && f34->v7.phyaddr.guest_code != f34->v7.img.phyaddr.guest_code) { + if (f34->v7.has_guest_code && + f34->v7.phyaddr.guest_code != f34->v7.img.phyaddr.guest_code) { f34->v7.new_partition_table = true; return; } @@ -1041,23 +1034,21 @@ static void rmi_f34v7_compare_partition_tables(struct f34_data *f34) } static void rmi_f34v7_parse_img_header_10_bl_container(struct f34_data *f34, - const u8 *image) + const void *image) { int i; int num_of_containers; unsigned int addr; unsigned int container_id; unsigned int length; - const u8 *content; - struct container_descriptor *descriptor; + const void *content; + const struct container_descriptor *descriptor; - BUG_ON(f34->v7.img.bootloader.size < 4); - - num_of_containers = (f34->v7.img.bootloader.size - 4) / 4; + num_of_containers = f34->v7.img.bootloader.size / 4 - 1; for (i = 1; i <= num_of_containers; i++) { - addr = get_unaligned_le32(f34->v7.img.bootloader.data + i*4); - descriptor = (struct container_descriptor *)(image + addr); + addr = get_unaligned_le32(f34->v7.img.bootloader.data + i * 4); + descriptor = image + addr; container_id = le16_to_cpu(descriptor->container_id); content = image + le32_to_cpu(descriptor->content_address); length = le32_to_cpu(descriptor->content_length); @@ -1086,13 +1077,10 @@ static void rmi_f34v7_parse_image_header_10(struct f34_data *f34) unsigned int offset; unsigned int container_id; unsigned int length; - const u8 *image; + const void *image = f34->v7.image; const u8 *content; - struct container_descriptor *descriptor; - struct image_header_10 *header; - - image = f34->v7.image; - header = (struct image_header_10 *)image; + const struct container_descriptor *descriptor; + const struct image_header_10 *header = image; f34->v7.img.checksum = le32_to_cpu(header->checksum); @@ -1101,7 +1089,7 @@ static void rmi_f34v7_parse_image_header_10(struct f34_data *f34) /* address of top level container */ offset = le32_to_cpu(header->top_level_container_start_addr); - descriptor = (struct container_descriptor *)(image + offset); + descriptor = image + offset; /* address of top level container content */ offset = le32_to_cpu(descriptor->content_address); @@ -1110,7 +1098,7 @@ static void rmi_f34v7_parse_image_header_10(struct f34_data *f34) for (i = 0; i < num_of_containers; i++) { addr = get_unaligned_le32(image + offset); offset += 4; - descriptor = (struct container_descriptor *)(image + addr); + descriptor = image + addr; container_id = le16_to_cpu(descriptor->container_id); content = image + le32_to_cpu(descriptor->content_address); length = le32_to_cpu(descriptor->content_length); @@ -1164,9 +1152,7 @@ static void rmi_f34v7_parse_image_header_10(struct f34_data *f34) static int rmi_f34v7_parse_image_info(struct f34_data *f34) { - struct image_header_10 *header; - - header = (struct image_header_10 *)f34->v7.image; + const struct image_header_10 *header = f34->v7.image; memset(&f34->v7.img, 0x00, sizeof(f34->v7.img));