[media] siano: simplify message endianness logic

Currently, every time a message is sent or received, the endiannes
need to be fixed on big endian machines. This is currently done
on every call to the send API, and on every msg reception logic.
Instead of doing that, move it to the send/receive functions.
That simplifies the logic and avoids the risk of forgetting to
fix it somewhere.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
diff --git a/drivers/media/common/siano/smscoreapi.c b/drivers/media/common/siano/smscoreapi.c
index 9379ea7..8c576a6 100644
--- a/drivers/media/common/siano/smscoreapi.c
+++ b/drivers/media/common/siano/smscoreapi.c
@@ -37,7 +37,6 @@
 #include "smscoreapi.h"
 #include "sms-cards.h"
 #include "smsir.h"
-#include "smsendian.h"
 
 static int sms_dbg;
 module_param_named(debug, sms_dbg, int, 0644);
@@ -807,8 +806,6 @@
 				msg->msgData[0] = coredev->ir.controller;
 				msg->msgData[1] = coredev->ir.timeout;
 
-				smsendian_handle_tx_message(
-					(struct SmsMsgHdr_ST2 *)msg);
 				rc = smscore_sendrequest_and_wait(coredev, msg,
 						msg->xMsgHeader. msgLength,
 						&coredev->ir_init_done);
@@ -853,7 +850,6 @@
 		MtuMsg.xMsgHeader.msgLength = sizeof(MtuMsg);
 		MtuMsg.msgData[0] = board->mtu;
 
-		smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&MtuMsg);
 		coredev->sendrequest_handler(coredev->context, &MtuMsg,
 					     sizeof(MtuMsg));
 	}
@@ -867,7 +863,6 @@
 				sizeof(CrysMsg));
 		CrysMsg.msgData[0] = board->crystal;
 
-		smsendian_handle_tx_message((struct SmsMsgHdr_S *)&CrysMsg);
 		coredev->sendrequest_handler(coredev->context, &CrysMsg,
 					     sizeof(CrysMsg));
 	}
@@ -989,7 +984,6 @@
 		/* Entry point */
 	msg->msgData[1] = firmware->Length;
 	msg->msgData[2] = 0; /* Regular checksum*/
-	smsendian_handle_tx_message(msg);
 	rc = smscore_sendrequest_and_wait(coredev, msg,
 					  msg->xMsgHeader.msgLength,
 					  &coredev->data_validity_done);
@@ -1013,14 +1007,12 @@
 		TriggerMsg->msgData[3] = 0; /* Parameter */
 		TriggerMsg->msgData[4] = 4; /* Task ID */
 
-		smsendian_handle_tx_message((struct SmsMsgHdr_S *)msg);
 		rc = smscore_sendrequest_and_wait(coredev, TriggerMsg,
 					TriggerMsg->xMsgHeader.msgLength,
 					&coredev->trigger_done);
 	} else {
 		SMS_INIT_MSG(&msg->xMsgHeader, MSG_SW_RELOAD_EXEC_REQ,
 				sizeof(struct SmsMsgHdr_ST));
-		smsendian_handle_tx_message((struct SmsMsgHdr_S *)msg);
 		rc = coredev->sendrequest_handler(coredev->context, msg,
 				msg->xMsgHeader.msgLength);
 	}
@@ -1305,7 +1297,6 @@
 			sizeof(struct SmsMsgData_ST));
 	msg->msgData[0] = mode;
 
-	smsendian_handle_tx_message((struct SmsMsgHdr_ST *)msg);
 	rc = smscore_sendrequest_and_wait(coredev, msg,
 			msg->xMsgHeader. msgLength,
 			&coredev->init_device_done);
@@ -1526,8 +1517,6 @@
 		rc = client->onresponse_handler(client->context, cb);
 
 	if (rc < 0) {
-		smsendian_handle_rx_message((struct SmsMsgData_ST *)phdr);
-
 		switch (phdr->msgType) {
 		case MSG_SMS_ISDBT_TUNE_RES:
 			break;
@@ -2008,7 +1997,6 @@
 		pMsg->msgData[5] = 0;
 	}
 
-	smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
 	rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
 			&coredev->gpio_configuration_done);
 
@@ -2058,7 +2046,6 @@
 	pMsg->msgData[1] = NewLevel;
 
 	/* Send message to SMS */
-	smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
 	rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
 			&coredev->gpio_set_level_done);
 
@@ -2107,7 +2094,6 @@
 	pMsg->msgData[1] = 0;
 
 	/* Send message to SMS */
-	smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
 	rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
 			&coredev->gpio_get_level_done);
 
diff --git a/drivers/media/common/siano/smsdvb.c b/drivers/media/common/siano/smsdvb.c
index dbb807e..6335574 100644
--- a/drivers/media/common/siano/smsdvb.c
+++ b/drivers/media/common/siano/smsdvb.c
@@ -29,7 +29,6 @@
 #include "dvb_frontend.h"
 
 #include "smscoreapi.h"
-#include "smsendian.h"
 #include "sms-cards.h"
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
@@ -324,8 +323,6 @@
 	/*u32 MsgDataLen = phdr->msgLength - sizeof(struct SmsMsgHdr_ST);*/
 	bool is_status_update = false;
 
-	smsendian_handle_rx_message((struct SmsMsgData_ST *) phdr);
-
 	switch (phdr->msgType) {
 	case MSG_SMS_DVBT_BDA_DATA:
 		dvb_dmx_swfilter(&client->demux, (u8 *)(phdr + 1),
@@ -545,7 +542,6 @@
 	PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
 	PidMsg.msgData[0] = feed->pid;
 
-	smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&PidMsg);
 	return smsclient_sendrequest(client->smsclient,
 				     &PidMsg, sizeof(PidMsg));
 }
@@ -566,7 +562,6 @@
 	PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
 	PidMsg.msgData[0] = feed->pid;
 
-	smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&PidMsg);
 	return smsclient_sendrequest(client->smsclient,
 				     &PidMsg, sizeof(PidMsg));
 }
@@ -577,7 +572,6 @@
 {
 	int rc;
 
-	smsendian_handle_tx_message((struct SmsMsgHdr_ST *)buffer);
 	rc = smsclient_sendrequest(client->smsclient, buffer, size);
 	if (rc < 0)
 		return rc;
@@ -606,8 +600,6 @@
 	else
 		Msg.msgType = MSG_SMS_GET_STATISTICS_REQ;
 
-	smsendian_handle_tx_message((struct SmsMsgHdr_S *)&Msg);
-
 	rc = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
 					 &client->stats_done);
 
diff --git a/drivers/media/mmc/siano/smssdio.c b/drivers/media/mmc/siano/smssdio.c
index c96da47..8834c43 100644
--- a/drivers/media/mmc/siano/smssdio.c
+++ b/drivers/media/mmc/siano/smssdio.c
@@ -43,6 +43,7 @@
 
 #include "smscoreapi.h"
 #include "sms-cards.h"
+#include "smsendian.h"
 
 /* Registers */
 
@@ -97,6 +98,7 @@
 
 	sdio_claim_host(smsdev->func);
 
+	smsendian_handle_tx_message((struct SmsMsgData_ST *) buffer);
 	while (size >= smsdev->func->cur_blksize) {
 		ret = sdio_memcpy_toio(smsdev->func, SMSSDIO_DATA,
 					buffer, smsdev->func->cur_blksize);
@@ -231,6 +233,7 @@
 	cb->size = hdr->msgLength;
 	cb->offset = 0;
 
+	smsendian_handle_rx_message((struct SmsMsgData_ST *) cb->p);
 	smscore_onresponse(smsdev->coredev, cb);
 }
 
diff --git a/drivers/media/usb/siano/smsusb.c b/drivers/media/usb/siano/smsusb.c
index 751c0d6..acd3d1e 100644
--- a/drivers/media/usb/siano/smsusb.c
+++ b/drivers/media/usb/siano/smsusb.c
@@ -129,6 +129,8 @@
 				  smscore_translate_msg(phdr->msgType),
 				  phdr->msgType, phdr->msgLength);
 
+			smsendian_handle_rx_message((struct SmsMsgData_ST *) phdr);
+
 			smscore_onresponse(dev->coredev, surb->cb);
 			surb->cb = NULL;
 		} else {
@@ -207,13 +209,14 @@
 	struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) buffer;
 	int dummy;
 
+	if (dev->state != SMSUSB_ACTIVE)
+		return -ENOENT;
+
 	sms_debug("sending %s(%d) size: %d",
 		  smscore_translate_msg(phdr->msgType), phdr->msgType,
 		  phdr->msgLength);
 
-	if (dev->state != SMSUSB_ACTIVE)
-		return -ENOENT;
-
+	smsendian_handle_tx_message((struct SmsMsgData_ST *) phdr);
 	smsendian_handle_message_header((struct SmsMsgHdr_ST *)buffer);
 	return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2),
 			    buffer, size, &dummy, 1000);