linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] mwifiex: Reduce endian conversion for REG Host Commands
@ 2016-06-23  5:29 Prasun Maiti
  2016-06-27  7:02 ` Amitkumar Karwar
  0 siblings, 1 reply; 8+ messages in thread
From: Prasun Maiti @ 2016-06-23  5:29 UTC (permalink / raw)
  To: Amitkumar Karwar
  Cc: Nishant Sarmukadam, Linux Wireless, Linux Next, Linux Kernel, Kalle Valo

For multiple REG Host Commands (e.g HostCmd_CMD_802_11_EEPROM_ACCESS,
HostCmd_CMD_MAC_REG_ACCESS etc.) "cpu_to_leX"-converted values are
saved to driver. So, "leX_to_cpu" conversion is required too many
times afterwards in driver.

This patch reduces the endian: conversion without saving "cpu_to_leX"
converted values in driver. This will convert endianness in prepare
command and command response path.

Signed-off-by: Prasun Maiti <prasunmaiti87@gmail.com>
---
Changes in v3:
	- Fixed the following warnings:
	* sta_ioctl.c:1339:34: warning: comparison of distinct pointer types lacks a cast [enabled by default]
	* sta_cmdresp.c:821:6: warning: comparison of distinct pointer types lacks a cast [enabled by default]

 drivers/net/wireless/marvell/mwifiex/sta_cmd.c     | 28 +++++++---------
 drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c | 37 +++++++++++-----------
 drivers/net/wireless/marvell/mwifiex/sta_ioctl.c   | 21 ++++++------
 3 files changed, 41 insertions(+), 45 deletions(-)

diff --git a/drivers/net/wireless/marvell/mwifiex/sta_cmd.c b/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
index e436574..9df02ba 100644
--- a/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
+++ b/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
@@ -1130,9 +1130,8 @@ static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
 		cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
 		mac_reg = &cmd->params.mac_reg;
 		mac_reg->action = cpu_to_le16(cmd_action);
-		mac_reg->offset =
-			cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
-		mac_reg->value = reg_rw->value;
+		mac_reg->offset = cpu_to_le16((u16) reg_rw->offset);
+		mac_reg->value = cpu_to_le32(reg_rw->value);
 		break;
 	}
 	case HostCmd_CMD_BBP_REG_ACCESS:
@@ -1142,9 +1141,8 @@ static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
 		cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
 		bbp_reg = &cmd->params.bbp_reg;
 		bbp_reg->action = cpu_to_le16(cmd_action);
-		bbp_reg->offset =
-			cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
-		bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
+		bbp_reg->offset = cpu_to_le16((u16) reg_rw->offset);
+		bbp_reg->value = (u8) reg_rw->value;
 		break;
 	}
 	case HostCmd_CMD_RF_REG_ACCESS:
@@ -1154,8 +1152,8 @@ static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
 		cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
 		rf_reg = &cmd->params.rf_reg;
 		rf_reg->action = cpu_to_le16(cmd_action);
-		rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
-		rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
+		rf_reg->offset = cpu_to_le16((u16) reg_rw->offset);
+		rf_reg->value = (u8) reg_rw->value;
 		break;
 	}
 	case HostCmd_CMD_PMIC_REG_ACCESS:
@@ -1165,9 +1163,8 @@ static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
 		cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
 		pmic_reg = &cmd->params.pmic_reg;
 		pmic_reg->action = cpu_to_le16(cmd_action);
-		pmic_reg->offset =
-				cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
-		pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
+		pmic_reg->offset = cpu_to_le16((u16) reg_rw->offset);
+		pmic_reg->value = (u8) reg_rw->value;
 		break;
 	}
 	case HostCmd_CMD_CAU_REG_ACCESS:
@@ -1177,9 +1174,8 @@ static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
 		cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
 		cau_reg = &cmd->params.rf_reg;
 		cau_reg->action = cpu_to_le16(cmd_action);
-		cau_reg->offset =
-				cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
-		cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
+		cau_reg->offset = cpu_to_le16((u16) reg_rw->offset);
+		cau_reg->value = (u8) reg_rw->value;
 		break;
 	}
 	case HostCmd_CMD_802_11_EEPROM_ACCESS:
@@ -1190,8 +1186,8 @@ static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,

 		cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
 		cmd_eeprom->action = cpu_to_le16(cmd_action);
-		cmd_eeprom->offset = rd_eeprom->offset;
-		cmd_eeprom->byte_count = rd_eeprom->byte_count;
+		cmd_eeprom->offset = cpu_to_le16(rd_eeprom->offset);
+		cmd_eeprom->byte_count = cpu_to_le16(rd_eeprom->byte_count);
 		cmd_eeprom->value = 0;
 		break;
 	}
diff --git a/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c b/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
index d18c797..1832511 100644
--- a/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
+++ b/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
@@ -781,45 +781,44 @@ static int mwifiex_ret_reg_access(u16 type, struct host_cmd_ds_command *resp,
 	switch (type) {
 	case HostCmd_CMD_MAC_REG_ACCESS:
 		r.mac = &resp->params.mac_reg;
-		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.mac->offset));
-		reg_rw->value = r.mac->value;
+		reg_rw->offset = (u32) le16_to_cpu(r.mac->offset);
+		reg_rw->value = le32_to_cpu(r.mac->value);
 		break;
 	case HostCmd_CMD_BBP_REG_ACCESS:
 		r.bbp = &resp->params.bbp_reg;
-		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.bbp->offset));
-		reg_rw->value = cpu_to_le32((u32) r.bbp->value);
+		reg_rw->offset = (u32) le16_to_cpu(r.bbp->offset);
+		reg_rw->value = (u32) r.bbp->value;
 		break;

 	case HostCmd_CMD_RF_REG_ACCESS:
 		r.rf = &resp->params.rf_reg;
-		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
-		reg_rw->value = cpu_to_le32((u32) r.bbp->value);
+		reg_rw->offset = (u32) le16_to_cpu(r.rf->offset);
+		reg_rw->value = (u32) r.bbp->value;
 		break;
 	case HostCmd_CMD_PMIC_REG_ACCESS:
 		r.pmic = &resp->params.pmic_reg;
-		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.pmic->offset));
-		reg_rw->value = cpu_to_le32((u32) r.pmic->value);
+		reg_rw->offset = (u32) le16_to_cpu(r.pmic->offset);
+		reg_rw->value = (u32) r.pmic->value;
 		break;
 	case HostCmd_CMD_CAU_REG_ACCESS:
 		r.rf = &resp->params.rf_reg;
-		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
-		reg_rw->value = cpu_to_le32((u32) r.rf->value);
+		reg_rw->offset = (u32) le16_to_cpu(r.rf->offset);
+		reg_rw->value = (u32) r.rf->value;
 		break;
 	case HostCmd_CMD_802_11_EEPROM_ACCESS:
 		r.eeprom = &resp->params.eeprom;
-		pr_debug("info: EEPROM read len=%x\n", r.eeprom->byte_count);
-		if (le16_to_cpu(eeprom->byte_count) <
-		    le16_to_cpu(r.eeprom->byte_count)) {
-			eeprom->byte_count = cpu_to_le16(0);
+		pr_debug("info: EEPROM read len=%x\n",
+				le16_to_cpu(r.eeprom->byte_count));
+		if (eeprom->byte_count < le16_to_cpu(r.eeprom->byte_count)) {
+			eeprom->byte_count = 0;
 			pr_debug("info: EEPROM read length is too big\n");
 			return -1;
 		}
-		eeprom->offset = r.eeprom->offset;
-		eeprom->byte_count = r.eeprom->byte_count;
-		if (le16_to_cpu(eeprom->byte_count) > 0)
+		eeprom->offset = le16_to_cpu(r.eeprom->offset);
+		eeprom->byte_count = le16_to_cpu(r.eeprom->byte_count);
+		if (eeprom->byte_count > 0)
 			memcpy(&eeprom->value, &r.eeprom->value,
-			       le16_to_cpu(r.eeprom->byte_count));
-
+			       min((u16)MAX_EEPROM_DATA, eeprom->byte_count));
 		break;
 	default:
 		return -1;
diff --git a/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c b/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
index 8e08626..6dab5ca 100644
--- a/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
+++ b/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
@@ -1247,7 +1247,7 @@ static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
 {
 	u16 cmd_no;

-	switch (le32_to_cpu(reg_rw->type)) {
+	switch (reg_rw->type) {
 	case MWIFIEX_REG_MAC:
 		cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
 		break;
@@ -1282,9 +1282,9 @@ mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
 {
 	struct mwifiex_ds_reg_rw reg_rw;

-	reg_rw.type = cpu_to_le32(reg_type);
-	reg_rw.offset = cpu_to_le32(reg_offset);
-	reg_rw.value = cpu_to_le32(reg_value);
+	reg_rw.type = reg_type;
+	reg_rw.offset = reg_offset;
+	reg_rw.value = reg_value;

 	return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
 }
@@ -1302,14 +1302,14 @@ mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
 	int ret;
 	struct mwifiex_ds_reg_rw reg_rw;

-	reg_rw.type = cpu_to_le32(reg_type);
-	reg_rw.offset = cpu_to_le32(reg_offset);
+	reg_rw.type = reg_type;
+	reg_rw.offset = reg_offset;
 	ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);

 	if (ret)
 		goto done;

-	*value = le32_to_cpu(reg_rw.value);
+	*value = reg_rw.value;

 done:
 	return ret;
@@ -1328,15 +1328,16 @@ mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
 	int ret;
 	struct mwifiex_ds_read_eeprom rd_eeprom;

-	rd_eeprom.offset = cpu_to_le16((u16) offset);
-	rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
+	rd_eeprom.offset =  offset;
+	rd_eeprom.byte_count = bytes;

 	/* Send request to firmware */
 	ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
 			       HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);

 	if (!ret)
-		memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
+		memcpy(value, rd_eeprom.value, min((u16)MAX_EEPROM_DATA,
+		       rd_eeprom.byte_count));
 	return ret;
 }

--
1.9.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* RE: [PATCH v3] mwifiex: Reduce endian conversion for REG Host Commands
  2016-06-23  5:29 [PATCH v3] mwifiex: Reduce endian conversion for REG Host Commands Prasun Maiti
@ 2016-06-27  7:02 ` Amitkumar Karwar
  2016-06-27 10:13   ` [PATCH v4] " Prasun Maiti
  0 siblings, 1 reply; 8+ messages in thread
From: Amitkumar Karwar @ 2016-06-27  7:02 UTC (permalink / raw)
  To: Prasun Maiti
  Cc: Nishant Sarmukadam, Linux Wireless, Linux Next, Linux Kernel, Kalle Valo

[-- Attachment #1: Type: text/plain, Size: 10395 bytes --]

Hi Prasun,

> From: Prasun Maiti [mailto:prasunmaiti87@gmail.com]
> Sent: Thursday, June 23, 2016 10:59 AM
> To: Amitkumar Karwar
> Cc: Nishant Sarmukadam; Linux Wireless; Linux Next; Linux Kernel; Kalle
> Valo
> Subject: [PATCH v3] mwifiex: Reduce endian conversion for REG Host
> Commands
> 
> For multiple REG Host Commands (e.g HostCmd_CMD_802_11_EEPROM_ACCESS,
> HostCmd_CMD_MAC_REG_ACCESS etc.) "cpu_to_leX"-converted values are saved
> to driver. So, "leX_to_cpu" conversion is required too many times
> afterwards in driver.
> 
> This patch reduces the endian: conversion without saving "cpu_to_leX"
> converted values in driver. This will convert endianness in prepare
> command and command response path.
> 
> Signed-off-by: Prasun Maiti <prasunmaiti87@gmail.com>
> ---
> Changes in v3:
> 	- Fixed the following warnings:
> 	* sta_ioctl.c:1339:34: warning: comparison of distinct pointer
> types lacks a cast [enabled by default]
> 	* sta_cmdresp.c:821:6: warning: comparison of distinct pointer
> types lacks a cast [enabled by default]
> 
>  drivers/net/wireless/marvell/mwifiex/sta_cmd.c     | 28 +++++++--------
> -
>  drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c | 37 +++++++++++----
> -------
>  drivers/net/wireless/marvell/mwifiex/sta_ioctl.c   | 21 ++++++------
>  3 files changed, 41 insertions(+), 45 deletions(-)
> 
> diff --git a/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
> b/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
> index e436574..9df02ba 100644
> --- a/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
> +++ b/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
> @@ -1130,9 +1130,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
>  		mac_reg = &cmd->params.mac_reg;
>  		mac_reg->action = cpu_to_le16(cmd_action);
> -		mac_reg->offset =
> -			cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
> -		mac_reg->value = reg_rw->value;
> +		mac_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		mac_reg->value = cpu_to_le32(reg_rw->value);
>  		break;
>  	}
>  	case HostCmd_CMD_BBP_REG_ACCESS:
> @@ -1142,9 +1141,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
>  		bbp_reg = &cmd->params.bbp_reg;
>  		bbp_reg->action = cpu_to_le16(cmd_action);
> -		bbp_reg->offset =
> -			cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
> -		bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
> +		bbp_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		bbp_reg->value = (u8) reg_rw->value;
>  		break;
>  	}
>  	case HostCmd_CMD_RF_REG_ACCESS:
> @@ -1154,8 +1152,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
>  		rf_reg = &cmd->params.rf_reg;
>  		rf_reg->action = cpu_to_le16(cmd_action);
> -		rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw-
> >offset));
> -		rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
> +		rf_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		rf_reg->value = (u8) reg_rw->value;
>  		break;
>  	}
>  	case HostCmd_CMD_PMIC_REG_ACCESS:
> @@ -1165,9 +1163,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
>  		pmic_reg = &cmd->params.pmic_reg;
>  		pmic_reg->action = cpu_to_le16(cmd_action);
> -		pmic_reg->offset =
> -				cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
> -		pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
> +		pmic_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		pmic_reg->value = (u8) reg_rw->value;
>  		break;
>  	}
>  	case HostCmd_CMD_CAU_REG_ACCESS:
> @@ -1177,9 +1174,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
>  		cau_reg = &cmd->params.rf_reg;
>  		cau_reg->action = cpu_to_le16(cmd_action);
> -		cau_reg->offset =
> -				cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
> -		cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
> +		cau_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		cau_reg->value = (u8) reg_rw->value;
>  		break;
>  	}
>  	case HostCmd_CMD_802_11_EEPROM_ACCESS:
> @@ -1190,8 +1186,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
> 
>  		cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
>  		cmd_eeprom->action = cpu_to_le16(cmd_action);
> -		cmd_eeprom->offset = rd_eeprom->offset;
> -		cmd_eeprom->byte_count = rd_eeprom->byte_count;
> +		cmd_eeprom->offset = cpu_to_le16(rd_eeprom->offset);
> +		cmd_eeprom->byte_count = cpu_to_le16(rd_eeprom->byte_count);
>  		cmd_eeprom->value = 0;
>  		break;
>  	}
> diff --git a/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
> b/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
> index d18c797..1832511 100644
> --- a/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
> +++ b/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
> @@ -781,45 +781,44 @@ static int mwifiex_ret_reg_access(u16 type, struct
> host_cmd_ds_command *resp,
>  	switch (type) {
>  	case HostCmd_CMD_MAC_REG_ACCESS:
>  		r.mac = &resp->params.mac_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.mac-
> >offset));
> -		reg_rw->value = r.mac->value;
> +		reg_rw->offset = (u32) le16_to_cpu(r.mac->offset);
> +		reg_rw->value = le32_to_cpu(r.mac->value);
>  		break;
>  	case HostCmd_CMD_BBP_REG_ACCESS:
>  		r.bbp = &resp->params.bbp_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.bbp-
> >offset));
> -		reg_rw->value = cpu_to_le32((u32) r.bbp->value);
> +		reg_rw->offset = (u32) le16_to_cpu(r.bbp->offset);
> +		reg_rw->value = (u32) r.bbp->value;
>  		break;
> 
>  	case HostCmd_CMD_RF_REG_ACCESS:
>  		r.rf = &resp->params.rf_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf-
> >offset));
> -		reg_rw->value = cpu_to_le32((u32) r.bbp->value);
> +		reg_rw->offset = (u32) le16_to_cpu(r.rf->offset);
> +		reg_rw->value = (u32) r.bbp->value;
>  		break;
>  	case HostCmd_CMD_PMIC_REG_ACCESS:
>  		r.pmic = &resp->params.pmic_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.pmic-
> >offset));
> -		reg_rw->value = cpu_to_le32((u32) r.pmic->value);
> +		reg_rw->offset = (u32) le16_to_cpu(r.pmic->offset);
> +		reg_rw->value = (u32) r.pmic->value;
>  		break;
>  	case HostCmd_CMD_CAU_REG_ACCESS:
>  		r.rf = &resp->params.rf_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf-
> >offset));
> -		reg_rw->value = cpu_to_le32((u32) r.rf->value);
> +		reg_rw->offset = (u32) le16_to_cpu(r.rf->offset);
> +		reg_rw->value = (u32) r.rf->value;
>  		break;
>  	case HostCmd_CMD_802_11_EEPROM_ACCESS:
>  		r.eeprom = &resp->params.eeprom;
> -		pr_debug("info: EEPROM read len=%x\n", r.eeprom-
> >byte_count);
> -		if (le16_to_cpu(eeprom->byte_count) <
> -		    le16_to_cpu(r.eeprom->byte_count)) {
> -			eeprom->byte_count = cpu_to_le16(0);
> +		pr_debug("info: EEPROM read len=%x\n",
> +				le16_to_cpu(r.eeprom->byte_count));
> +		if (eeprom->byte_count < le16_to_cpu(r.eeprom->byte_count))
> {
> +			eeprom->byte_count = 0;
>  			pr_debug("info: EEPROM read length is too big\n");
>  			return -1;
>  		}
> -		eeprom->offset = r.eeprom->offset;
> -		eeprom->byte_count = r.eeprom->byte_count;
> -		if (le16_to_cpu(eeprom->byte_count) > 0)
> +		eeprom->offset = le16_to_cpu(r.eeprom->offset);
> +		eeprom->byte_count = le16_to_cpu(r.eeprom->byte_count);
> +		if (eeprom->byte_count > 0)
>  			memcpy(&eeprom->value, &r.eeprom->value,
> -			       le16_to_cpu(r.eeprom->byte_count));
> -
> +			       min((u16)MAX_EEPROM_DATA, eeprom->byte_count));
>  		break;
>  	default:
>  		return -1;
> diff --git a/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
> b/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
> index 8e08626..6dab5ca 100644
> --- a/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
> +++ b/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
> @@ -1247,7 +1247,7 @@ static int mwifiex_reg_mem_ioctl_reg_rw(struct
> mwifiex_private *priv,  {
>  	u16 cmd_no;
> 
> -	switch (le32_to_cpu(reg_rw->type)) {
> +	switch (reg_rw->type) {
>  	case MWIFIEX_REG_MAC:
>  		cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
>  		break;
> @@ -1282,9 +1282,9 @@ mwifiex_reg_write(struct mwifiex_private *priv,
> u32 reg_type,  {
>  	struct mwifiex_ds_reg_rw reg_rw;
> 
> -	reg_rw.type = cpu_to_le32(reg_type);
> -	reg_rw.offset = cpu_to_le32(reg_offset);
> -	reg_rw.value = cpu_to_le32(reg_value);
> +	reg_rw.type = reg_type;
> +	reg_rw.offset = reg_offset;
> +	reg_rw.value = reg_value;
> 
>  	return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw,
> HostCmd_ACT_GEN_SET);  } @@ -1302,14 +1302,14 @@ mwifiex_reg_read(struct
> mwifiex_private *priv, u32 reg_type,
>  	int ret;
>  	struct mwifiex_ds_reg_rw reg_rw;
> 
> -	reg_rw.type = cpu_to_le32(reg_type);
> -	reg_rw.offset = cpu_to_le32(reg_offset);
> +	reg_rw.type = reg_type;
> +	reg_rw.offset = reg_offset;
>  	ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw,
> HostCmd_ACT_GEN_GET);
> 
>  	if (ret)
>  		goto done;
> 
> -	*value = le32_to_cpu(reg_rw.value);
> +	*value = reg_rw.value;
> 
>  done:
>  	return ret;
> @@ -1328,15 +1328,16 @@ mwifiex_eeprom_read(struct mwifiex_private
> *priv, u16 offset, u16 bytes,
>  	int ret;
>  	struct mwifiex_ds_read_eeprom rd_eeprom;
> 
> -	rd_eeprom.offset = cpu_to_le16((u16) offset);
> -	rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
> +	rd_eeprom.offset =  offset;
> +	rd_eeprom.byte_count = bytes;
> 
>  	/* Send request to firmware */
>  	ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
>  			       HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);
> 
>  	if (!ret)
> -		memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
> +		memcpy(value, rd_eeprom.value, min((u16)MAX_EEPROM_DATA,
> +		       rd_eeprom.byte_count));
>  	return ret;
>  }
> 

I can see attached sparse compilation warnings with your patch.
Sparse info: https://www.kernel.org/doc/Documentation/sparse.txt
I suppose you need to change structure definitions as well. __le16/__le32 members should now be defined as u16/u32 to resolve the warnings. Please prepare updated version with the change.

Regards,
Amitkumar

[-- Attachment #2: sparse.txt --]
[-- Type: text/plain, Size: 12349 bytes --]

/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1250:23: warning: restricted __le32 degrades to integer
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1250:23: warning: restricted __le32 degrades to integer
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1250:23: warning: restricted __le32 degrades to integer
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1250:23: warning: restricted __le32 degrades to integer
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1250:23: warning: restricted __le32 degrades to integer
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1285:21: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1285:21:    expected restricted __le32 [usertype] type
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1285:21:    got unsigned int [unsigned] [usertype] reg_type
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1286:23: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1286:23:    expected restricted __le32 [usertype] offset
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1286:23:    got unsigned int [unsigned] [usertype] reg_offset
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1287:22: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1287:22:    expected restricted __le32 [usertype] value
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1287:22:    got unsigned int [unsigned] [usertype] reg_value
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1305:21: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1305:21:    expected restricted __le32 [usertype] type
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1305:21:    got unsigned int [unsigned] [usertype] reg_type
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1306:23: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1306:23:    expected restricted __le32 [usertype] offset
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1306:23:    got unsigned int [unsigned] [usertype] reg_offset
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1312:16: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1312:16:    expected unsigned int [unsigned] [usertype] <noident>
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1312:16:    got restricted __le32 [addressable] [usertype] value
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1331:26: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1331:26:    expected restricted __le16 [usertype] offset
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1331:26:    got unsigned short [unsigned] [usertype] offset
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1332:30: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1332:30:    expected restricted __le16 [usertype] byte_count
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1332:30:    got unsigned short [unsigned] [usertype] bytes
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c:1339:48: error: incompatible types in comparison expression (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmd.c:1133:35: warning: cast from restricted __le32
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmd.c:1134:34: warning: cast from restricted __le32
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmd.c:1144:35: warning: cast from restricted __le32
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmd.c:1145:35: warning: cast from restricted __le32
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmd.c:1155:34: warning: cast from restricted __le32
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmd.c:1156:34: warning: cast from restricted __le32
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmd.c:1166:36: warning: cast from restricted __le32
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmd.c:1167:36: warning: cast from restricted __le32
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmd.c:1177:35: warning: cast from restricted __le32
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmd.c:1178:35: warning: cast from restricted __le32
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmd.c:1189:38: warning: cast from restricted __le16
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmd.c:1190:42: warning: cast from restricted __le16
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:784:32: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:784:32:    expected restricted __le32 [usertype] offset
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:784:32:    got unsigned int [unsigned] [usertype] <noident>
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:785:31: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:785:31:    expected restricted __le32 [usertype] value
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:785:31:    got unsigned int [unsigned] [usertype] <noident>
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:789:32: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:789:32:    expected restricted __le32 [usertype] offset
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:789:32:    got unsigned int [unsigned] [usertype] <noident>
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:790:31: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:790:31:    expected restricted __le32 [usertype] value
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:790:31:    got unsigned int [unsigned] [usertype] <noident>
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:795:32: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:795:32:    expected restricted __le32 [usertype] offset
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:795:32:    got unsigned int [unsigned] [usertype] <noident>
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:796:31: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:796:31:    expected restricted __le32 [usertype] value
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:796:31:    got unsigned int [unsigned] [usertype] <noident>
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:800:32: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:800:32:    expected restricted __le32 [usertype] offset
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:800:32:    got unsigned int [unsigned] [usertype] <noident>
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:801:31: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:801:31:    expected restricted __le32 [usertype] value
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:801:31:    got unsigned int [unsigned] [usertype] <noident>
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:805:32: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:805:32:    expected restricted __le32 [usertype] offset
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:805:32:    got unsigned int [unsigned] [usertype] <noident>
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:806:31: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:806:31:    expected restricted __le32 [usertype] value
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:806:31:    got unsigned int [unsigned] [usertype] <noident>
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:812:27: warning: restricted __le16 degrades to integer
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:817:32: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:817:32:    expected restricted __le16 [usertype] offset
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:817:32:    got unsigned short [unsigned] [usertype] <noident>
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:818:36: warning: incorrect type in assignment (different base types)
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:818:36:    expected restricted __le16 [usertype] byte_count
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:818:36:    got unsigned short [unsigned] [usertype] <noident>
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:819:27: warning: restricted __le16 degrades to integer
/home/amit/git.mwifiex-devel/mwifiex-devel/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c:821:32: error: incompatible types in comparison expression (different base types)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v4] mwifiex: Reduce endian conversion for REG Host Commands
  2016-06-27  7:02 ` Amitkumar Karwar
@ 2016-06-27 10:13   ` Prasun Maiti
  2016-07-08 11:02     ` Amitkumar Karwar
                       ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Prasun Maiti @ 2016-06-27 10:13 UTC (permalink / raw)
  To: Amitkumar Karwar
  Cc: Nishant Sarmukadam, Linux Wireless, Linux Next, Linux Kernel, Kalle Valo

For multiple REG Host Commands (e.g HostCmd_CMD_802_11_EEPROM_ACCESS,
HostCmd_CMD_MAC_REG_ACCESS etc.) "cpu_to_leX"-converted values are
saved to driver. So, "leX_to_cpu" conversion is required too many
times afterwards in driver.

This patch reduces the endian: conversion without saving "cpu_to_leX"
converted values in driver. This will convert endianness in prepare
command and command response path.

Signed-off-by: Prasun Maiti <prasunmaiti87@gmail.com>
---
Changes in v3:
	- Fixed the following warnings:
	* sta_ioctl.c:1339:34: warning: comparison of distinct pointer types lacks a cast [enabled by default]
	* sta_cmdresp.c:821:6: warning: comparison of distinct pointer types lacks a cast [enabled by default]

Changes in v4:
	- Fixed the sparse compilation warnings:
	* warning: cast from restricted __le32
	* warning: cast from restricted __le16

 drivers/net/wireless/marvell/mwifiex/ioctl.h       | 10 +++---
 drivers/net/wireless/marvell/mwifiex/sta_cmd.c     | 28 +++++++---------
 drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c | 37 +++++++++++-----------
 drivers/net/wireless/marvell/mwifiex/sta_ioctl.c   | 21 ++++++------
 4 files changed, 46 insertions(+), 50 deletions(-)

diff --git a/drivers/net/wireless/marvell/mwifiex/ioctl.h b/drivers/net/wireless/marvell/mwifiex/ioctl.h
index a5a48c1..4ce9330 100644
--- a/drivers/net/wireless/marvell/mwifiex/ioctl.h
+++ b/drivers/net/wireless/marvell/mwifiex/ioctl.h
@@ -341,16 +341,16 @@ enum {
 };

 struct mwifiex_ds_reg_rw {
-	__le32 type;
-	__le32 offset;
-	__le32 value;
+	u32 type;
+	u32 offset;
+	u32 value;
 };

 #define MAX_EEPROM_DATA 256

 struct mwifiex_ds_read_eeprom {
-	__le16 offset;
-	__le16 byte_count;
+	u16 offset;
+	u16 byte_count;
 	u8 value[MAX_EEPROM_DATA];
 };

diff --git a/drivers/net/wireless/marvell/mwifiex/sta_cmd.c b/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
index e436574..9df02ba 100644
--- a/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
+++ b/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
@@ -1130,9 +1130,8 @@ static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
 		cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
 		mac_reg = &cmd->params.mac_reg;
 		mac_reg->action = cpu_to_le16(cmd_action);
-		mac_reg->offset =
-			cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
-		mac_reg->value = reg_rw->value;
+		mac_reg->offset = cpu_to_le16((u16) reg_rw->offset);
+		mac_reg->value = cpu_to_le32(reg_rw->value);
 		break;
 	}
 	case HostCmd_CMD_BBP_REG_ACCESS:
@@ -1142,9 +1141,8 @@ static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
 		cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
 		bbp_reg = &cmd->params.bbp_reg;
 		bbp_reg->action = cpu_to_le16(cmd_action);
-		bbp_reg->offset =
-			cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
-		bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
+		bbp_reg->offset = cpu_to_le16((u16) reg_rw->offset);
+		bbp_reg->value = (u8) reg_rw->value;
 		break;
 	}
 	case HostCmd_CMD_RF_REG_ACCESS:
@@ -1154,8 +1152,8 @@ static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
 		cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
 		rf_reg = &cmd->params.rf_reg;
 		rf_reg->action = cpu_to_le16(cmd_action);
-		rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
-		rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
+		rf_reg->offset = cpu_to_le16((u16) reg_rw->offset);
+		rf_reg->value = (u8) reg_rw->value;
 		break;
 	}
 	case HostCmd_CMD_PMIC_REG_ACCESS:
@@ -1165,9 +1163,8 @@ static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
 		cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
 		pmic_reg = &cmd->params.pmic_reg;
 		pmic_reg->action = cpu_to_le16(cmd_action);
-		pmic_reg->offset =
-				cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
-		pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
+		pmic_reg->offset = cpu_to_le16((u16) reg_rw->offset);
+		pmic_reg->value = (u8) reg_rw->value;
 		break;
 	}
 	case HostCmd_CMD_CAU_REG_ACCESS:
@@ -1177,9 +1174,8 @@ static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
 		cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
 		cau_reg = &cmd->params.rf_reg;
 		cau_reg->action = cpu_to_le16(cmd_action);
-		cau_reg->offset =
-				cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
-		cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
+		cau_reg->offset = cpu_to_le16((u16) reg_rw->offset);
+		cau_reg->value = (u8) reg_rw->value;
 		break;
 	}
 	case HostCmd_CMD_802_11_EEPROM_ACCESS:
@@ -1190,8 +1186,8 @@ static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,

 		cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
 		cmd_eeprom->action = cpu_to_le16(cmd_action);
-		cmd_eeprom->offset = rd_eeprom->offset;
-		cmd_eeprom->byte_count = rd_eeprom->byte_count;
+		cmd_eeprom->offset = cpu_to_le16(rd_eeprom->offset);
+		cmd_eeprom->byte_count = cpu_to_le16(rd_eeprom->byte_count);
 		cmd_eeprom->value = 0;
 		break;
 	}
diff --git a/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c b/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
index d18c797..1832511 100644
--- a/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
+++ b/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
@@ -781,45 +781,44 @@ static int mwifiex_ret_reg_access(u16 type, struct host_cmd_ds_command *resp,
 	switch (type) {
 	case HostCmd_CMD_MAC_REG_ACCESS:
 		r.mac = &resp->params.mac_reg;
-		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.mac->offset));
-		reg_rw->value = r.mac->value;
+		reg_rw->offset = (u32) le16_to_cpu(r.mac->offset);
+		reg_rw->value = le32_to_cpu(r.mac->value);
 		break;
 	case HostCmd_CMD_BBP_REG_ACCESS:
 		r.bbp = &resp->params.bbp_reg;
-		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.bbp->offset));
-		reg_rw->value = cpu_to_le32((u32) r.bbp->value);
+		reg_rw->offset = (u32) le16_to_cpu(r.bbp->offset);
+		reg_rw->value = (u32) r.bbp->value;
 		break;

 	case HostCmd_CMD_RF_REG_ACCESS:
 		r.rf = &resp->params.rf_reg;
-		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
-		reg_rw->value = cpu_to_le32((u32) r.bbp->value);
+		reg_rw->offset = (u32) le16_to_cpu(r.rf->offset);
+		reg_rw->value = (u32) r.bbp->value;
 		break;
 	case HostCmd_CMD_PMIC_REG_ACCESS:
 		r.pmic = &resp->params.pmic_reg;
-		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.pmic->offset));
-		reg_rw->value = cpu_to_le32((u32) r.pmic->value);
+		reg_rw->offset = (u32) le16_to_cpu(r.pmic->offset);
+		reg_rw->value = (u32) r.pmic->value;
 		break;
 	case HostCmd_CMD_CAU_REG_ACCESS:
 		r.rf = &resp->params.rf_reg;
-		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
-		reg_rw->value = cpu_to_le32((u32) r.rf->value);
+		reg_rw->offset = (u32) le16_to_cpu(r.rf->offset);
+		reg_rw->value = (u32) r.rf->value;
 		break;
 	case HostCmd_CMD_802_11_EEPROM_ACCESS:
 		r.eeprom = &resp->params.eeprom;
-		pr_debug("info: EEPROM read len=%x\n", r.eeprom->byte_count);
-		if (le16_to_cpu(eeprom->byte_count) <
-		    le16_to_cpu(r.eeprom->byte_count)) {
-			eeprom->byte_count = cpu_to_le16(0);
+		pr_debug("info: EEPROM read len=%x\n",
+				le16_to_cpu(r.eeprom->byte_count));
+		if (eeprom->byte_count < le16_to_cpu(r.eeprom->byte_count)) {
+			eeprom->byte_count = 0;
 			pr_debug("info: EEPROM read length is too big\n");
 			return -1;
 		}
-		eeprom->offset = r.eeprom->offset;
-		eeprom->byte_count = r.eeprom->byte_count;
-		if (le16_to_cpu(eeprom->byte_count) > 0)
+		eeprom->offset = le16_to_cpu(r.eeprom->offset);
+		eeprom->byte_count = le16_to_cpu(r.eeprom->byte_count);
+		if (eeprom->byte_count > 0)
 			memcpy(&eeprom->value, &r.eeprom->value,
-			       le16_to_cpu(r.eeprom->byte_count));
-
+			       min((u16)MAX_EEPROM_DATA, eeprom->byte_count));
 		break;
 	default:
 		return -1;
diff --git a/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c b/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
index 8e08626..6dab5ca 100644
--- a/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
+++ b/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
@@ -1247,7 +1247,7 @@ static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
 {
 	u16 cmd_no;

-	switch (le32_to_cpu(reg_rw->type)) {
+	switch (reg_rw->type) {
 	case MWIFIEX_REG_MAC:
 		cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
 		break;
@@ -1282,9 +1282,9 @@ mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
 {
 	struct mwifiex_ds_reg_rw reg_rw;

-	reg_rw.type = cpu_to_le32(reg_type);
-	reg_rw.offset = cpu_to_le32(reg_offset);
-	reg_rw.value = cpu_to_le32(reg_value);
+	reg_rw.type = reg_type;
+	reg_rw.offset = reg_offset;
+	reg_rw.value = reg_value;

 	return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
 }
@@ -1302,14 +1302,14 @@ mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
 	int ret;
 	struct mwifiex_ds_reg_rw reg_rw;

-	reg_rw.type = cpu_to_le32(reg_type);
-	reg_rw.offset = cpu_to_le32(reg_offset);
+	reg_rw.type = reg_type;
+	reg_rw.offset = reg_offset;
 	ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);

 	if (ret)
 		goto done;

-	*value = le32_to_cpu(reg_rw.value);
+	*value = reg_rw.value;

 done:
 	return ret;
@@ -1328,15 +1328,16 @@ mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
 	int ret;
 	struct mwifiex_ds_read_eeprom rd_eeprom;

-	rd_eeprom.offset = cpu_to_le16((u16) offset);
-	rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
+	rd_eeprom.offset =  offset;
+	rd_eeprom.byte_count = bytes;

 	/* Send request to firmware */
 	ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
 			       HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);

 	if (!ret)
-		memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
+		memcpy(value, rd_eeprom.value, min((u16)MAX_EEPROM_DATA,
+		       rd_eeprom.byte_count));
 	return ret;
 }

--
1.9.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* RE: [PATCH v4] mwifiex: Reduce endian conversion for REG Host Commands
  2016-06-27 10:13   ` [PATCH v4] " Prasun Maiti
@ 2016-07-08 11:02     ` Amitkumar Karwar
  2016-07-08 13:40       ` Kalle Valo
  2016-07-08 14:33     ` Amitkumar Karwar
  2016-07-18 19:33     ` [v4] " Kalle Valo
  2 siblings, 1 reply; 8+ messages in thread
From: Amitkumar Karwar @ 2016-07-08 11:02 UTC (permalink / raw)
  To: Prasun Maiti
  Cc: Nishant Sarmukadam, Linux Wireless, Linux Next, Linux Kernel, Kalle Valo

Hi Kalle,

> From: Prasun Maiti [mailto:prasunmaiti87@gmail.com]
> Sent: Monday, June 27, 2016 3:43 PM
> To: Amitkumar Karwar
> Cc: Nishant Sarmukadam; Linux Wireless; Linux Next; Linux Kernel; Kalle
> Valo
> Subject: [PATCH v4] mwifiex: Reduce endian conversion for REG Host
> Commands
> 
> For multiple REG Host Commands (e.g HostCmd_CMD_802_11_EEPROM_ACCESS,
> HostCmd_CMD_MAC_REG_ACCESS etc.) "cpu_to_leX"-converted values are saved
> to driver. So, "leX_to_cpu" conversion is required too many times
> afterwards in driver.
> 
> This patch reduces the endian: conversion without saving "cpu_to_leX"
> converted values in driver. This will convert endianness in prepare
> command and command response path.
> 
> Signed-off-by: Prasun Maiti <prasunmaiti87@gmail.com>
> ---
> Changes in v3:
> 	- Fixed the following warnings:
> 	* sta_ioctl.c:1339:34: warning: comparison of distinct pointer
> types lacks a cast [enabled by default]
> 	* sta_cmdresp.c:821:6: warning: comparison of distinct pointer
> types lacks a cast [enabled by default]
> 
> Changes in v4:
> 	- Fixed the sparse compilation warnings:
> 	* warning: cast from restricted __le32
> 	* warning: cast from restricted __le16
> 
>  drivers/net/wireless/marvell/mwifiex/ioctl.h       | 10 +++---
>  drivers/net/wireless/marvell/mwifiex/sta_cmd.c     | 28 +++++++--------
> -
>  drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c | 37 +++++++++++----
> -------
>  drivers/net/wireless/marvell/mwifiex/sta_ioctl.c   | 21 ++++++------
>  4 files changed, 46 insertions(+), 50 deletions(-)
> 
> diff --git a/drivers/net/wireless/marvell/mwifiex/ioctl.h
> b/drivers/net/wireless/marvell/mwifiex/ioctl.h
> index a5a48c1..4ce9330 100644
> --- a/drivers/net/wireless/marvell/mwifiex/ioctl.h
> +++ b/drivers/net/wireless/marvell/mwifiex/ioctl.h
> @@ -341,16 +341,16 @@ enum {
>  };
> 
>  struct mwifiex_ds_reg_rw {
> -	__le32 type;
> -	__le32 offset;
> -	__le32 value;
> +	u32 type;
> +	u32 offset;
> +	u32 value;
>  };
> 
>  #define MAX_EEPROM_DATA 256
> 
>  struct mwifiex_ds_read_eeprom {
> -	__le16 offset;
> -	__le16 byte_count;
> +	u16 offset;
> +	u16 byte_count;
>  	u8 value[MAX_EEPROM_DATA];
>  };
> 
> diff --git a/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
> b/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
> index e436574..9df02ba 100644
> --- a/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
> +++ b/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
> @@ -1130,9 +1130,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
>  		mac_reg = &cmd->params.mac_reg;
>  		mac_reg->action = cpu_to_le16(cmd_action);
> -		mac_reg->offset =
> -			cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
> -		mac_reg->value = reg_rw->value;
> +		mac_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		mac_reg->value = cpu_to_le32(reg_rw->value);
>  		break;
>  	}
>  	case HostCmd_CMD_BBP_REG_ACCESS:
> @@ -1142,9 +1141,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
>  		bbp_reg = &cmd->params.bbp_reg;
>  		bbp_reg->action = cpu_to_le16(cmd_action);
> -		bbp_reg->offset =
> -			cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
> -		bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
> +		bbp_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		bbp_reg->value = (u8) reg_rw->value;
>  		break;
>  	}
>  	case HostCmd_CMD_RF_REG_ACCESS:
> @@ -1154,8 +1152,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
>  		rf_reg = &cmd->params.rf_reg;
>  		rf_reg->action = cpu_to_le16(cmd_action);
> -		rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw-
> >offset));
> -		rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
> +		rf_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		rf_reg->value = (u8) reg_rw->value;
>  		break;
>  	}
>  	case HostCmd_CMD_PMIC_REG_ACCESS:
> @@ -1165,9 +1163,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
>  		pmic_reg = &cmd->params.pmic_reg;
>  		pmic_reg->action = cpu_to_le16(cmd_action);
> -		pmic_reg->offset =
> -				cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
> -		pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
> +		pmic_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		pmic_reg->value = (u8) reg_rw->value;
>  		break;
>  	}
>  	case HostCmd_CMD_CAU_REG_ACCESS:
> @@ -1177,9 +1174,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
>  		cau_reg = &cmd->params.rf_reg;
>  		cau_reg->action = cpu_to_le16(cmd_action);
> -		cau_reg->offset =
> -				cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
> -		cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
> +		cau_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		cau_reg->value = (u8) reg_rw->value;
>  		break;
>  	}
>  	case HostCmd_CMD_802_11_EEPROM_ACCESS:
> @@ -1190,8 +1186,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
> 
>  		cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
>  		cmd_eeprom->action = cpu_to_le16(cmd_action);
> -		cmd_eeprom->offset = rd_eeprom->offset;
> -		cmd_eeprom->byte_count = rd_eeprom->byte_count;
> +		cmd_eeprom->offset = cpu_to_le16(rd_eeprom->offset);
> +		cmd_eeprom->byte_count = cpu_to_le16(rd_eeprom->byte_count);
>  		cmd_eeprom->value = 0;
>  		break;
>  	}
> diff --git a/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
> b/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
> index d18c797..1832511 100644
> --- a/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
> +++ b/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
> @@ -781,45 +781,44 @@ static int mwifiex_ret_reg_access(u16 type, struct
> host_cmd_ds_command *resp,
>  	switch (type) {
>  	case HostCmd_CMD_MAC_REG_ACCESS:
>  		r.mac = &resp->params.mac_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.mac-
> >offset));
> -		reg_rw->value = r.mac->value;
> +		reg_rw->offset = (u32) le16_to_cpu(r.mac->offset);
> +		reg_rw->value = le32_to_cpu(r.mac->value);
>  		break;
>  	case HostCmd_CMD_BBP_REG_ACCESS:
>  		r.bbp = &resp->params.bbp_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.bbp-
> >offset));
> -		reg_rw->value = cpu_to_le32((u32) r.bbp->value);
> +		reg_rw->offset = (u32) le16_to_cpu(r.bbp->offset);
> +		reg_rw->value = (u32) r.bbp->value;
>  		break;
> 
>  	case HostCmd_CMD_RF_REG_ACCESS:
>  		r.rf = &resp->params.rf_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf-
> >offset));
> -		reg_rw->value = cpu_to_le32((u32) r.bbp->value);
> +		reg_rw->offset = (u32) le16_to_cpu(r.rf->offset);
> +		reg_rw->value = (u32) r.bbp->value;
>  		break;
>  	case HostCmd_CMD_PMIC_REG_ACCESS:
>  		r.pmic = &resp->params.pmic_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.pmic-
> >offset));
> -		reg_rw->value = cpu_to_le32((u32) r.pmic->value);
> +		reg_rw->offset = (u32) le16_to_cpu(r.pmic->offset);
> +		reg_rw->value = (u32) r.pmic->value;
>  		break;
>  	case HostCmd_CMD_CAU_REG_ACCESS:
>  		r.rf = &resp->params.rf_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf-
> >offset));
> -		reg_rw->value = cpu_to_le32((u32) r.rf->value);
> +		reg_rw->offset = (u32) le16_to_cpu(r.rf->offset);
> +		reg_rw->value = (u32) r.rf->value;
>  		break;
>  	case HostCmd_CMD_802_11_EEPROM_ACCESS:
>  		r.eeprom = &resp->params.eeprom;
> -		pr_debug("info: EEPROM read len=%x\n", r.eeprom-
> >byte_count);
> -		if (le16_to_cpu(eeprom->byte_count) <
> -		    le16_to_cpu(r.eeprom->byte_count)) {
> -			eeprom->byte_count = cpu_to_le16(0);
> +		pr_debug("info: EEPROM read len=%x\n",
> +				le16_to_cpu(r.eeprom->byte_count));
> +		if (eeprom->byte_count < le16_to_cpu(r.eeprom->byte_count))
> {
> +			eeprom->byte_count = 0;
>  			pr_debug("info: EEPROM read length is too big\n");
>  			return -1;
>  		}
> -		eeprom->offset = r.eeprom->offset;
> -		eeprom->byte_count = r.eeprom->byte_count;
> -		if (le16_to_cpu(eeprom->byte_count) > 0)
> +		eeprom->offset = le16_to_cpu(r.eeprom->offset);
> +		eeprom->byte_count = le16_to_cpu(r.eeprom->byte_count);
> +		if (eeprom->byte_count > 0)
>  			memcpy(&eeprom->value, &r.eeprom->value,
> -			       le16_to_cpu(r.eeprom->byte_count));
> -
> +			       min((u16)MAX_EEPROM_DATA, eeprom->byte_count));
>  		break;
>  	default:
>  		return -1;
> diff --git a/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
> b/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
> index 8e08626..6dab5ca 100644
> --- a/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
> +++ b/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
> @@ -1247,7 +1247,7 @@ static int mwifiex_reg_mem_ioctl_reg_rw(struct
> mwifiex_private *priv,  {
>  	u16 cmd_no;
> 
> -	switch (le32_to_cpu(reg_rw->type)) {
> +	switch (reg_rw->type) {
>  	case MWIFIEX_REG_MAC:
>  		cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
>  		break;
> @@ -1282,9 +1282,9 @@ mwifiex_reg_write(struct mwifiex_private *priv,
> u32 reg_type,  {
>  	struct mwifiex_ds_reg_rw reg_rw;
> 
> -	reg_rw.type = cpu_to_le32(reg_type);
> -	reg_rw.offset = cpu_to_le32(reg_offset);
> -	reg_rw.value = cpu_to_le32(reg_value);
> +	reg_rw.type = reg_type;
> +	reg_rw.offset = reg_offset;
> +	reg_rw.value = reg_value;
> 
>  	return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw,
> HostCmd_ACT_GEN_SET);  } @@ -1302,14 +1302,14 @@ mwifiex_reg_read(struct
> mwifiex_private *priv, u32 reg_type,
>  	int ret;
>  	struct mwifiex_ds_reg_rw reg_rw;
> 
> -	reg_rw.type = cpu_to_le32(reg_type);
> -	reg_rw.offset = cpu_to_le32(reg_offset);
> +	reg_rw.type = reg_type;
> +	reg_rw.offset = reg_offset;
>  	ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw,
> HostCmd_ACT_GEN_GET);
> 
>  	if (ret)
>  		goto done;
> 
> -	*value = le32_to_cpu(reg_rw.value);
> +	*value = reg_rw.value;
> 
>  done:
>  	return ret;
> @@ -1328,15 +1328,16 @@ mwifiex_eeprom_read(struct mwifiex_private
> *priv, u16 offset, u16 bytes,
>  	int ret;
>  	struct mwifiex_ds_read_eeprom rd_eeprom;
> 
> -	rd_eeprom.offset = cpu_to_le16((u16) offset);
> -	rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
> +	rd_eeprom.offset =  offset;
> +	rd_eeprom.byte_count = bytes;
> 
>  	/* Send request to firmware */
>  	ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
>  			       HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);
> 
>  	if (!ret)
> -		memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
> +		memcpy(value, rd_eeprom.value, min((u16)MAX_EEPROM_DATA,
> +		       rd_eeprom.byte_count));
>  	return ret;
>  }

Any specific reason for dropping this patch?
I can see the status as "Deferred" on patchwork.

Regards,
Amitkumar

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4] mwifiex: Reduce endian conversion for REG Host Commands
  2016-07-08 11:02     ` Amitkumar Karwar
@ 2016-07-08 13:40       ` Kalle Valo
  2016-07-08 14:32         ` Amitkumar Karwar
  0 siblings, 1 reply; 8+ messages in thread
From: Kalle Valo @ 2016-07-08 13:40 UTC (permalink / raw)
  To: Amitkumar Karwar
  Cc: Prasun Maiti, Nishant Sarmukadam, Linux Wireless, Linux Next,
	Linux Kernel

Amitkumar Karwar <akarwar@marvell.com> writes:

>> From: Prasun Maiti [mailto:prasunmaiti87@gmail.com]
>> Sent: Monday, June 27, 2016 3:43 PM
>> To: Amitkumar Karwar
>> Cc: Nishant Sarmukadam; Linux Wireless; Linux Next; Linux Kernel; Kalle
>> Valo
>> Subject: [PATCH v4] mwifiex: Reduce endian conversion for REG Host
>> Commands
>> 
>> For multiple REG Host Commands (e.g HostCmd_CMD_802_11_EEPROM_ACCESS,
>> HostCmd_CMD_MAC_REG_ACCESS etc.) "cpu_to_leX"-converted values are saved
>> to driver. So, "leX_to_cpu" conversion is required too many times
>> afterwards in driver.
>> 
>> This patch reduces the endian: conversion without saving "cpu_to_leX"
>> converted values in driver. This will convert endianness in prepare
>> command and command response path.
>> 
>> Signed-off-by: Prasun Maiti <prasunmaiti87@gmail.com>

[deleted almost 300 lines of unnecessary quotes]

> Any specific reason for dropping this patch?
> I can see the status as "Deferred" on patchwork.

It's not dropped, "Deferred" means that the patch was postponed for some
reason and I need to look at the patch more carefully. In this case I
did it because I was hoping to see an Acked-by from you.

-- 
Kalle Valo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH v4] mwifiex: Reduce endian conversion for REG Host Commands
  2016-07-08 13:40       ` Kalle Valo
@ 2016-07-08 14:32         ` Amitkumar Karwar
  0 siblings, 0 replies; 8+ messages in thread
From: Amitkumar Karwar @ 2016-07-08 14:32 UTC (permalink / raw)
  To: Kalle Valo
  Cc: Prasun Maiti, Nishant Sarmukadam, Linux Wireless, Linux Next,
	Linux Kernel

> From: linux-wireless-owner@vger.kernel.org [mailto:linux-wireless-
> owner@vger.kernel.org] On Behalf Of Kalle Valo
> Sent: Friday, July 08, 2016 7:10 PM
> To: Amitkumar Karwar
> Cc: Prasun Maiti; Nishant Sarmukadam; Linux Wireless; Linux Next; Linux
> Kernel
> Subject: Re: [PATCH v4] mwifiex: Reduce endian conversion for REG Host
> Commands
> 
> Amitkumar Karwar <akarwar@marvell.com> writes:
> 
> >> From: Prasun Maiti [mailto:prasunmaiti87@gmail.com]
> >> Sent: Monday, June 27, 2016 3:43 PM
> >> To: Amitkumar Karwar
> >> Cc: Nishant Sarmukadam; Linux Wireless; Linux Next; Linux Kernel;
> >> Kalle Valo
> >> Subject: [PATCH v4] mwifiex: Reduce endian conversion for REG Host
> >> Commands
> >>
> >> For multiple REG Host Commands (e.g HostCmd_CMD_802_11_EEPROM_ACCESS,
> >> HostCmd_CMD_MAC_REG_ACCESS etc.) "cpu_to_leX"-converted values are
> >> saved to driver. So, "leX_to_cpu" conversion is required too many
> >> times afterwards in driver.
> >>
> >> This patch reduces the endian: conversion without saving "cpu_to_leX"
> >> converted values in driver. This will convert endianness in prepare
> >> command and command response path.
> >>
> >> Signed-off-by: Prasun Maiti <prasunmaiti87@gmail.com>
> 
> [deleted almost 300 lines of unnecessary quotes]
> 
> > Any specific reason for dropping this patch?
> > I can see the status as "Deferred" on patchwork.
> 
> It's not dropped, "Deferred" means that the patch was postponed for some
> reason and I need to look at the patch more carefully. In this case I
> did it because I was hoping to see an Acked-by from you.

Thanks for clarification. I will ack the patch.

Regards,
Amitkumar

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH v4] mwifiex: Reduce endian conversion for REG Host Commands
  2016-06-27 10:13   ` [PATCH v4] " Prasun Maiti
  2016-07-08 11:02     ` Amitkumar Karwar
@ 2016-07-08 14:33     ` Amitkumar Karwar
  2016-07-18 19:33     ` [v4] " Kalle Valo
  2 siblings, 0 replies; 8+ messages in thread
From: Amitkumar Karwar @ 2016-07-08 14:33 UTC (permalink / raw)
  To: Prasun Maiti
  Cc: Nishant Sarmukadam, Linux Wireless, Linux Next, Linux Kernel, Kalle Valo

> From: Prasun Maiti [mailto:prasunmaiti87@gmail.com]
> Sent: Monday, June 27, 2016 3:43 PM
> To: Amitkumar Karwar
> Cc: Nishant Sarmukadam; Linux Wireless; Linux Next; Linux Kernel; Kalle
> Valo
> Subject: [PATCH v4] mwifiex: Reduce endian conversion for REG Host
> Commands
> 
> For multiple REG Host Commands (e.g HostCmd_CMD_802_11_EEPROM_ACCESS,
> HostCmd_CMD_MAC_REG_ACCESS etc.) "cpu_to_leX"-converted values are saved
> to driver. So, "leX_to_cpu" conversion is required too many times
> afterwards in driver.
> 
> This patch reduces the endian: conversion without saving "cpu_to_leX"
> converted values in driver. This will convert endianness in prepare
> command and command response path.
> 
> Signed-off-by: Prasun Maiti <prasunmaiti87@gmail.com>
> ---
> Changes in v3:
> 	- Fixed the following warnings:
> 	* sta_ioctl.c:1339:34: warning: comparison of distinct pointer
> types lacks a cast [enabled by default]
> 	* sta_cmdresp.c:821:6: warning: comparison of distinct pointer
> types lacks a cast [enabled by default]
> 
> Changes in v4:
> 	- Fixed the sparse compilation warnings:
> 	* warning: cast from restricted __le32
> 	* warning: cast from restricted __le16
> 
>  drivers/net/wireless/marvell/mwifiex/ioctl.h       | 10 +++---
>  drivers/net/wireless/marvell/mwifiex/sta_cmd.c     | 28 +++++++--------
> -
>  drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c | 37 +++++++++++----
> -------
>  drivers/net/wireless/marvell/mwifiex/sta_ioctl.c   | 21 ++++++------
>  4 files changed, 46 insertions(+), 50 deletions(-)
> 
> diff --git a/drivers/net/wireless/marvell/mwifiex/ioctl.h
> b/drivers/net/wireless/marvell/mwifiex/ioctl.h
> index a5a48c1..4ce9330 100644
> --- a/drivers/net/wireless/marvell/mwifiex/ioctl.h
> +++ b/drivers/net/wireless/marvell/mwifiex/ioctl.h
> @@ -341,16 +341,16 @@ enum {
>  };
> 
>  struct mwifiex_ds_reg_rw {
> -	__le32 type;
> -	__le32 offset;
> -	__le32 value;
> +	u32 type;
> +	u32 offset;
> +	u32 value;
>  };
> 
>  #define MAX_EEPROM_DATA 256
> 
>  struct mwifiex_ds_read_eeprom {
> -	__le16 offset;
> -	__le16 byte_count;
> +	u16 offset;
> +	u16 byte_count;
>  	u8 value[MAX_EEPROM_DATA];
>  };
> 
> diff --git a/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
> b/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
> index e436574..9df02ba 100644
> --- a/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
> +++ b/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
> @@ -1130,9 +1130,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
>  		mac_reg = &cmd->params.mac_reg;
>  		mac_reg->action = cpu_to_le16(cmd_action);
> -		mac_reg->offset =
> -			cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
> -		mac_reg->value = reg_rw->value;
> +		mac_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		mac_reg->value = cpu_to_le32(reg_rw->value);
>  		break;
>  	}
>  	case HostCmd_CMD_BBP_REG_ACCESS:
> @@ -1142,9 +1141,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
>  		bbp_reg = &cmd->params.bbp_reg;
>  		bbp_reg->action = cpu_to_le16(cmd_action);
> -		bbp_reg->offset =
> -			cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
> -		bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
> +		bbp_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		bbp_reg->value = (u8) reg_rw->value;
>  		break;
>  	}
>  	case HostCmd_CMD_RF_REG_ACCESS:
> @@ -1154,8 +1152,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
>  		rf_reg = &cmd->params.rf_reg;
>  		rf_reg->action = cpu_to_le16(cmd_action);
> -		rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw-
> >offset));
> -		rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
> +		rf_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		rf_reg->value = (u8) reg_rw->value;
>  		break;
>  	}
>  	case HostCmd_CMD_PMIC_REG_ACCESS:
> @@ -1165,9 +1163,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
>  		pmic_reg = &cmd->params.pmic_reg;
>  		pmic_reg->action = cpu_to_le16(cmd_action);
> -		pmic_reg->offset =
> -				cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
> -		pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
> +		pmic_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		pmic_reg->value = (u8) reg_rw->value;
>  		break;
>  	}
>  	case HostCmd_CMD_CAU_REG_ACCESS:
> @@ -1177,9 +1174,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
>  		cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
>  		cau_reg = &cmd->params.rf_reg;
>  		cau_reg->action = cpu_to_le16(cmd_action);
> -		cau_reg->offset =
> -				cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
> -		cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
> +		cau_reg->offset = cpu_to_le16((u16) reg_rw->offset);
> +		cau_reg->value = (u8) reg_rw->value;
>  		break;
>  	}
>  	case HostCmd_CMD_802_11_EEPROM_ACCESS:
> @@ -1190,8 +1186,8 @@ static int mwifiex_cmd_reg_access(struct
> host_cmd_ds_command *cmd,
> 
>  		cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
>  		cmd_eeprom->action = cpu_to_le16(cmd_action);
> -		cmd_eeprom->offset = rd_eeprom->offset;
> -		cmd_eeprom->byte_count = rd_eeprom->byte_count;
> +		cmd_eeprom->offset = cpu_to_le16(rd_eeprom->offset);
> +		cmd_eeprom->byte_count = cpu_to_le16(rd_eeprom->byte_count);
>  		cmd_eeprom->value = 0;
>  		break;
>  	}
> diff --git a/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
> b/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
> index d18c797..1832511 100644
> --- a/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
> +++ b/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
> @@ -781,45 +781,44 @@ static int mwifiex_ret_reg_access(u16 type, struct
> host_cmd_ds_command *resp,
>  	switch (type) {
>  	case HostCmd_CMD_MAC_REG_ACCESS:
>  		r.mac = &resp->params.mac_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.mac-
> >offset));
> -		reg_rw->value = r.mac->value;
> +		reg_rw->offset = (u32) le16_to_cpu(r.mac->offset);
> +		reg_rw->value = le32_to_cpu(r.mac->value);
>  		break;
>  	case HostCmd_CMD_BBP_REG_ACCESS:
>  		r.bbp = &resp->params.bbp_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.bbp-
> >offset));
> -		reg_rw->value = cpu_to_le32((u32) r.bbp->value);
> +		reg_rw->offset = (u32) le16_to_cpu(r.bbp->offset);
> +		reg_rw->value = (u32) r.bbp->value;
>  		break;
> 
>  	case HostCmd_CMD_RF_REG_ACCESS:
>  		r.rf = &resp->params.rf_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf-
> >offset));
> -		reg_rw->value = cpu_to_le32((u32) r.bbp->value);
> +		reg_rw->offset = (u32) le16_to_cpu(r.rf->offset);
> +		reg_rw->value = (u32) r.bbp->value;
>  		break;
>  	case HostCmd_CMD_PMIC_REG_ACCESS:
>  		r.pmic = &resp->params.pmic_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.pmic-
> >offset));
> -		reg_rw->value = cpu_to_le32((u32) r.pmic->value);
> +		reg_rw->offset = (u32) le16_to_cpu(r.pmic->offset);
> +		reg_rw->value = (u32) r.pmic->value;
>  		break;
>  	case HostCmd_CMD_CAU_REG_ACCESS:
>  		r.rf = &resp->params.rf_reg;
> -		reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf-
> >offset));
> -		reg_rw->value = cpu_to_le32((u32) r.rf->value);
> +		reg_rw->offset = (u32) le16_to_cpu(r.rf->offset);
> +		reg_rw->value = (u32) r.rf->value;
>  		break;
>  	case HostCmd_CMD_802_11_EEPROM_ACCESS:
>  		r.eeprom = &resp->params.eeprom;
> -		pr_debug("info: EEPROM read len=%x\n", r.eeprom-
> >byte_count);
> -		if (le16_to_cpu(eeprom->byte_count) <
> -		    le16_to_cpu(r.eeprom->byte_count)) {
> -			eeprom->byte_count = cpu_to_le16(0);
> +		pr_debug("info: EEPROM read len=%x\n",
> +				le16_to_cpu(r.eeprom->byte_count));
> +		if (eeprom->byte_count < le16_to_cpu(r.eeprom->byte_count))
> {
> +			eeprom->byte_count = 0;
>  			pr_debug("info: EEPROM read length is too big\n");
>  			return -1;
>  		}
> -		eeprom->offset = r.eeprom->offset;
> -		eeprom->byte_count = r.eeprom->byte_count;
> -		if (le16_to_cpu(eeprom->byte_count) > 0)
> +		eeprom->offset = le16_to_cpu(r.eeprom->offset);
> +		eeprom->byte_count = le16_to_cpu(r.eeprom->byte_count);
> +		if (eeprom->byte_count > 0)
>  			memcpy(&eeprom->value, &r.eeprom->value,
> -			       le16_to_cpu(r.eeprom->byte_count));
> -
> +			       min((u16)MAX_EEPROM_DATA, eeprom->byte_count));
>  		break;
>  	default:
>  		return -1;
> diff --git a/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
> b/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
> index 8e08626..6dab5ca 100644
> --- a/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
> +++ b/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
> @@ -1247,7 +1247,7 @@ static int mwifiex_reg_mem_ioctl_reg_rw(struct
> mwifiex_private *priv,  {
>  	u16 cmd_no;
> 
> -	switch (le32_to_cpu(reg_rw->type)) {
> +	switch (reg_rw->type) {
>  	case MWIFIEX_REG_MAC:
>  		cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
>  		break;
> @@ -1282,9 +1282,9 @@ mwifiex_reg_write(struct mwifiex_private *priv,
> u32 reg_type,  {
>  	struct mwifiex_ds_reg_rw reg_rw;
> 
> -	reg_rw.type = cpu_to_le32(reg_type);
> -	reg_rw.offset = cpu_to_le32(reg_offset);
> -	reg_rw.value = cpu_to_le32(reg_value);
> +	reg_rw.type = reg_type;
> +	reg_rw.offset = reg_offset;
> +	reg_rw.value = reg_value;
> 
>  	return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw,
> HostCmd_ACT_GEN_SET);  } @@ -1302,14 +1302,14 @@ mwifiex_reg_read(struct
> mwifiex_private *priv, u32 reg_type,
>  	int ret;
>  	struct mwifiex_ds_reg_rw reg_rw;
> 
> -	reg_rw.type = cpu_to_le32(reg_type);
> -	reg_rw.offset = cpu_to_le32(reg_offset);
> +	reg_rw.type = reg_type;
> +	reg_rw.offset = reg_offset;
>  	ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw,
> HostCmd_ACT_GEN_GET);
> 
>  	if (ret)
>  		goto done;
> 
> -	*value = le32_to_cpu(reg_rw.value);
> +	*value = reg_rw.value;
> 
>  done:
>  	return ret;
> @@ -1328,15 +1328,16 @@ mwifiex_eeprom_read(struct mwifiex_private
> *priv, u16 offset, u16 bytes,
>  	int ret;
>  	struct mwifiex_ds_read_eeprom rd_eeprom;
> 
> -	rd_eeprom.offset = cpu_to_le16((u16) offset);
> -	rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
> +	rd_eeprom.offset =  offset;
> +	rd_eeprom.byte_count = bytes;
> 
>  	/* Send request to firmware */
>  	ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
>  			       HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);
> 
>  	if (!ret)
> -		memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
> +		memcpy(value, rd_eeprom.value, min((u16)MAX_EEPROM_DATA,
> +		       rd_eeprom.byte_count));
>  	return ret;
>  }
> 

Acked-by: Amitkumar Karwar <akarwar@marvell.com>

Regards,
Amitkumar

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [v4] mwifiex: Reduce endian conversion for REG Host Commands
  2016-06-27 10:13   ` [PATCH v4] " Prasun Maiti
  2016-07-08 11:02     ` Amitkumar Karwar
  2016-07-08 14:33     ` Amitkumar Karwar
@ 2016-07-18 19:33     ` Kalle Valo
  2 siblings, 0 replies; 8+ messages in thread
From: Kalle Valo @ 2016-07-18 19:33 UTC (permalink / raw)
  To: Prasun Maiti
  Cc: Amitkumar Karwar, Nishant Sarmukadam, Linux Wireless, Linux Next,
	Linux Kernel

Prasun Maiti <prasunmaiti87@gmail.com> wrote:
> For multiple REG Host Commands (e.g HostCmd_CMD_802_11_EEPROM_ACCESS,
> HostCmd_CMD_MAC_REG_ACCESS etc.) "cpu_to_leX"-converted values are
> saved to driver. So, "leX_to_cpu" conversion is required too many
> times afterwards in driver.
> 
> This patch reduces the endian: conversion without saving "cpu_to_leX"
> converted values in driver. This will convert endianness in prepare
> command and command response path.
> 
> Signed-off-by: Prasun Maiti <prasunmaiti87@gmail.com>
> Acked-by: Amitkumar Karwar <akarwar@marvell.com>

Thanks, 1 patch applied to wireless-drivers-next.git:

8cfb86003dbf mwifiex: Reduce endian conversion for REG Host Commands

-- 
Sent by pwcli
https://patchwork.kernel.org/patch/9200265/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-07-18 19:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-23  5:29 [PATCH v3] mwifiex: Reduce endian conversion for REG Host Commands Prasun Maiti
2016-06-27  7:02 ` Amitkumar Karwar
2016-06-27 10:13   ` [PATCH v4] " Prasun Maiti
2016-07-08 11:02     ` Amitkumar Karwar
2016-07-08 13:40       ` Kalle Valo
2016-07-08 14:32         ` Amitkumar Karwar
2016-07-08 14:33     ` Amitkumar Karwar
2016-07-18 19:33     ` [v4] " Kalle Valo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).