From patchwork Tue May 30 04:49:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9753763 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 BBC58602BF for ; Tue, 30 May 2017 04:49:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B8D6274B4 for ; Tue, 30 May 2017 04:49:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CF0B27E63; Tue, 30 May 2017 04:49:49 +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 20589274B4 for ; Tue, 30 May 2017 04:49:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750821AbdE3Ets (ORCPT ); Tue, 30 May 2017 00:49:48 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34149 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750758AbdE3Etr (ORCPT ); Tue, 30 May 2017 00:49:47 -0400 Received: by mail-pf0-f196.google.com with SMTP id w69so15198194pfk.1; Mon, 29 May 2017 21:49:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=9Tb51P9im7sqscq/G9Y7U8PoOyQeMQ3YBvLn6MZsQV4=; b=koOVGBXpDcUZfxq+wT4htKEdULY2T+9s+kJsFKMIMgYUaQK2GOV1zWTYojoYXpfa8K A2WNtP8SUpdG0WmVhh4ginrlJb5EmPUYOHMlC0wGhfJVgfqZO8IVLh5OHJbd/8zGuGY+ oHWyV9Vmk+N278aSbM1mUh2x6EN4WHGhsWYaLpJ574JdEs/SQNZlVBOTValnD5du0p78 v+6QpqlNt3gzbWLHvL12d5YrXPJxxHLq5hGri/+QL6rkamDA4ulzQ0NC5kawjOmHN8iq 21kdBl4yVqSMpr8KjZOjEkJ+c3dyKSXxbaqUsMxWlW1LSFpUKUzhQHnoI8YFOnj3qwy8 FyLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=9Tb51P9im7sqscq/G9Y7U8PoOyQeMQ3YBvLn6MZsQV4=; b=OVz2d/SWPhmHC7yevASfvGP+4egrjzEBtm/0AlckZDpRRpmFra6rmHk4W1k4gzHcda TuGY51w7cST7bPaql3DTFoMY8EybLfoeo5vzjzO5aVuGj69rQm927nfqjew1MOg1mxhV I8NRJRfdYDyrnLr2p6qRoB+nkAYE7UPvwF/gjnnzi6c+q18K0zXbA88lwAqgUWu/x9/+ l7JVxUK8St8JbfHpOfEUQ5fwhDZYG/9AqDvu47Wb1YDllq6v0PCzcwH5qDxLEZ6quPuj NMZhbzBVseU33kbdp6GTQkfwYyHHiB73+LuJ/5ysq67xQrBiAT3NjrVwUrryt90r2T4y 0j5w== X-Gm-Message-State: AODbwcBPia1JuazVaiWpsfsRi8ckXxFrwWRZboBgs3J8u5IjkUvQPkwF euknvaOiTcNsuQ== X-Received: by 10.84.247.2 with SMTP id n2mr61619313pll.74.1496119786628; Mon, 29 May 2017 21:49:46 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1311:a91f:4c15:f7b7:ef43]) by smtp.gmail.com with ESMTPSA id d185sm16002013pgc.39.2017.05.29.21.49.45 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 29 May 2017 21:49:46 -0700 (PDT) Date: Mon, 29 May 2017 21:49:44 -0700 From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Nick Dyer , Benjamin Tissoires , Dan Carpenter , linux-kernel@vger.kernel.org Subject: [PATCH] Input: synaptics-rmi4 - use %ph to form F34 configuration ID Message-ID: <20170530044944.GA33451@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline 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 Instead of printing bytes one by one, let's use %phN to print the buffer in one go. Also use hweight8 to count number of partitions instead of inspecting it bit by bit. Signed-off-by: Dmitry Torokhov Reviewed-by: Benjamin Tissoires Tested-by: Nick Dyer --- drivers/input/rmi4/rmi_f34v7.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/input/rmi4/rmi_f34v7.c b/drivers/input/rmi4/rmi_f34v7.c index ae2db1c3aebf..3991d2943660 100644 --- a/drivers/input/rmi4/rmi_f34v7.c +++ b/drivers/input/rmi4/rmi_f34v7.c @@ -9,13 +9,14 @@ * the Free Software Foundation. */ +#include #include #include #include -#include #include #include #include +#include #include "rmi_driver.h" #include "rmi_f34.h" @@ -464,7 +465,7 @@ static int rmi_f34v7_read_queries_bl_version(struct f34_data *f34) static int rmi_f34v7_read_queries(struct f34_data *f34) { int ret; - int i, j; + int i; u8 base; int offset; u8 *ptable; @@ -519,9 +520,6 @@ static int rmi_f34v7_read_queries(struct f34_data *f34) if (query_0 & HAS_CONFIG_ID) { u8 f34_ctrl[CONFIG_ID_SIZE]; - int i = 0; - u8 *p = f34->configuration_id; - *p = '\0'; ret = rmi_read_block(f34->fn->rmi_dev, f34->fn->fd.control_base_addr, @@ -531,13 +529,11 @@ static int rmi_f34v7_read_queries(struct f34_data *f34) return ret; /* Eat leading zeros */ - while (i < sizeof(f34_ctrl) && !f34_ctrl[i]) - i++; + for (i = 0; i < sizeof(f34_ctrl) - 1 && !f34_ctrl[i]; i++) + /* Empty */; - for (; i < sizeof(f34_ctrl); i++) - p += snprintf(p, f34->configuration_id - + sizeof(f34->configuration_id) - p, - "%02X", f34_ctrl[i]); + snprintf(f34->configuration_id, sizeof(f34->configuration_id), + "%*phN", (int)sizeof(f34_ctrl) - i, f34_ctrl + i); rmi_dbg(RMI_DEBUG_FN, &f34->fn->dev, "Configuration ID: %s\n", f34->configuration_id); @@ -545,9 +541,7 @@ static int rmi_f34v7_read_queries(struct f34_data *f34) f34->v7.partitions = 0; for (i = 0; i < sizeof(query_1_7.partition_support); i++) - for (j = 0; j < 8; j++) - if (query_1_7.partition_support[i] & (1 << j)) - f34->v7.partitions++; + f34->v7.partitions += hweight8(query_1_7.partition_support[i]); rmi_dbg(RMI_DEBUG_FN, &f34->fn->dev, "%s: Supported partitions: %*ph\n", __func__, sizeof(query_1_7.partition_support),