public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	Andrew Duggan <aduggan@synaptics.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	Nick Dyer <nick@shmanahar.org>
Subject: [PATCH 3/4] Input: synaptics-rmi4 - cleanup SMbus mapping handling
Date: Fri, 24 Mar 2017 23:00:49 -0700	[thread overview]
Message-ID: <20170325060050.39867-3-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20170325060050.39867-1-dmitry.torokhov@gmail.com>

There is no reason to copy structures field-by-filed when we can copy
eements at once.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/rmi4/rmi_smbus.c | 43 ++++++++++++++++++------------------------
 1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/drivers/input/rmi4/rmi_smbus.c b/drivers/input/rmi4/rmi_smbus.c
index c8bf49686460..724643bf31a6 100644
--- a/drivers/input/rmi4/rmi_smbus.c
+++ b/drivers/input/rmi4/rmi_smbus.c
@@ -83,62 +83,55 @@ static int rmi_smb_get_command_code(struct rmi_transport_dev *xport,
 {
 	struct rmi_smb_xport *rmi_smb =
 		container_of(xport, struct rmi_smb_xport, xport);
+	struct mapping_table_entry new_map;
 	int i;
-	int retval;
-	struct mapping_table_entry mapping_data[1];
+	int retval = 0;
 
 	mutex_lock(&rmi_smb->mappingtable_mutex);
+
 	for (i = 0; i < RMI_SMB2_MAP_SIZE; i++) {
 		struct mapping_table_entry *entry = &rmi_smb->mapping_table[i];
 		if (le16_to_cpu(entry->rmiaddr) == rmiaddr) {
 			if (isread) {
-				if (entry->readcount == bytecount) {
-					*commandcode = i;
-					retval = 0;
+				if (entry->readcount == bytecount)
 					goto exit;
-				}
 			} else {
 				if (entry->flags & RMI_SMB2_MAP_FLAGS_WE) {
-					*commandcode = i;
-					retval = 0;
 					goto exit;
 				}
 			}
 		}
 	}
+
 	i = rmi_smb->table_index;
 	rmi_smb->table_index = (i + 1) % RMI_SMB2_MAP_SIZE;
 
 	/* constructs mapping table data entry. 4 bytes each entry */
-	memset(mapping_data, 0, sizeof(mapping_data));
-
-	mapping_data[0].rmiaddr = cpu_to_le16(rmiaddr);
-	mapping_data[0].readcount = bytecount;
-	mapping_data[0].flags = !isread ? RMI_SMB2_MAP_FLAGS_WE : 0;
-
-	retval = smb_block_write(xport, i + 0x80, mapping_data,
-				 sizeof(mapping_data));
+	memset(&new_map, 0, sizeof(new_map));
+	new_map.rmiaddr = cpu_to_le16(rmiaddr);
+	new_map.readcount = bytecount;
+	new_map.flags = !isread ? RMI_SMB2_MAP_FLAGS_WE : 0;
 
+	retval = smb_block_write(xport, i + 0x80, &new_map, sizeof(new_map));
 	if (retval < 0) {
 		/*
 		 * if not written to device mapping table
 		 * clear the driver mapping table records
 		 */
-		rmi_smb->mapping_table[i].rmiaddr = 0x0000;
-		rmi_smb->mapping_table[i].readcount = 0;
-		rmi_smb->mapping_table[i].flags = 0;
-		goto exit;
+		memset(&new_map, 0, sizeof(new_map));
 	}
+
 	/* save to the driver level mapping table */
-	rmi_smb->mapping_table[i].rmiaddr = rmiaddr;
-	rmi_smb->mapping_table[i].readcount = bytecount;
-	rmi_smb->mapping_table[i].flags = !isread ? RMI_SMB2_MAP_FLAGS_WE : 0;
-	*commandcode = i;
+	rmi_smb->mapping_table[i] = new_map;
 
 exit:
 	mutex_unlock(&rmi_smb->mappingtable_mutex);
 
-	return retval;
+	if (retval < 0)
+		return retval;
+
+	*commandcode = i;
+	return 0;
 }
 
 static int rmi_smb_write_block(struct rmi_transport_dev *xport, u16 rmiaddr,
-- 
2.12.1.578.ge9c3154ca4-goog

  parent reply	other threads:[~2017-03-25  6:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-25  6:00 [PATCH 1/4] Input: synaptics-rmi4 - fix handling failures from rmi_enable_sensor Dmitry Torokhov
2017-03-25  6:00 ` [PATCH 2/4] Input: synaptics-rmi4 - fix endianness issue in SMBus transport Dmitry Torokhov
2017-03-31  9:15   ` Benjamin Tissoires
2017-03-25  6:00 ` Dmitry Torokhov [this message]
2017-03-31  9:21   ` [PATCH 3/4] Input: synaptics-rmi4 - cleanup SMbus mapping handling Benjamin Tissoires
2017-03-25  6:00 ` [PATCH 4/4] Input: synaptics-rmi4 - when registering sensors do not call them "drivers" Dmitry Torokhov
2017-03-31  9:28   ` Benjamin Tissoires
2017-03-31  9:15 ` [PATCH 1/4] Input: synaptics-rmi4 - fix handling failures from rmi_enable_sensor Benjamin Tissoires

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170325060050.39867-3-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=aduggan@synaptics.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nick@shmanahar.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox