Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1632793 > unrolled thread

Re: [PATCH] staging: rtl8192u: Improve readability and fix sparse warnings: cast from restricted __le16

Started byGreg KH <gregkh@linuxfoundation.org>
First post2017-04-28 12:40 +0200
Last post2017-04-29 13:40 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH] staging: rtl8192u: Improve readability and fix sparse  warnings: cast from restricted __le16 Greg KH <gregkh@linuxfoundation.org> - 2017-04-28 12:40 +0200
    [PATCH 1/3] staging: rtl8192u: Remove unnecessary scope Tuomo Rinne <tuomo.rinne@gmail.com> - 2017-04-29 13:40 +0200
      [PATCH 2/3] staging: rtl8192u: Improve code readability Tuomo Rinne <tuomo.rinne@gmail.com> - 2017-04-29 13:40 +0200
      [PATCH 3/3] staging: rtl8192u: Convert u4bAcParam back to little-endian after construction Tuomo Rinne <tuomo.rinne@gmail.com> - 2017-04-29 13:40 +0200

#1632793 — Re: [PATCH] staging: rtl8192u: Improve readability and fix sparse warnings: cast from restricted __le16

FromGreg KH <gregkh@linuxfoundation.org>
Date2017-04-28 12:40 +0200
SubjectRe: [PATCH] staging: rtl8192u: Improve readability and fix sparse warnings: cast from restricted __le16
Message-ID<tBbtE-64f-27@gated-at.bofh.it>
On Sat, Apr 22, 2017 at 11:55:23PM +0100, Tuomo Rinne wrote:
> This patch fixes following sparse warnings:
> 
> drivers/staging/rtl8192u//r8192U_dm.c:2307:49: warning: cast from restricted __le16
> drivers/staging/rtl8192u//r8192U_dm.c:2308:44: warning: cast from restricted __le16
> drivers/staging/rtl8192u//r8192U_dm.c:2309:44: warning: cast from restricted __le16
> 
> In order to avoid the warnings the u4bAcParam variable is constructed
> using the cpu's endianness and in case of big endian architectures the
> variable is converted back to little endian before passed to write_nic_dword
> function.
> 
> Also the patch improves readability by getting rid of unnecessary scope
> and splitting complex variable construction to multiple lines.

Don't do multiple things in the same patch, please break this up into
different patches, each one doing only one thing.

thanks,

greg k-h

[toc] | [next] | [standalone]


#1633292 — [PATCH 1/3] staging: rtl8192u: Remove unnecessary scope

FromTuomo Rinne <tuomo.rinne@gmail.com>
Date2017-04-29 13:40 +0200
Subject[PATCH 1/3] staging: rtl8192u: Remove unnecessary scope
Message-ID<tByTf-5FX-7@gated-at.bofh.it>
In reply to#1632793
Remove scope unnecessary scope that is already enforced by the if
statements scope.

Signed-off-by: Tuomo Rinne <tuomo.rinne@gmail.com>
---
 drivers/staging/rtl8192u/r8192U_dm.c | 66 +++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 34 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U_dm.c b/drivers/staging/rtl8192u/r8192U_dm.c
index 623d495..16cafb62 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -2300,43 +2300,41 @@ static void dm_check_edca_turbo(
 		 * Restore original EDCA according to the declaration of AP.
 		 */
 		if (priv->bcurrent_turbo_EDCA) {
+			u8		u1bAIFS;
+			u32		u4bAcParam;
+			struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
+			u8 mode = priv->ieee80211->mode;
+
+			/*  For Each time updating EDCA parameter, reset EDCA turbo mode status. */
+			dm_init_edca_turbo(dev);
+			u1bAIFS = qos_parameters->aifs[0] * ((mode&(IEEE_G|IEEE_N_24G)) ? 9 : 20) + aSifsTime;
+			u4bAcParam = (((le16_to_cpu(qos_parameters->tx_op_limit[0])) << AC_PARAM_TXOP_LIMIT_OFFSET)|
+				((le16_to_cpu(qos_parameters->cw_max[0])) << AC_PARAM_ECW_MAX_OFFSET)|
+				((le16_to_cpu(qos_parameters->cw_min[0])) << AC_PARAM_ECW_MIN_OFFSET)|
+				((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
+			/*write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);*/
+			write_nic_dword(dev, EDCAPARA_BE,  u4bAcParam);
+
+			/*
+			 * Check ACM bit.
+			 * If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13.
+			 */
 			{
-				u8		u1bAIFS;
-				u32		u4bAcParam;
-				struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
-				u8 mode = priv->ieee80211->mode;
-
-				/*  For Each time updating EDCA parameter, reset EDCA turbo mode status. */
-				dm_init_edca_turbo(dev);
-				u1bAIFS = qos_parameters->aifs[0] * ((mode&(IEEE_G|IEEE_N_24G)) ? 9 : 20) + aSifsTime;
-				u4bAcParam = (((le16_to_cpu(qos_parameters->tx_op_limit[0])) << AC_PARAM_TXOP_LIMIT_OFFSET)|
-					((le16_to_cpu(qos_parameters->cw_max[0])) << AC_PARAM_ECW_MAX_OFFSET)|
-					((le16_to_cpu(qos_parameters->cw_min[0])) << AC_PARAM_ECW_MIN_OFFSET)|
-					((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
-				/*write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);*/
-				write_nic_dword(dev, EDCAPARA_BE,  u4bAcParam);
-
-				/*
-				 * Check ACM bit.
-				 * If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13.
-				 */
-				{
-					/*  TODO:  Modified this part and try to set acm control in only 1 IO processing!! */
-
-					PACI_AIFSN	pAciAifsn = (PACI_AIFSN)&(qos_parameters->aifs[0]);
-					u8		AcmCtrl;
-
-					read_nic_byte(dev, AcmHwCtrl, &AcmCtrl);
-
-					if (pAciAifsn->f.ACM) { /*  ACM bit is 1. */
-						AcmCtrl |= AcmHw_BeqEn;
-					} else {	/* ACM bit is 0. */
-						AcmCtrl &= (~AcmHw_BeqEn);
-					}
+				/*  TODO:  Modified this part and try to set acm control in only 1 IO processing!! */
 
-					RT_TRACE(COMP_QOS, "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n", AcmCtrl);
-					write_nic_byte(dev, AcmHwCtrl, AcmCtrl);
+				PACI_AIFSN	pAciAifsn = (PACI_AIFSN)&(qos_parameters->aifs[0]);
+				u8		AcmCtrl;
+
+				read_nic_byte(dev, AcmHwCtrl, &AcmCtrl);
+
+				if (pAciAifsn->f.ACM) { /*  ACM bit is 1. */
+					AcmCtrl |= AcmHw_BeqEn;
+				} else {	/* ACM bit is 0. */
+					AcmCtrl &= (~AcmHw_BeqEn);
 				}
+
+				RT_TRACE(COMP_QOS, "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n", AcmCtrl);
+				write_nic_byte(dev, AcmHwCtrl, AcmCtrl);
 			}
 			priv->bcurrent_turbo_EDCA = false;
 		}
-- 
2.1.4

[toc] | [prev] | [next] | [standalone]


#1633293 — [PATCH 2/3] staging: rtl8192u: Improve code readability

FromTuomo Rinne <tuomo.rinne@gmail.com>
Date2017-04-29 13:40 +0200
Subject[PATCH 2/3] staging: rtl8192u: Improve code readability
Message-ID<tByTf-5FX-9@gated-at.bofh.it>
In reply to#1633292
Split the u4bAcParam parameter construction to multiple lines for easier
readability.

Signed-off-by: Tuomo Rinne <tuomo.rinne@gmail.com>
---
 drivers/staging/rtl8192u/r8192U_dm.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U_dm.c b/drivers/staging/rtl8192u/r8192U_dm.c
index 16cafb62..5e84ed7 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -2300,20 +2300,30 @@ static void dm_check_edca_turbo(
 		 * Restore original EDCA according to the declaration of AP.
 		 */
 		if (priv->bcurrent_turbo_EDCA) {
-			u8		u1bAIFS;
-			u32		u4bAcParam;
+			u8	u1bAIFS;
+			u32	u4bAcParam, op_limit, cw_max, cw_min;
+
 			struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
 			u8 mode = priv->ieee80211->mode;
 
 			/*  For Each time updating EDCA parameter, reset EDCA turbo mode status. */
 			dm_init_edca_turbo(dev);
-			u1bAIFS = qos_parameters->aifs[0] * ((mode&(IEEE_G|IEEE_N_24G)) ? 9 : 20) + aSifsTime;
-			u4bAcParam = (((le16_to_cpu(qos_parameters->tx_op_limit[0])) << AC_PARAM_TXOP_LIMIT_OFFSET)|
-				((le16_to_cpu(qos_parameters->cw_max[0])) << AC_PARAM_ECW_MAX_OFFSET)|
-				((le16_to_cpu(qos_parameters->cw_min[0])) << AC_PARAM_ECW_MIN_OFFSET)|
-				((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
-			/*write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);*/
-			write_nic_dword(dev, EDCAPARA_BE,  u4bAcParam);
+
+			u1bAIFS = qos_parameters->aifs[0] * ((mode & (IEEE_G | IEEE_N_24G)) ? 9 : 20) + aSifsTime;
+
+			op_limit = (u32)le16_to_cpu(qos_parameters->tx_op_limit[0]);
+			cw_max   = (u32)le16_to_cpu(qos_parameters->cw_max[0]);
+			cw_min   = (u32)le16_to_cpu(qos_parameters->cw_min[0]);
+
+			op_limit <<= AC_PARAM_TXOP_LIMIT_OFFSET;
+			cw_max   <<= AC_PARAM_ECW_MAX_OFFSET;
+			cw_min   <<= AC_PARAM_ECW_MIN_OFFSET;
+			u1bAIFS  <<= AC_PARAM_AIFS_OFFSET;
+
+			u4bAcParam = op_limit | cw_max | cw_min | u1bAIFS;
+
+			write_nic_dword(dev, EDCAPARA_BE, u4bAcParam);
+
 
 			/*
 			 * Check ACM bit.
-- 
2.1.4

[toc] | [prev] | [next] | [standalone]


#1633294 — [PATCH 3/3] staging: rtl8192u: Convert u4bAcParam back to little-endian after construction

FromTuomo Rinne <tuomo.rinne@gmail.com>
Date2017-04-29 13:40 +0200
Subject[PATCH 3/3] staging: rtl8192u: Convert u4bAcParam back to little-endian after construction
Message-ID<tByTg-5FX-15@gated-at.bofh.it>
In reply to#1633292
commit 9304b5b0d4fe8498d3d059db4bb8a7de253355a5 adds casting of le16
values to cpu to get rid of sparse warnings. The u4bAcParam is therefore
constructed using machines endianess. However, the parameter ought to be casted back to little endian to keep the function logic the same as before.

Unfortunately I don't have the hardware to test this change.

Signed-off-by: Tuomo Rinne <tuomo.rinne@gmail.com>
---
 drivers/staging/rtl8192u/r8192U_dm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8192u/r8192U_dm.c b/drivers/staging/rtl8192u/r8192U_dm.c
index 5e84ed7..dceec20 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -2321,10 +2321,10 @@ static void dm_check_edca_turbo(
 			u1bAIFS  <<= AC_PARAM_AIFS_OFFSET;
 
 			u4bAcParam = op_limit | cw_max | cw_min | u1bAIFS;
+			cpu_to_le32s(u4bAcParam);
 
 			write_nic_dword(dev, EDCAPARA_BE, u4bAcParam);
 
-
 			/*
 			 * Check ACM bit.
 			 * If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13.
-- 
2.1.4

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web