Commit 8a7c71ae authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: synaptics-rmi4 - cleanup SMbus mapping handling

There is no reason to copy structures field-by-filed when we can copy
elements at once.
Reviewed-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 2593cd11
...@@ -83,63 +83,56 @@ static int rmi_smb_get_command_code(struct rmi_transport_dev *xport, ...@@ -83,63 +83,56 @@ static int rmi_smb_get_command_code(struct rmi_transport_dev *xport,
{ {
struct rmi_smb_xport *rmi_smb = struct rmi_smb_xport *rmi_smb =
container_of(xport, struct rmi_smb_xport, xport); container_of(xport, struct rmi_smb_xport, xport);
struct mapping_table_entry new_map;
int i; int i;
int retval; int retval = 0;
struct mapping_table_entry mapping_data[1];
mutex_lock(&rmi_smb->mappingtable_mutex); mutex_lock(&rmi_smb->mappingtable_mutex);
for (i = 0; i < RMI_SMB2_MAP_SIZE; i++) { for (i = 0; i < RMI_SMB2_MAP_SIZE; i++) {
struct mapping_table_entry *entry = &rmi_smb->mapping_table[i]; struct mapping_table_entry *entry = &rmi_smb->mapping_table[i];
if (le16_to_cpu(entry->rmiaddr) == rmiaddr) { if (le16_to_cpu(entry->rmiaddr) == rmiaddr) {
if (isread) { if (isread) {
if (entry->readcount == bytecount) { if (entry->readcount == bytecount)
*commandcode = i;
retval = 0;
goto exit; goto exit;
}
} else { } else {
if (entry->flags & RMI_SMB2_MAP_FLAGS_WE) { if (entry->flags & RMI_SMB2_MAP_FLAGS_WE) {
*commandcode = i;
retval = 0;
goto exit; goto exit;
} }
} }
} }
} }
i = rmi_smb->table_index; i = rmi_smb->table_index;
rmi_smb->table_index = (i + 1) % RMI_SMB2_MAP_SIZE; rmi_smb->table_index = (i + 1) % RMI_SMB2_MAP_SIZE;
/* constructs mapping table data entry. 4 bytes each entry */ /* constructs mapping table data entry. 4 bytes each entry */
memset(mapping_data, 0, sizeof(mapping_data)); memset(&new_map, 0, sizeof(new_map));
new_map.rmiaddr = cpu_to_le16(rmiaddr);
mapping_data[0].rmiaddr = cpu_to_le16(rmiaddr); new_map.readcount = bytecount;
mapping_data[0].readcount = bytecount; new_map.flags = !isread ? RMI_SMB2_MAP_FLAGS_WE : 0;
mapping_data[0].flags = !isread ? RMI_SMB2_MAP_FLAGS_WE : 0;
retval = smb_block_write(xport, i + 0x80, mapping_data,
sizeof(mapping_data));
retval = smb_block_write(xport, i + 0x80, &new_map, sizeof(new_map));
if (retval < 0) { if (retval < 0) {
/* /*
* if not written to device mapping table * if not written to device mapping table
* clear the driver mapping table records * clear the driver mapping table records
*/ */
rmi_smb->mapping_table[i].rmiaddr = 0x0000; memset(&new_map, 0, sizeof(new_map));
rmi_smb->mapping_table[i].readcount = 0;
rmi_smb->mapping_table[i].flags = 0;
goto exit;
} }
/* save to the driver level mapping table */ /* save to the driver level mapping table */
rmi_smb->mapping_table[i].rmiaddr = rmiaddr; rmi_smb->mapping_table[i] = new_map;
rmi_smb->mapping_table[i].readcount = bytecount;
rmi_smb->mapping_table[i].flags = !isread ? RMI_SMB2_MAP_FLAGS_WE : 0;
*commandcode = i;
exit: exit:
mutex_unlock(&rmi_smb->mappingtable_mutex); 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, static int rmi_smb_write_block(struct rmi_transport_dev *xport, u16 rmiaddr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment