Re: [PATCH 5.8 05/85] Revert "usbip: Implement a match function to fix usbip"

2020-10-08 Thread M. Vefa Bicakci

On 08/10/2020 05.25, Greg Kroah-Hartman wrote:

On Thu, Oct 08, 2020 at 04:56:56AM -0400, M. Vefa Bicakci wrote:

On 07/10/2020 12.13, Greg Kroah-Hartman wrote:

On Tue, Oct 06, 2020 at 04:26:27PM +0300, M. Vefa Bicakci wrote:

On 05/10/2020 18.26, Greg Kroah-Hartman wrote:

From: M. Vefa Bicakci 

commit d6407613c1e2ef90213dee388aa16b6e1bd08cbc upstream.

This commit reverts commit 7a2f2974f265 ("usbip: Implement a match
function to fix usbip").

In summary, commit d5643d2249b2 ("USB: Fix device driver race")
inadvertently broke usbip functionality, which I resolved in an incorrect
manner by introducing a match function to usbip, usbip_match(), that
unconditionally returns true.

However, the usbip_match function, as is, causes usbip to take over
virtual devices used by syzkaller for USB fuzzing, which is a regression
reported by Andrey Konovalov.

Furthermore, in conjunction with the fix of another bug, handled by another
patch titled "usbcore/driver: Fix specific driver selection" in this patch
set, the usbip_match function causes unexpected USB subsystem behaviour
when the usbip_host driver is loaded. The unexpected behaviour can be
qualified as follows:
- If commit 41160802ab8e ("USB: Simplify USB ID table match") is included
 in the kernel, then all USB devices are bound to the usbip_host
 driver, which appears to the user as if all USB devices were
 disconnected.
- If the same commit (41160802ab8e) is not in the kernel (as is the case
 with v5.8.10) then all USB devices are re-probed and re-bound to their
 original device drivers, which appears to the user as a disconnection
 and re-connection of USB devices.

Please note that this commit will make usbip non-operational again,
until yet another patch in this patch set is merged, titled
"usbcore/driver: Accommodate usbip".

Cc:  # 5.8: 41160802ab8e: USB: Simplify USB ID table 
match
Cc:  # 5.8


Hello Greg,

Sorry for the lateness of this e-mail.

I had noted commit 41160802ab8e ("USB: Simplify USB ID table match") as a
prerequisite in the commit message, but I just realized that the commit
identifier refers to a commit in my local git tree, and not to the actual
commit in Linus Torvalds' git tree! I apologize for this mistake.

Here is the correct commit identifier:
0ed9498f9ecfde50c93f3f3dd64b4cd5414d9944 ("USB: Simplify USB ID table 
match")

Perhaps this is why the prerequisite commit was not cherry-picked to the 5.8.y
branch.

As a justification for the cherry-pick, commit 0ed9498f9ecf actually resolves
a bug. In summary, this commit works together with commit adb6e6ac20ee ("USB:
Also match device drivers using the ->match vfunc", which has been cherry-picked
as part of v5.8.6) and ensures that a USB driver's ->match function is also
called during the search for a more specialized/appropriate USB driver, in case
the driver in question does not have an id_table.

If I am to be the devil's advocate, however, then given that there is only one
specialized USB device driver ("apple-mfi-fastcharge"), which conveniently has
an id_table, and also given that usbip no longer has a match function, I also
realize that it may not be crucial to cherry-pick 0ed9498f9ecf as a prerequisite
commit.


I'm sorry, but I don't really understand.  Does 5.8.y need an additional
patch here, or is all ok because I missed the above patch?


No worries; sorry for not communicating clearly and for the delay.

I meant to state that it would be good to have commit 0ed9498f9ecf ("USB: 
Simplify
USB ID table match") cherry picked to 5.8.y, as it fixes a bug, albeit a minor 
one.


What bug does it fix now?  Is usbip or the apple charger driver not
working properly on 5.8.14?  If nothing is broken, no need to add this
patch...


I had tried to describe the bug in my original e-mail; it involves not 
considering
the match functions of candidate USB drivers when determining whether a more
specialized driver exists for a USB device. The bug takes effect when a 
candidate
USB driver does not have an id_table, but has a match function.

To the best of my current understanding, however, the impact of the bug is
currently none/negligible, because the only specialized driver is currently
the Apple charger driver, and the Apple charger driver uses an id_table and
not a match function.

All this to say, given your last statement, and having thought about the whole
thing one more time, perhaps we do not need to cherry-pick the aforementioned
commit. Sorry for the noise!

Thank you,

Vefa


Re: [PATCH 5.8 05/85] Revert "usbip: Implement a match function to fix usbip"

2020-10-08 Thread M. Vefa Bicakci

On 07/10/2020 12.13, Greg Kroah-Hartman wrote:

On Tue, Oct 06, 2020 at 04:26:27PM +0300, M. Vefa Bicakci wrote:

On 05/10/2020 18.26, Greg Kroah-Hartman wrote:

From: M. Vefa Bicakci 

commit d6407613c1e2ef90213dee388aa16b6e1bd08cbc upstream.

This commit reverts commit 7a2f2974f265 ("usbip: Implement a match
function to fix usbip").

In summary, commit d5643d2249b2 ("USB: Fix device driver race")
inadvertently broke usbip functionality, which I resolved in an incorrect
manner by introducing a match function to usbip, usbip_match(), that
unconditionally returns true.

However, the usbip_match function, as is, causes usbip to take over
virtual devices used by syzkaller for USB fuzzing, which is a regression
reported by Andrey Konovalov.

Furthermore, in conjunction with the fix of another bug, handled by another
patch titled "usbcore/driver: Fix specific driver selection" in this patch
set, the usbip_match function causes unexpected USB subsystem behaviour
when the usbip_host driver is loaded. The unexpected behaviour can be
qualified as follows:
- If commit 41160802ab8e ("USB: Simplify USB ID table match") is included
in the kernel, then all USB devices are bound to the usbip_host
driver, which appears to the user as if all USB devices were
disconnected.
- If the same commit (41160802ab8e) is not in the kernel (as is the case
with v5.8.10) then all USB devices are re-probed and re-bound to their
original device drivers, which appears to the user as a disconnection
and re-connection of USB devices.

Please note that this commit will make usbip non-operational again,
until yet another patch in this patch set is merged, titled
"usbcore/driver: Accommodate usbip".

Cc:  # 5.8: 41160802ab8e: USB: Simplify USB ID table 
match
Cc:  # 5.8


Hello Greg,

Sorry for the lateness of this e-mail.

I had noted commit 41160802ab8e ("USB: Simplify USB ID table match") as a
prerequisite in the commit message, but I just realized that the commit
identifier refers to a commit in my local git tree, and not to the actual
commit in Linus Torvalds' git tree! I apologize for this mistake.

Here is the correct commit identifier:
   0ed9498f9ecfde50c93f3f3dd64b4cd5414d9944 ("USB: Simplify USB ID table match")

Perhaps this is why the prerequisite commit was not cherry-picked to the 5.8.y
branch.

As a justification for the cherry-pick, commit 0ed9498f9ecf actually resolves
a bug. In summary, this commit works together with commit adb6e6ac20ee ("USB:
Also match device drivers using the ->match vfunc", which has been cherry-picked
as part of v5.8.6) and ensures that a USB driver's ->match function is also
called during the search for a more specialized/appropriate USB driver, in case
the driver in question does not have an id_table.

If I am to be the devil's advocate, however, then given that there is only one
specialized USB device driver ("apple-mfi-fastcharge"), which conveniently has
an id_table, and also given that usbip no longer has a match function, I also
realize that it may not be crucial to cherry-pick 0ed9498f9ecf as a prerequisite
commit.


I'm sorry, but I don't really understand.  Does 5.8.y need an additional
patch here, or is all ok because I missed the above patch?


No worries; sorry for not communicating clearly and for the delay.

I meant to state that it would be good to have commit 0ed9498f9ecf ("USB: 
Simplify
USB ID table match") cherry picked to 5.8.y, as it fixes a bug, albeit a minor 
one.

Thank you,

Vefa


Re: [PATCH 5.8 05/85] Revert "usbip: Implement a match function to fix usbip"

2020-10-06 Thread M. Vefa Bicakci

On 05/10/2020 18.26, Greg Kroah-Hartman wrote:

From: M. Vefa Bicakci 

commit d6407613c1e2ef90213dee388aa16b6e1bd08cbc upstream.

This commit reverts commit 7a2f2974f265 ("usbip: Implement a match
function to fix usbip").

In summary, commit d5643d2249b2 ("USB: Fix device driver race")
inadvertently broke usbip functionality, which I resolved in an incorrect
manner by introducing a match function to usbip, usbip_match(), that
unconditionally returns true.

However, the usbip_match function, as is, causes usbip to take over
virtual devices used by syzkaller for USB fuzzing, which is a regression
reported by Andrey Konovalov.

Furthermore, in conjunction with the fix of another bug, handled by another
patch titled "usbcore/driver: Fix specific driver selection" in this patch
set, the usbip_match function causes unexpected USB subsystem behaviour
when the usbip_host driver is loaded. The unexpected behaviour can be
qualified as follows:
- If commit 41160802ab8e ("USB: Simplify USB ID table match") is included
   in the kernel, then all USB devices are bound to the usbip_host
   driver, which appears to the user as if all USB devices were
   disconnected.
- If the same commit (41160802ab8e) is not in the kernel (as is the case
   with v5.8.10) then all USB devices are re-probed and re-bound to their
   original device drivers, which appears to the user as a disconnection
   and re-connection of USB devices.

Please note that this commit will make usbip non-operational again,
until yet another patch in this patch set is merged, titled
"usbcore/driver: Accommodate usbip".

Cc:  # 5.8: 41160802ab8e: USB: Simplify USB ID table 
match
Cc:  # 5.8


Hello Greg,

Sorry for the lateness of this e-mail.

I had noted commit 41160802ab8e ("USB: Simplify USB ID table match") as a
prerequisite in the commit message, but I just realized that the commit
identifier refers to a commit in my local git tree, and not to the actual
commit in Linus Torvalds' git tree! I apologize for this mistake.

Here is the correct commit identifier:
  0ed9498f9ecfde50c93f3f3dd64b4cd5414d9944 ("USB: Simplify USB ID table match")

Perhaps this is why the prerequisite commit was not cherry-picked to the 5.8.y
branch.

As a justification for the cherry-pick, commit 0ed9498f9ecf actually resolves
a bug. In summary, this commit works together with commit adb6e6ac20ee ("USB:
Also match device drivers using the ->match vfunc", which has been cherry-picked
as part of v5.8.6) and ensures that a USB driver's ->match function is also
called during the search for a more specialized/appropriate USB driver, in case
the driver in question does not have an id_table.

If I am to be the devil's advocate, however, then given that there is only one
specialized USB device driver ("apple-mfi-fastcharge"), which conveniently has
an id_table, and also given that usbip no longer has a match function, I also
realize that it may not be crucial to cherry-pick 0ed9498f9ecf as a prerequisite
commit.

I just wanted to bring this to your attention.

Thank you,

Vefa


Re: [PATCH] platform/x86: intel_pmc_core: Do not ioremap RAM

2019-08-16 Thread M. Vefa Bicakci
On Fri, 16 Aug 2019 12:21:58 +0300
Andy Shevchenko  wrote:

> On Fri, Aug 16, 2019 at 4:42 AM M. Vefa Bicakci  wrote:
> >
> > On a Xen-based PVH virtual machine with more than 4 GiB of RAM,
> > intel_pmc_core fails initialization with the following warning message
> > from the kernel, indicating that the driver is attempting to ioremap
> > RAM:
> >
> >   [ cut here ]
> >   ioremap on RAM at 0xfe00 - 0xfe001fff  
> 
> > This issue appears to manifest itself because of the following fallback
> > mechanism in the driver:
> >
> > if (lpit_read_residency_count_address(_s0_addr))
> > pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT;
> >
> > The validity of address PMC_BASE_ADDR_DEFAULT (i.e., 0xFE00) is not
> > verified by the driver, which is what this patch introduces. With this
> > patch, if address PMC_BASE_ADDR_DEFAULT is in RAM, then the driver will
> > not attempt to ioremap the aforementioned address.  
> 
> Thank you for the patch.

Hello Andy,

Thank you for reviewing the patch!

> Is there anything preventing us to use memremap() in such case?

I re-read the documentation for memremap a few times along with taking
a look at its code, but I think I am missing an important piece of
information. As I understand it, depending on its flags, memremap would
allow a section of RAM to be mapped for the PMC driver.

The intention with this patch is to prevent the driver from being
instantiated when the default/fallback memory address is in RAM, as
this issue occurs with a non-administrative virtual machine (domU in
Xen terminology) that does not simulate or pass-through a corresponding
PMC device.

I think that I have misunderstood your review comment though, so I
would apppreciate it if you could elaborate.

Thanks again for reviewing the patch,

Vefa

(Please note that my next reply may be delayed by about 10 hours.)


[PATCH] platform/x86: intel_pmc_core_pltdrv: Module removal warning fix

2019-08-15 Thread M. Vefa Bicakci
Prior to this commit, removing the intel_pmc_core_pltdrv module
would cause the following warning:

  [ cut here ]
  Device 'intel_pmc_core.0' does not have a release() function, \
it is broken and must be fixed. See Documentation/kobject.txt.
  WARNING: CPU: 0 PID: 2202 at drivers/base/core.c:1238 device_release+0x6f/0x80
  Modules linked in: fuse intel_rapl_msr ip6table_filter ip6_tables ipt_REJECT \
nf_reject_ipv4 xt_conntrack iptable_filter xt_MASQUERADE iptable_nat nf_nat 
\
nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 libcrc32c intel_rapl_common \
intel_pmc_core_pltdrv(-) xen_netfront intel_pmc_core crct10dif_pclmul \
crc32_pclmul crc32c_intel ghash_clmulni_intel intel_rapl_perf pcspkr 
binfmt_misc \
u2mfn(O) xenfs xen_gntdev xen_gntalloc xen_blkback xen_privcmd xen_evtchn \
ip_tables overlay xen_blkfront
  CPU: 0 PID: 2202 Comm: rmmod Tainted: GW  O  
5.3.0-rc3-next-20190809-1 #2
  RIP: 0010:device_release+0x6f/0x80
  Code: 48 8b 85 c0 02 00 00 48 85 c0 74 09 48 8b 40 40 48 85 c0 75 c6 48 8b 75 
50 48 85 f6 74 10 48 c7 c7 58 68 12 82 e8 5f 62 a9 ff <0f> 0b eb b5 48 8b 75 00 
eb ea 0f 1f 80 00 00 00 00 0f 1f 44 00 00
  RSP: 0018:c9763ea8 EFLAGS: 00010286
  RAX:  RBX: 822da080 RCX: 0006
  RDX: 0007 RSI: 0082 RDI: 88813ba17540
  RBP: c0107010 R08: 0195 R09: 000d
  R10: 000a R11: c9763d65 R12: 88800c9e9000
  R13:  R14:  R15: 
  FS:  71250bf142c0() GS:88813ba0() knlGS:
  CS:  0010 DS:  ES:  CR0: 80050033
  CR2: 60ab8fd82d49 CR3: 0001273ba004 CR4: 003606f0
  Call Trace:
   kobject_put+0x85/0x1b0
   __x64_sys_delete_module+0x14b/0x270
   do_syscall_64+0x5f/0x1a0
   entry_SYSCALL_64_after_hwframe+0x44/0xa9
  RIP: 0033:0x71250c031c6b
  Code: 73 01 c3 48 8b 0d 1d 42 0c 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 
84 00 00 00 00 00 90 f3 0f 1e fa b8 b0 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 
c3 48 8b 0d ed 41 0c 00 f7 d8 64 89 01 48
  RSP: 002b:7ffec29e6038 EFLAGS: 0206 ORIG_RAX: 00b0
  RAX: ffda RBX: 6040bc3e07b0 RCX: 71250c031c6b
  RDX: 000a RSI: 0800 RDI: 6040bc3e0818
  RBP: 7ffec29e6088 R08: 1999 R09: 
  R10: 71250c0a6ac0 R11: 0206 R12: 7ffec29e6250
  R13: 7ffec29e67b7 R14: 6040bc3e0260 R15: 7ffec29e6090
  ---[ end trace 5e5421608729d6f5 ]---

This commit hence adds an empty release function for the driver.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/platform/x86/intel_pmc_core_pltdrv.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/platform/x86/intel_pmc_core_pltdrv.c 
b/drivers/platform/x86/intel_pmc_core_pltdrv.c
index a8754a6db1b8..186540014c48 100644
--- a/drivers/platform/x86/intel_pmc_core_pltdrv.c
+++ b/drivers/platform/x86/intel_pmc_core_pltdrv.c
@@ -18,8 +18,16 @@
 #include 
 #include 
 
+static void intel_pmc_core_release(struct device *dev)
+{
+   /* Nothing to do. */
+}
+
 static struct platform_device pmc_core_device = {
.name = "intel_pmc_core",
+   .dev  = {
+   .release = intel_pmc_core_release,
+   },
 };
 
 /*
-- 
2.21.0



[PATCH] platform/x86: intel_pmc_core: Do not ioremap RAM

2019-08-15 Thread M. Vefa Bicakci
On a Xen-based PVH virtual machine with more than 4 GiB of RAM,
intel_pmc_core fails initialization with the following warning message
from the kernel, indicating that the driver is attempting to ioremap
RAM:

  [ cut here ]
  ioremap on RAM at 0xfe00 - 0xfe001fff
  WARNING: CPU: 1 PID: 434 at arch/x86/mm/ioremap.c:186 
__ioremap_caller.constprop.0+0x2aa/0x2c0
  Modules linked in: intel_pmc_core_pltdrv(+) xen_netfront(+) intel_pmc_core \
crct10dif_pclmul crc32_pclmul crc32c_intel ghash_clmulni_intel \
intel_rapl_perf pcspkr binfmt_misc u2mfn(O) xenfs xen_gntdev \
xen_gntalloc xen_blkback xen_privcmd xen_evtchn ip_tables overlay \
xen_blkfront
  CPU: 1 PID: 434 Comm: systemd-udevd Tainted: G   O  
5.3.0-rc3-next-20190809-1 #2
  RIP: 0010:__ioremap_caller.constprop.0+0x2aa/0x2c0
  Code: 05 0f c9 1b 01 49 09 c6 e9 8e fe ff ff 48 8d 54 24 28 48 c7 c7 68 87 0a 
82 c6 05 c4 23 2b 01 01 48 8d 74 24 18 e8 d4 4a 06 00 <0f> 0b 45 31 ff e9 fe fe 
ff ff e8 e7 47 06 00 0f 1f 80 00 00 00 00
  RSP: 0018:c92dfa20 EFLAGS: 00010282
  RAX:  RBX: c0107000 RCX: 0006
  RDX: 0007 RSI: 0092 RDI: 88813bb17540
  RBP: fe00 R08: 015f R09: 000a
  R10: 000a R11: c92df8da R12: 2000
  R13:  R14: 0002 R15: 822da3a0
  FS:  72ecce666940() GS:88813bb0() knlGS:
  CS:  0010 DS:  ES:  CR0: 80050033
  CR2: 785be7346d20 CR3: 0d872001 CR4: 003606e0
  Call Trace:
   ? pmc_core_probe+0x87/0x2d0 [intel_pmc_core]
   pmc_core_probe+0x87/0x2d0 [intel_pmc_core]
   platform_drv_probe+0x35/0x80
   really_probe+0x298/0x3c0
   driver_probe_device+0x7a/0x100
   ? driver_allows_async_probing+0x50/0x50
   bus_for_each_drv+0x8f/0xd0
   __device_attach+0xf0/0x170
   bus_probe_device+0x8e/0xa0
   device_add+0x692/0x7e0
   platform_device_add+0xe9/0x240
   ? 0xc00ec000
   do_one_initcall+0x59/0x214
   do_init_module+0x5c/0x230
   load_module+0x258d/0x2840
   ? __do_sys_finit_module+0xbb/0x120
   __do_sys_finit_module+0xbb/0x120
   do_syscall_64+0x5f/0x1a0
   entry_SYSCALL_64_after_hwframe+0x44/0xa9
  RIP: 0033:0x72eccf662fad
  Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 
89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 
c3 48 8b 0d ab 9e 0c 00 f7 d8 64 89 01 48
  RSP: 002b:7ffd3710d018 EFLAGS: 0246 ORIG_RAX: 0139
  RAX: ffda RBX: 60ab8fda2530 RCX: 72eccf662fad
  RDX:  RSI: 72eccf2bd84d RDI: 0017
  RBP: 0002 R08:  R09: 0007
  R10: 0017 R11: 0246 R12: 72eccf2bd84d
  R13:  R14: 60ab8fd9b5e0 R15: 0007
  ---[ end trace 5e5421608729d6f4 ]---

This issue appears to manifest itself because of the following fallback
mechanism in the driver:

if (lpit_read_residency_count_address(_s0_addr))
pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT;

The validity of address PMC_BASE_ADDR_DEFAULT (i.e., 0xFE00) is not
verified by the driver, which is what this patch introduces. With this
patch, if address PMC_BASE_ADDR_DEFAULT is in RAM, then the driver will
not attempt to ioremap the aforementioned address.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/platform/x86/intel_pmc_core.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/intel_pmc_core.c 
b/drivers/platform/x86/intel_pmc_core.c
index c510d0d72475..3b6b8dcc4767 100644
--- a/drivers/platform/x86/intel_pmc_core.c
+++ b/drivers/platform/x86/intel_pmc_core.c
@@ -878,10 +878,14 @@ static int pmc_core_probe(struct platform_device *pdev)
if (pmcdev->map == _reg_map && !pci_dev_present(pmc_pci_ids))
pmcdev->map = _reg_map;
 
-   if (lpit_read_residency_count_address(_s0_addr))
+   if (lpit_read_residency_count_address(_s0_addr)) {
pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT;
-   else
+
+   if (page_is_ram(PHYS_PFN(pmcdev->base_addr)))
+   return -ENODEV;
+   } else {
pmcdev->base_addr = slp_s0_addr - pmcdev->map->slp_s0_offset;
+   }
 
pmcdev->regbase = ioremap(pmcdev->base_addr,
  pmcdev->map->regmap_length);
-- 
2.21.0



[PATCH v2] kconfig: Clear "written" flag to avoid data loss

2019-08-03 Thread M. Vefa Bicakci
Prior to this commit, starting nconfig, xconfig or gconfig, and saving
the .config file more than once caused data loss, where a .config file
that contained only comments would be written to disk starting from the
second save operation.

This bug manifests itself because the SYMBOL_WRITTEN flag is never
cleared after the first call to conf_write, and subsequent calls to
conf_write then skip all of the configuration symbols due to the
SYMBOL_WRITTEN flag being set.

This commit resolves this issue by clearing the SYMBOL_WRITTEN flag
from all symbols before conf_write returns.

Fixes: 8e2442a5f86e ("kconfig: fix missing choice values in auto.conf")
Cc: linux-stable  # 4.19+
Signed-off-by: M. Vefa Bicakci 

---

Changes since v1:
* As suggested by Masahiro Yamada, instead of defining a new helper
  function to traverse over all symbols in a pre-defined order, use
  the for_all_symbols iterator.
---
 scripts/kconfig/confdata.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 1134892599da..3569d2dec37c 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -848,6 +848,7 @@ int conf_write(const char *name)
const char *str;
char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1];
char *env;
+   int i;
bool need_newline = false;
 
if (!name)
@@ -930,6 +931,9 @@ int conf_write(const char *name)
}
fclose(out);
 
+   for_all_symbols(i, sym)
+   sym->flags &= ~SYMBOL_WRITTEN;
+
if (*tmpname) {
if (is_same(name, tmpname)) {
conf_message("No change to %s", name);
-- 
2.21.0



Re: [PATCH] kconfig: fix missing choice values in auto.conf

2019-08-02 Thread M. Vefa Bicakci
Hello,

> conf_write() must be changed accordingly. Currently, it clears
> SYMBOL_WRITE after the symbol is written into the .config file. This
> is needed to prevent it from writing the same symbol multiple times in
> case the symbol is declared in two or more locations. I added the new
> flag SYMBOL_WRITTEN, to track the symbols that have been written.
[snip]
> diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> index cbb6efa4a5a6..e0972b255aac 100644
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
[snip]
> @@ -903,7 +904,7 @@ int conf_write(const char *name)
>   fprintf(out, "\n");
>   need_newline = false;
>   }
> - sym->flags &= ~SYMBOL_WRITE;
> + sym->flags |= SYMBOL_WRITTEN;

The SYMBOL_WRITTEN flag is never cleared after being set in this
function, which unfortunately causes data loss to occur when a user
starts xconfig, gconfig, or nconfig and saves a config file more than
once. Every save operation after the first one causes the saved .config
file to contain only comments.

I am appending a patch that resolves this issue. The patch is a bit
ugly because of the code duplication, but it fixes this bug. (I have
lightly tested the patch.) Even if the patch is not merged, I would
appreciate it if this bug could be fixed.

Thank you,

Vefa

=== 8< === Patch Follows === >8 ===

From: "M. Vefa Bicakci" 
Date: Fri, 2 Aug 2019 17:44:40 -0400
Subject: [PATCH] kconfig: Clear "written" flag to avoid data loss

Prior to this commit, starting nconfig, xconfig or gconfig, and saving
the .config file more than once caused data loss, where a .config file
that contained only comments would be written to disk starting from the
second save operation.

This bug manifests itself because the SYMBOL_WRITTEN flag is never
cleared after the first call to conf_write, and subsequent calls to
conf_write then skip all of the configuration symbols due to the
SYMBOL_WRITTEN flag being set.

This commit resolves this issue by clearing the SYMBOL_WRITTEN flag
from all symbols before conf_write returns.

Fixes: 8e2442a5f86e ("kconfig: fix missing choice values in auto.conf")
Cc: linux-stable  # 4.19+
Signed-off-by: M. Vefa Bicakci 
---
 scripts/kconfig/confdata.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 1134892599da..24fe0c851e8c 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -840,6 +840,35 @@ int conf_write_defconfig(const char *filename)
return 0;
 }
 
+static void conf_clear_written_flag(void)
+{
+   struct menu *menu;
+   struct symbol *sym;
+
+   menu = rootmenu.list;
+   while (menu) {
+   sym = menu->sym;
+   if (sym && (sym->flags & SYMBOL_WRITTEN))
+   sym->flags &= ~SYMBOL_WRITTEN;
+
+   if (menu->list) {
+   menu = menu->list;
+   continue;
+   }
+
+   if (menu->next) {
+   menu = menu->next;
+   } else {
+   while ((menu = menu->parent)) {
+   if (menu->next) {
+   menu = menu->next;
+   break;
+   }
+   }
+   }
+   }
+}
+
 int conf_write(const char *name)
 {
FILE *out;
@@ -930,6 +959,8 @@ int conf_write(const char *name)
}
fclose(out);
 
+   conf_clear_written_flag();
+
if (*tmpname) {
if (is_same(name, tmpname)) {
conf_message("No change to %s", name);
-- 
2.21.0



Re: [PATCH] x86/cpuid: Deal with broken firmware once more

2016-11-13 Thread M. Vefa Bicakci
On 11/13/2016 09:04 PM, Boris Ostrovsky wrote:
> On 11/12/2016 05:05 PM, M. Vefa Bicakci wrote:
>> On 11/10/2016 06:31 PM, Boris Ostrovsky wrote:
>>> On 11/10/2016 10:05 AM, Charles (Chas) Williams wrote:
>>>>
>>>> On 11/10/2016 09:02 AM, Boris Ostrovsky wrote:
>>>>> On 11/10/2016 06:13 AM, Thomas Gleixner wrote:
>>>>>> On Thu, 10 Nov 2016, M. Vefa Bicakci wrote:
>>>>>>
>>>>>>> I have found that your patch unfortunately does not improve the
>>>>>>> situation
>>>>>>> for me. Here is an excerpt obtained from the dmesg of a kernel
>>>>>>> compiled
>>>>>>> with this patch *as well as* Sebastian's patch:
>>>>>>> [0.002561] CPU: Physical Processor ID: 0
>>>>>>> [0.002566] CPU: Processor Core ID: 0
>>>>>>> [0.002572] [Firmware Bug]: CPU0: APIC id mismatch. Firmware:
>>>>>>>  CPUID: 2
>>>>>> So apic->cpu_present_to_apicid() gives us a completely bogus APIC id
>>>>>> which
>>>>>> translates to a bogus package id. And looking at the XEN code:
>>>>>>
>>>>>>xen_pv_apic.cpu_present_to_apicid = xen_cpu_present_to_apicid,
>>>>>>
>>>>>> and xen_cpu_present_to_apicid does:
>>>>>>
>>>>>> static int xen_cpu_present_to_apicid(int cpu)
>>>>>> {
>>>>>> if (cpu_present(cpu))
>>>>>> return xen_get_apic_id(xen_apic_read(APIC_ID));
>>>>>> else
>>>>>> return BAD_APICID;
>>>>>> }
>>>>>>
>>>>>> So independent of which present CPU we query we get just some random
>>>>>> information, in the above case we get BAD_APICID from
>>>>>> xen_apic_read() not
>>>>>> from the else path as this CPU _IS_ present.
>>>>>>
>>>>>> What's so wrong with storing the fricking firmware supplied APICid as
>>>>>> everybody else does and report it back when queried?
>>>>> By firmware you mean ACPI? It is most likely not available to PV guests.
>>>>> How about returning cpu_data(cpu).initial_apicid?
>>>>>
>>>>> And what was the original problem?
>>>> The original issue I found was that VMware was returning a different set
>>>> of APIC id's in the ACPI tables than what it advertised on the CPU's.
>>>>
>>>> http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1266716.html
>>> For Xen, we recently added a6a198bc60e6 ("xen/x86: Update topology map
>>> for PV VCPUs") to at least temporarily work around some topology map
>>> problems that PV guests have with RAPL (which I think is what Vefa's
>>> problem was).
>> Hello Boris,
>>
>> (Sorry for the delay!)
>>
>> It appears that the problem is a bit different compared to the one
>> corrected by a6a198bc60e6, because my kernel tree -- based on 4.8.6 --
>> already includes the -stable backport of that commit, i.e.
>>   88540ad0820ddfb05626e0136c0e5a79cea85fd1
>>
>> The patch I included in my previous e-mail (dated 2016-11-10) corrects
>> root cause of the issue I am having with 4.8.6. Sebastian's original
>> patch adding error checking to the RAPL module prevents the RAPL module
>> from causing a kernel oops without my patch.
> 
> I don't see any messages from you on that date. Can you provide a link
> to it (and to Sebastian's patch)?
> 
> (BTW, generally it's a good idea to copy xen-devel list on any
> Xen-related issues).

As I explain below, it turns out that my issue was 'only' a kernel
configuration issue.

For reference, I had unknowingly solved my kernel-configuration-induced
issue via the patch at:
  https://marc.info/?l=linux-kernel=147875027314638=2

Sebastian's patch (which adds error handling to the RAPL module) is at:
  https://marc.info/?l=linux-kernel=147739814217598=2

>> The issue I am experiencing is caused by the boot-up code in the
>> 'init_apic_mappings' function switching the APIC ops structure from
>> Xen's structure to a no-op structure by calling the 'apic_disable'
>> function. Please let me know if I can clarify or elaborate.
> 
> apic_disable() is only invoked if there is no APIC present (i.e.
> detect_init_APIC() returns a non-zero value) and I don't think this can
> happen. Is your CPUID[1].edx[9] not set?

I found out that my domU kernels invoke 

Re: [PATCH] x86/cpuid: Deal with broken firmware once more

2016-11-13 Thread M. Vefa Bicakci
On 11/13/2016 09:04 PM, Boris Ostrovsky wrote:
> On 11/12/2016 05:05 PM, M. Vefa Bicakci wrote:
>> On 11/10/2016 06:31 PM, Boris Ostrovsky wrote:
>>> On 11/10/2016 10:05 AM, Charles (Chas) Williams wrote:
>>>>
>>>> On 11/10/2016 09:02 AM, Boris Ostrovsky wrote:
>>>>> On 11/10/2016 06:13 AM, Thomas Gleixner wrote:
>>>>>> On Thu, 10 Nov 2016, M. Vefa Bicakci wrote:
>>>>>>
>>>>>>> I have found that your patch unfortunately does not improve the
>>>>>>> situation
>>>>>>> for me. Here is an excerpt obtained from the dmesg of a kernel
>>>>>>> compiled
>>>>>>> with this patch *as well as* Sebastian's patch:
>>>>>>> [0.002561] CPU: Physical Processor ID: 0
>>>>>>> [0.002566] CPU: Processor Core ID: 0
>>>>>>> [0.002572] [Firmware Bug]: CPU0: APIC id mismatch. Firmware:
>>>>>>>  CPUID: 2
>>>>>> So apic->cpu_present_to_apicid() gives us a completely bogus APIC id
>>>>>> which
>>>>>> translates to a bogus package id. And looking at the XEN code:
>>>>>>
>>>>>>xen_pv_apic.cpu_present_to_apicid = xen_cpu_present_to_apicid,
>>>>>>
>>>>>> and xen_cpu_present_to_apicid does:
>>>>>>
>>>>>> static int xen_cpu_present_to_apicid(int cpu)
>>>>>> {
>>>>>> if (cpu_present(cpu))
>>>>>> return xen_get_apic_id(xen_apic_read(APIC_ID));
>>>>>> else
>>>>>> return BAD_APICID;
>>>>>> }
>>>>>>
>>>>>> So independent of which present CPU we query we get just some random
>>>>>> information, in the above case we get BAD_APICID from
>>>>>> xen_apic_read() not
>>>>>> from the else path as this CPU _IS_ present.
>>>>>>
>>>>>> What's so wrong with storing the fricking firmware supplied APICid as
>>>>>> everybody else does and report it back when queried?
>>>>> By firmware you mean ACPI? It is most likely not available to PV guests.
>>>>> How about returning cpu_data(cpu).initial_apicid?
>>>>>
>>>>> And what was the original problem?
>>>> The original issue I found was that VMware was returning a different set
>>>> of APIC id's in the ACPI tables than what it advertised on the CPU's.
>>>>
>>>> http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1266716.html
>>> For Xen, we recently added a6a198bc60e6 ("xen/x86: Update topology map
>>> for PV VCPUs") to at least temporarily work around some topology map
>>> problems that PV guests have with RAPL (which I think is what Vefa's
>>> problem was).
>> Hello Boris,
>>
>> (Sorry for the delay!)
>>
>> It appears that the problem is a bit different compared to the one
>> corrected by a6a198bc60e6, because my kernel tree -- based on 4.8.6 --
>> already includes the -stable backport of that commit, i.e.
>>   88540ad0820ddfb05626e0136c0e5a79cea85fd1
>>
>> The patch I included in my previous e-mail (dated 2016-11-10) corrects
>> root cause of the issue I am having with 4.8.6. Sebastian's original
>> patch adding error checking to the RAPL module prevents the RAPL module
>> from causing a kernel oops without my patch.
> 
> I don't see any messages from you on that date. Can you provide a link
> to it (and to Sebastian's patch)?
> 
> (BTW, generally it's a good idea to copy xen-devel list on any
> Xen-related issues).

As I explain below, it turns out that my issue was 'only' a kernel
configuration issue.

For reference, I had unknowingly solved my kernel-configuration-induced
issue via the patch at:
  https://marc.info/?l=linux-kernel=147875027314638=2

Sebastian's patch (which adds error handling to the RAPL module) is at:
  https://marc.info/?l=linux-kernel=147739814217598=2

>> The issue I am experiencing is caused by the boot-up code in the
>> 'init_apic_mappings' function switching the APIC ops structure from
>> Xen's structure to a no-op structure by calling the 'apic_disable'
>> function. Please let me know if I can clarify or elaborate.
> 
> apic_disable() is only invoked if there is no APIC present (i.e.
> detect_init_APIC() returns a non-zero value) and I don't think this can
> happen. Is your CPUID[1].edx[9] not set?

I found out that my domU kernels invoke 

Re: [PATCH] x86/cpuid: Deal with broken firmware once more

2016-11-12 Thread M. Vefa Bicakci
On 11/10/2016 01:50 PM, Charles (Chas) Williams wrote:
> 
> 
> On 11/09/2016 10:57 PM, M. Vefa Bicakci wrote:
>> [0.002000] mvb: CPU: Physical Processor ID: 0
>> [0.002000] mvb: CPU: Processor Core ID: 0
>> [0.002000] mvb: identify_cpu:1112: c: 880013b0a040,
>> c->logical_proc_id: 65535
>> [0.002000] mvb: __default_cpu_present_to_apicid:612: Returning
>> 65535! mps_cpu: 1, nr_cpu_ids: 2, cpu_present(mps_cpu): 1
>> [0.002000] smpboot: mvb: topology_update_package_map:270: cpu: 1,
>> pkg: 4095
>> [0.002000] smpboot: APIC() Converting physical 4095 to logical
>> package 0
>> [0.002000] smpboot: mvb: topology_update_package_map:305: cpu: 1,
>> cpu_data(cpu).logical_proc_id: 0
> 
> This seems strange.  0x is BAD_APICID.  Why didn't this fail here:
> 
> for_each_present_cpu(cpu) {
> unsigned int apicid = apic->cpu_present_to_apicid(cpu);
> 
> if (apicid == BAD_APICID ||
> !apic->apic_id_valid(apicid))  <<<<<<<<<<
> continue;
> if (!topology_update_package_map(apicid, cpu))
> continue;
> 
> topology_update_package_map() should never have been called?

(Sorry for the delay!)

It appears that this is a different call path than the one in
smp_init_package_map function. I *think* the following call path is the
one shown in the dmesg, but I am not sure:

cpu_bringup_and_idle
  cpu_bringup (arch/x86/xen/smp.c)
smp_store_cpu_info (this call path branch is included for context)
  identify_secondary_cpu
identify_cpu
  detect_ht
topology_update_package_map

Sorry about the potentially misleading dmesg excerpt I posted.

Vefa


Re: [PATCH] x86/cpuid: Deal with broken firmware once more

2016-11-12 Thread M. Vefa Bicakci
On 11/10/2016 06:31 PM, Boris Ostrovsky wrote:
> On 11/10/2016 10:05 AM, Charles (Chas) Williams wrote:
>>
>>
>> On 11/10/2016 09:02 AM, Boris Ostrovsky wrote:
>>> On 11/10/2016 06:13 AM, Thomas Gleixner wrote:
>>>> On Thu, 10 Nov 2016, M. Vefa Bicakci wrote:
>>>>
>>>>> I have found that your patch unfortunately does not improve the
>>>>> situation
>>>>> for me. Here is an excerpt obtained from the dmesg of a kernel
>>>>> compiled
>>>>> with this patch *as well as* Sebastian's patch:
>>>>> [0.002561] CPU: Physical Processor ID: 0
>>>>> [0.002566] CPU: Processor Core ID: 0
>>>>> [0.002572] [Firmware Bug]: CPU0: APIC id mismatch. Firmware:
>>>>>  CPUID: 2
>>>> So apic->cpu_present_to_apicid() gives us a completely bogus APIC id
>>>> which
>>>> translates to a bogus package id. And looking at the XEN code:
>>>>
>>>>xen_pv_apic.cpu_present_to_apicid = xen_cpu_present_to_apicid,
>>>>
>>>> and xen_cpu_present_to_apicid does:
>>>>
>>>> static int xen_cpu_present_to_apicid(int cpu)
>>>> {
>>>> if (cpu_present(cpu))
>>>> return xen_get_apic_id(xen_apic_read(APIC_ID));
>>>> else
>>>> return BAD_APICID;
>>>> }
>>>>
>>>> So independent of which present CPU we query we get just some random
>>>> information, in the above case we get BAD_APICID from
>>>> xen_apic_read() not
>>>> from the else path as this CPU _IS_ present.
>>>>
>>>> What's so wrong with storing the fricking firmware supplied APICid as
>>>> everybody else does and report it back when queried?
>>>
>>> By firmware you mean ACPI? It is most likely not available to PV guests.
>>> How about returning cpu_data(cpu).initial_apicid?
>>>
>>> And what was the original problem?
>>
>> The original issue I found was that VMware was returning a different set
>> of APIC id's in the ACPI tables than what it advertised on the CPU's.
>>
>> http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1266716.html
> 
> For Xen, we recently added a6a198bc60e6 ("xen/x86: Update topology map
> for PV VCPUs") to at least temporarily work around some topology map
> problems that PV guests have with RAPL (which I think is what Vefa's
> problem was).

Hello Boris,

(Sorry for the delay!)

It appears that the problem is a bit different compared to the one
corrected by a6a198bc60e6, because my kernel tree -- based on 4.8.6 --
already includes the -stable backport of that commit, i.e.
  88540ad0820ddfb05626e0136c0e5a79cea85fd1

The patch I included in my previous e-mail (dated 2016-11-10) corrects
root cause of the issue I am having with 4.8.6. Sebastian's original
patch adding error checking to the RAPL module prevents the RAPL module
from causing a kernel oops without my patch.

The issue I am experiencing is caused by the boot-up code in the
'init_apic_mappings' function switching the APIC ops structure from
Xen's structure to a no-op structure by calling the 'apic_disable'
function. Please let me know if I can clarify or elaborate.

For the record, using 4.8.7 without my correction patch patch does not
rectify the issue at hand. 4.8.7 changes the call site of the
'init_apic_mapping' function, so I had thought that it could be helpful.

Thank you,

Vefa


Re: [PATCH] x86/cpuid: Deal with broken firmware once more

2016-11-12 Thread M. Vefa Bicakci
On 11/10/2016 01:50 PM, Charles (Chas) Williams wrote:
> 
> 
> On 11/09/2016 10:57 PM, M. Vefa Bicakci wrote:
>> [0.002000] mvb: CPU: Physical Processor ID: 0
>> [0.002000] mvb: CPU: Processor Core ID: 0
>> [0.002000] mvb: identify_cpu:1112: c: 880013b0a040,
>> c->logical_proc_id: 65535
>> [0.002000] mvb: __default_cpu_present_to_apicid:612: Returning
>> 65535! mps_cpu: 1, nr_cpu_ids: 2, cpu_present(mps_cpu): 1
>> [0.002000] smpboot: mvb: topology_update_package_map:270: cpu: 1,
>> pkg: 4095
>> [0.002000] smpboot: APIC() Converting physical 4095 to logical
>> package 0
>> [0.002000] smpboot: mvb: topology_update_package_map:305: cpu: 1,
>> cpu_data(cpu).logical_proc_id: 0
> 
> This seems strange.  0x is BAD_APICID.  Why didn't this fail here:
> 
> for_each_present_cpu(cpu) {
> unsigned int apicid = apic->cpu_present_to_apicid(cpu);
> 
> if (apicid == BAD_APICID ||
> !apic->apic_id_valid(apicid))  <<<<<<<<<<
> continue;
> if (!topology_update_package_map(apicid, cpu))
> continue;
> 
> topology_update_package_map() should never have been called?

(Sorry for the delay!)

It appears that this is a different call path than the one in
smp_init_package_map function. I *think* the following call path is the
one shown in the dmesg, but I am not sure:

cpu_bringup_and_idle
  cpu_bringup (arch/x86/xen/smp.c)
smp_store_cpu_info (this call path branch is included for context)
  identify_secondary_cpu
identify_cpu
  detect_ht
topology_update_package_map

Sorry about the potentially misleading dmesg excerpt I posted.

Vefa


Re: [PATCH] x86/cpuid: Deal with broken firmware once more

2016-11-12 Thread M. Vefa Bicakci
On 11/10/2016 06:31 PM, Boris Ostrovsky wrote:
> On 11/10/2016 10:05 AM, Charles (Chas) Williams wrote:
>>
>>
>> On 11/10/2016 09:02 AM, Boris Ostrovsky wrote:
>>> On 11/10/2016 06:13 AM, Thomas Gleixner wrote:
>>>> On Thu, 10 Nov 2016, M. Vefa Bicakci wrote:
>>>>
>>>>> I have found that your patch unfortunately does not improve the
>>>>> situation
>>>>> for me. Here is an excerpt obtained from the dmesg of a kernel
>>>>> compiled
>>>>> with this patch *as well as* Sebastian's patch:
>>>>> [0.002561] CPU: Physical Processor ID: 0
>>>>> [0.002566] CPU: Processor Core ID: 0
>>>>> [0.002572] [Firmware Bug]: CPU0: APIC id mismatch. Firmware:
>>>>>  CPUID: 2
>>>> So apic->cpu_present_to_apicid() gives us a completely bogus APIC id
>>>> which
>>>> translates to a bogus package id. And looking at the XEN code:
>>>>
>>>>xen_pv_apic.cpu_present_to_apicid = xen_cpu_present_to_apicid,
>>>>
>>>> and xen_cpu_present_to_apicid does:
>>>>
>>>> static int xen_cpu_present_to_apicid(int cpu)
>>>> {
>>>> if (cpu_present(cpu))
>>>> return xen_get_apic_id(xen_apic_read(APIC_ID));
>>>> else
>>>> return BAD_APICID;
>>>> }
>>>>
>>>> So independent of which present CPU we query we get just some random
>>>> information, in the above case we get BAD_APICID from
>>>> xen_apic_read() not
>>>> from the else path as this CPU _IS_ present.
>>>>
>>>> What's so wrong with storing the fricking firmware supplied APICid as
>>>> everybody else does and report it back when queried?
>>>
>>> By firmware you mean ACPI? It is most likely not available to PV guests.
>>> How about returning cpu_data(cpu).initial_apicid?
>>>
>>> And what was the original problem?
>>
>> The original issue I found was that VMware was returning a different set
>> of APIC id's in the ACPI tables than what it advertised on the CPU's.
>>
>> http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1266716.html
> 
> For Xen, we recently added a6a198bc60e6 ("xen/x86: Update topology map
> for PV VCPUs") to at least temporarily work around some topology map
> problems that PV guests have with RAPL (which I think is what Vefa's
> problem was).

Hello Boris,

(Sorry for the delay!)

It appears that the problem is a bit different compared to the one
corrected by a6a198bc60e6, because my kernel tree -- based on 4.8.6 --
already includes the -stable backport of that commit, i.e.
  88540ad0820ddfb05626e0136c0e5a79cea85fd1

The patch I included in my previous e-mail (dated 2016-11-10) corrects
root cause of the issue I am having with 4.8.6. Sebastian's original
patch adding error checking to the RAPL module prevents the RAPL module
from causing a kernel oops without my patch.

The issue I am experiencing is caused by the boot-up code in the
'init_apic_mappings' function switching the APIC ops structure from
Xen's structure to a no-op structure by calling the 'apic_disable'
function. Please let me know if I can clarify or elaborate.

For the record, using 4.8.7 without my correction patch patch does not
rectify the issue at hand. 4.8.7 changes the call site of the
'init_apic_mapping' function, so I had thought that it could be helpful.

Thank you,

Vefa


Re: [PATCH] x86/cpuid: Deal with broken firmware once more

2016-11-09 Thread M. Vefa Bicakci
On 11/09/2016 06:35 PM, Thomas Gleixner wrote:
> Both ACPI and MP specifications require that the APIC id in the respective
> tables must be the same as the APIC id in CPUID. 
> 
> The kernel retrieves the physical package id from the APIC id during the
> ACPI/MP table scan and builds the physical to logical package map.
> 
> There exist Virtualbox and Xen implementations which violate the spec. As a
> result the physical to logical package map, which relies on the ACPI/MP
> tables does not work on those systems, because the CPUID initialized
> physical package id does not match the firmware id. This causes system
> crashes and malfunction due to invalid package mappings.
> 
> The only way to cure this is to sanitize the physical package id after the
> CPUID enumeration and yell when the APIC ids are different. If the physical
> package IDs differ use the package information from the ACPI/MP tables so
> the existing logical package map just works.
> 
> Reported-by: "Charles (Chas) Williams" <ciwil...@brocade.com>,
> Reported-by: M. Vefa Bicakci <m@runbox.com>
> Signed-off-by: Thomas Gleixner <t...@linutronix.de>

Hello Thomas and Sebastian,

Sorry for the delay in reporting what I have found out and for the delay in 
testing this patch, which has been due to my health.

I have found that your patch unfortunately does not improve the situation for 
me. Here is an excerpt obtained from the dmesg of a kernel compiled with this 
patch *as well as* Sebastian's patch:

=== 8< ===
[0.002561] CPU: Physical Processor ID: 0

[0.002566] CPU: Processor Core ID: 0

[0.002572] [Firmware Bug]: CPU0: APIC id mismatch. Firmware:  CPUID: 2

[0.002577] [Firmware Bug]: CPU0: Using firmware package id 4095 instead of 0

[0.002586] Last level iTLB entries: 4KB 512, 2MB 8, 4MB 8

[0.002591] Last level dTLB entries: 4KB 512, 2MB 32, 4MB 32, 1GB 0

[0.033319] ftrace: allocating 28753 entries in 113 pages

[0.040121] cpu 0 spinlock event irq 1

[0.040145] smpboot: Max logical packages: 1

[0.040155] VPMU disabled by hypervisor.

[0.040181] Performance Events: unsupported p6 CPU model 42 no PMU driver, 
software events only.

[0.047050] NMI watchdog: disabled (cpu0): hardware events not enabled

[0.047065] NMI watchdog: Shutting down hard lockup detector on all cpus

[0.052015] installing Xen timer for CPU 1

[0.052074] SMP alternatives: switching to SMP code

[0.002000] Disabled fast string operations

[0.002000] [Firmware Bug]: CPU1: APIC id mismatch. Firmware:  CPUID: 2

[0.002000] [Firmware Bug]: CPU1: Using firmware package id 4095 instead of 0

[0.002000] smpboot: APIC() Converting physical 4095 to logical package 0

[0.078061] cpu 1 spinlock event irq 13

...
[0.216404] Freeing initrd memory: 4340K (880001fa7000 - 
8800023e4000)

[0.216487] RAPL PMU: rapl pmu error: max package: 1 but CPU0 belongs to 
65535

[0.217572] futex hash table entries: 512 (order: 3, 32768 bytes)

[0.218293] Initialise system trusted keyrings

...
[0.216404] Freeing initrd memory: 4340K (880001fa7000 - 
8800023e4000)

[0.216487] RAPL PMU: rapl pmu error: max package: 1 but CPU0 belongs to 
65535

[0.217572] futex hash table entries: 512 (order: 3, 32768 bytes)

...
[2.974474] intel_rapl: Found RAPL domain package

[2.974489] intel_rapl: Found RAPL domain core

[2.974498] intel_rapl: Found RAPL domain uncore

[2.974518] intel_rapl: RAPL package 4095 domain package locked by BIOS

=== >8 ===

As you can see, your patch unfortunately does not correct the issue with the 
virtual CPU package identifiers in Xen-based virtual machines using 
para-virtualization.

In summary, the root cause of the issue for me appears to be that the boot-up 
code in the init_apic_mappings function switches the APIC 'ops' structure from 
Xen's 'ops' structure to the no-op ops structure. Due to this, the 
smp_init_package_map uses the no-op APIC ops structure's 
cpu_present_to_to_apicid function, even though it should use the corresponding 
method from Xen's APIC ops structure (i.e., xen_cpu_present_to_apicid).

Here is a dmesg excerpt with a kernel patched with Sebastian's patch (and some 
debugging code), exhibiting the issue I have just explained: (Note the 
'switched to apic NOOP' line.)

=== 8< ===
(early) [0.00] SFI: Simple Firmware Interface v0.81 
http://simplefirmware.org
(early) [0.00] smpboot: Allowing 2 CPUs, 0 hotplug CPUs
(early) [0.00] No local APIC present
(early) [0.00] APIC: disable apic facility
(early) [0.00] APIC: switched to apic NOOP
(early) [0.00] e820: [mem 0xfa00-0x] available for PCI 
devices
(early) [0.00] Booting paravirtualized kernel on Xen
...
[0.034082] mvb: kernel_init_freeable:1007: About to call smp_prepare_cpus..

Re: [PATCH] x86/cpuid: Deal with broken firmware once more

2016-11-09 Thread M. Vefa Bicakci
On 11/09/2016 06:35 PM, Thomas Gleixner wrote:
> Both ACPI and MP specifications require that the APIC id in the respective
> tables must be the same as the APIC id in CPUID. 
> 
> The kernel retrieves the physical package id from the APIC id during the
> ACPI/MP table scan and builds the physical to logical package map.
> 
> There exist Virtualbox and Xen implementations which violate the spec. As a
> result the physical to logical package map, which relies on the ACPI/MP
> tables does not work on those systems, because the CPUID initialized
> physical package id does not match the firmware id. This causes system
> crashes and malfunction due to invalid package mappings.
> 
> The only way to cure this is to sanitize the physical package id after the
> CPUID enumeration and yell when the APIC ids are different. If the physical
> package IDs differ use the package information from the ACPI/MP tables so
> the existing logical package map just works.
> 
> Reported-by: "Charles (Chas) Williams" ,
> Reported-by: M. Vefa Bicakci 
> Signed-off-by: Thomas Gleixner 

Hello Thomas and Sebastian,

Sorry for the delay in reporting what I have found out and for the delay in 
testing this patch, which has been due to my health.

I have found that your patch unfortunately does not improve the situation for 
me. Here is an excerpt obtained from the dmesg of a kernel compiled with this 
patch *as well as* Sebastian's patch:

=== 8< ===
[0.002561] CPU: Physical Processor ID: 0

[0.002566] CPU: Processor Core ID: 0

[0.002572] [Firmware Bug]: CPU0: APIC id mismatch. Firmware:  CPUID: 2

[0.002577] [Firmware Bug]: CPU0: Using firmware package id 4095 instead of 0

[0.002586] Last level iTLB entries: 4KB 512, 2MB 8, 4MB 8

[0.002591] Last level dTLB entries: 4KB 512, 2MB 32, 4MB 32, 1GB 0

[0.033319] ftrace: allocating 28753 entries in 113 pages

[0.040121] cpu 0 spinlock event irq 1

[0.040145] smpboot: Max logical packages: 1

[0.040155] VPMU disabled by hypervisor.

[0.040181] Performance Events: unsupported p6 CPU model 42 no PMU driver, 
software events only.

[0.047050] NMI watchdog: disabled (cpu0): hardware events not enabled

[0.047065] NMI watchdog: Shutting down hard lockup detector on all cpus

[0.052015] installing Xen timer for CPU 1

[0.052074] SMP alternatives: switching to SMP code

[0.002000] Disabled fast string operations

[0.002000] [Firmware Bug]: CPU1: APIC id mismatch. Firmware:  CPUID: 2

[0.002000] [Firmware Bug]: CPU1: Using firmware package id 4095 instead of 0

[0.002000] smpboot: APIC() Converting physical 4095 to logical package 0

[0.078061] cpu 1 spinlock event irq 13

...
[0.216404] Freeing initrd memory: 4340K (880001fa7000 - 
8800023e4000)

[0.216487] RAPL PMU: rapl pmu error: max package: 1 but CPU0 belongs to 
65535

[0.217572] futex hash table entries: 512 (order: 3, 32768 bytes)

[0.218293] Initialise system trusted keyrings

...
[0.216404] Freeing initrd memory: 4340K (880001fa7000 - 
8800023e4000)

[0.216487] RAPL PMU: rapl pmu error: max package: 1 but CPU0 belongs to 
65535

[0.217572] futex hash table entries: 512 (order: 3, 32768 bytes)

...
[2.974474] intel_rapl: Found RAPL domain package

[2.974489] intel_rapl: Found RAPL domain core

[2.974498] intel_rapl: Found RAPL domain uncore

[2.974518] intel_rapl: RAPL package 4095 domain package locked by BIOS

=== >8 ===

As you can see, your patch unfortunately does not correct the issue with the 
virtual CPU package identifiers in Xen-based virtual machines using 
para-virtualization.

In summary, the root cause of the issue for me appears to be that the boot-up 
code in the init_apic_mappings function switches the APIC 'ops' structure from 
Xen's 'ops' structure to the no-op ops structure. Due to this, the 
smp_init_package_map uses the no-op APIC ops structure's 
cpu_present_to_to_apicid function, even though it should use the corresponding 
method from Xen's APIC ops structure (i.e., xen_cpu_present_to_apicid).

Here is a dmesg excerpt with a kernel patched with Sebastian's patch (and some 
debugging code), exhibiting the issue I have just explained: (Note the 
'switched to apic NOOP' line.)

=== 8< ===
(early) [0.00] SFI: Simple Firmware Interface v0.81 
http://simplefirmware.org
(early) [0.00] smpboot: Allowing 2 CPUs, 0 hotplug CPUs
(early) [0.00] No local APIC present
(early) [0.00] APIC: disable apic facility
(early) [0.00] APIC: switched to apic NOOP
(early) [0.00] e820: [mem 0xfa00-0x] available for PCI 
devices
(early) [0.00] Booting paravirtualized kernel on Xen
...
[0.034082] mvb: kernel_init_freeable:1007: About to call smp_prepare_cpus...
[0.034123] cpu 0 spinlock event irq 1
[0.034138] smpboot: mvb: smp

Re: [PREEMPT-RT] Oops in rapl_cpu_prepare()

2016-11-03 Thread M. Vefa Bicakci
On 11/02/2016 08:23 PM, Sebastian Andrzej Siewior wrote:
> On 2016-11-01 13:15:53 [+0300], M. Vefa Bicakci wrote:
>> Hello Sebastian,
>
> Hi,
> 
>> The patch fixes the kernel oops for me.
>>
>> I am using a custom 4.8.5-based kernel on Qubes OS R3.2, which is based
>> on Xen 4.6.3. Apparently, Xen also has a similar bug/flaw/quirk regarding
>> the allocation of package identifiers for the virtual CPUs.
>>
>> Prior to your patch, my Xen-based virtual machines would intermittently
>> crash most of the time at boot-up with the backtrace reported by Charles.
>> Due to this, I was under the impression that this is a subtle race
>> condition.
> 
> how hard is it to get such a xen setup up and running?

Hello Sebastian,

Sorry about my late reply!

The set-up I use is a bit involved/complicated. To replicate it, you
would need to install Qubes OS R3.2 (assuming that you have compatible
hardware with a lot of RAM) and then build a custom 4.8.y-based kernel
with a set of cherry-picked commits. After installing this kernel in
dom0 with dnf or rpm, you would need to run:

  # Generate a domU initrd and copy the kernel image and the generated
  # initrd to Qubes OS's domU kernel directory (/var/lib/qubes/...)
  $ sudo /usr/sbin/qubes-prepare-vm-kernel 

  # From now on, use kernel_version when starting domU instances.
  $ qubes-prefs -s default-kernel 

Afterwards, starting a domU (i.e., AppVM in Qubes OS terminology) should
exhibit the issue in question related to RAPL:

  $ sudo truncate -s0 /var/log/xen/console/guest-.log
  $ qvm-start --debug 
  $ cat /var/log/xen/console/guest-.log

As you may appreciate, the set-up is a bit involved. Nevertheless, in
case you would like to replicate my set-up, I can try to publish my
linux-4.8.y-based git branch so that you can build a similar kernel as
the one I use.

Vefa


Re: [PREEMPT-RT] Oops in rapl_cpu_prepare()

2016-11-03 Thread M. Vefa Bicakci
On 11/02/2016 08:23 PM, Sebastian Andrzej Siewior wrote:
> On 2016-11-01 13:15:53 [+0300], M. Vefa Bicakci wrote:
>> Hello Sebastian,
>
> Hi,
> 
>> The patch fixes the kernel oops for me.
>>
>> I am using a custom 4.8.5-based kernel on Qubes OS R3.2, which is based
>> on Xen 4.6.3. Apparently, Xen also has a similar bug/flaw/quirk regarding
>> the allocation of package identifiers for the virtual CPUs.
>>
>> Prior to your patch, my Xen-based virtual machines would intermittently
>> crash most of the time at boot-up with the backtrace reported by Charles.
>> Due to this, I was under the impression that this is a subtle race
>> condition.
> 
> how hard is it to get such a xen setup up and running?

Hello Sebastian,

Sorry about my late reply!

The set-up I use is a bit involved/complicated. To replicate it, you
would need to install Qubes OS R3.2 (assuming that you have compatible
hardware with a lot of RAM) and then build a custom 4.8.y-based kernel
with a set of cherry-picked commits. After installing this kernel in
dom0 with dnf or rpm, you would need to run:

  # Generate a domU initrd and copy the kernel image and the generated
  # initrd to Qubes OS's domU kernel directory (/var/lib/qubes/...)
  $ sudo /usr/sbin/qubes-prepare-vm-kernel 

  # From now on, use kernel_version when starting domU instances.
  $ qubes-prefs -s default-kernel 

Afterwards, starting a domU (i.e., AppVM in Qubes OS terminology) should
exhibit the issue in question related to RAPL:

  $ sudo truncate -s0 /var/log/xen/console/guest-.log
  $ qvm-start --debug 
  $ cat /var/log/xen/console/guest-.log

As you may appreciate, the set-up is a bit involved. Nevertheless, in
case you would like to replicate my set-up, I can try to publish my
linux-4.8.y-based git branch so that you can build a similar kernel as
the one I use.

Vefa


Re: [PREEMPT-RT] Oops in rapl_cpu_prepare()

2016-11-01 Thread M. Vefa Bicakci
> On 2016-10-27 15:00:32 [-0400], Charles (Chas) Williams wrote:
>>
>> [snip]
>>
>> But sometimes the topology info is correct and if I get lucky, the
>> package id could be valid for all the CPU's.  Given the behavior,
>> I have seen so far it makes me thing the RAPL isn't being emulated.
>> So even if I did boot onto a "valid" set of cores, would I always be
>> certain that I will be on those cores?
> 
> I don't what vmware does here. Nor do they ship source to check. So if
> you have a big HW box with say two packages, it might make sense to give
> this information to the guest _if_ the CPUs are pinned and the guest
> never migrates.
> 
>> Per your request in your next email:
>> 
>> > One thing I forgot to ask: Could you please check if you get the same
>> > pkgid reported for cpu 0-3 on a pre-v4.8 kernel? (before the hotplug
>> > rework).
>> 
>> Our previous kernel was 4.4, and didn't use the logical package id:
>
> I see.
> 
> Did the patch I sent fixed it for you and were you not able to test?

Hello Sebastian,

The patch fixes the kernel oops for me.

I am using a custom 4.8.5-based kernel on Qubes OS R3.2, which is based
on Xen 4.6.3. Apparently, Xen also has a similar bug/flaw/quirk regarding
the allocation of package identifiers for the virtual CPUs.

Prior to your patch, my Xen-based virtual machines would intermittently
crash most of the time at boot-up with the backtrace reported by Charles.
Due to this, I was under the impression that this is a subtle race
condition.

With your patch, the virtual machines boot-up successfully, all the time.
Here are the relevant excerpts from dmesg:

=== 8< ===
[0.263936] RAPL PMU: rapl pmu error: max package: 1 but CPU0 belongs to 
65535
...
[2.213669] intel_rapl: Found RAPL domain package
[2.213689] intel_rapl: Found RAPL domain core
[2.216337] intel_rapl: Found RAPL domain uncore
[2.216370] intel_rapl: RAPL package 0 domain package locked by BIOS
=== >8 ===

Thank you,

Vefa

Please note: I am not subscribed to the Linux kernel mailing list, so
I had to manually construct the headers of this reply with the proper
In-Reply-To and References values (which were extracted from marc.info).
As a result, this e-mail may not show up as a reply to your earlier
conversation with Charles.



Re: [PREEMPT-RT] Oops in rapl_cpu_prepare()

2016-11-01 Thread M. Vefa Bicakci
> On 2016-10-27 15:00:32 [-0400], Charles (Chas) Williams wrote:
>>
>> [snip]
>>
>> But sometimes the topology info is correct and if I get lucky, the
>> package id could be valid for all the CPU's.  Given the behavior,
>> I have seen so far it makes me thing the RAPL isn't being emulated.
>> So even if I did boot onto a "valid" set of cores, would I always be
>> certain that I will be on those cores?
> 
> I don't what vmware does here. Nor do they ship source to check. So if
> you have a big HW box with say two packages, it might make sense to give
> this information to the guest _if_ the CPUs are pinned and the guest
> never migrates.
> 
>> Per your request in your next email:
>> 
>> > One thing I forgot to ask: Could you please check if you get the same
>> > pkgid reported for cpu 0-3 on a pre-v4.8 kernel? (before the hotplug
>> > rework).
>> 
>> Our previous kernel was 4.4, and didn't use the logical package id:
>
> I see.
> 
> Did the patch I sent fixed it for you and were you not able to test?

Hello Sebastian,

The patch fixes the kernel oops for me.

I am using a custom 4.8.5-based kernel on Qubes OS R3.2, which is based
on Xen 4.6.3. Apparently, Xen also has a similar bug/flaw/quirk regarding
the allocation of package identifiers for the virtual CPUs.

Prior to your patch, my Xen-based virtual machines would intermittently
crash most of the time at boot-up with the backtrace reported by Charles.
Due to this, I was under the impression that this is a subtle race
condition.

With your patch, the virtual machines boot-up successfully, all the time.
Here are the relevant excerpts from dmesg:

=== 8< ===
[0.263936] RAPL PMU: rapl pmu error: max package: 1 but CPU0 belongs to 
65535
...
[2.213669] intel_rapl: Found RAPL domain package
[2.213689] intel_rapl: Found RAPL domain core
[2.216337] intel_rapl: Found RAPL domain uncore
[2.216370] intel_rapl: RAPL package 0 domain package locked by BIOS
=== >8 ===

Thank you,

Vefa

Please note: I am not subscribed to the Linux kernel mailing list, so
I had to manually construct the headers of this reply with the proper
In-Reply-To and References values (which were extracted from marc.info).
As a result, this e-mail may not show up as a reply to your earlier
conversation with Charles.



[PATCH 0/2] staging: lustre: Correct two minor issues found by sparse

2016-02-28 Thread M. Vefa Bicakci
The patches in this series correct two minor issues found by sparse in
staging/lustre.

These patches were tested with compilation only; given their nature, I
hope/believe this is sufficient. The patches apply cleanly onto commit
2cda64cf6998 ("staging: unisys: visorbus: Remove useless return variables")
which points to the tip of the staging-next and staging-testing branches
as of now.

M. Vefa Bicakci (2):
  staging: lustre: Use const static file_operations struct
  staging: lustre: Use __user for a pointer to a user space address

 drivers/staging/lustre/lustre/libcfs/module.c   | 2 +-
 drivers/staging/lustre/lustre/obdclass/lprocfs_status.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

-- 
2.5.0



[PATCH 0/2] staging: lustre: Correct two minor issues found by sparse

2016-02-28 Thread M. Vefa Bicakci
The patches in this series correct two minor issues found by sparse in
staging/lustre.

These patches were tested with compilation only; given their nature, I
hope/believe this is sufficient. The patches apply cleanly onto commit
2cda64cf6998 ("staging: unisys: visorbus: Remove useless return variables")
which points to the tip of the staging-next and staging-testing branches
as of now.

M. Vefa Bicakci (2):
  staging: lustre: Use const static file_operations struct
  staging: lustre: Use __user for a pointer to a user space address

 drivers/staging/lustre/lustre/libcfs/module.c   | 2 +-
 drivers/staging/lustre/lustre/obdclass/lprocfs_status.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

-- 
2.5.0



[PATCH 2/2] staging: lustre: Use __user for a pointer to a user space address

2016-02-28 Thread M. Vefa Bicakci
This commit corrects two sparse warnings caused by the lack of a __user
annotation for the third argument of the libcfs_ioctl_handle function.

  module.c:165:68: warning: incorrect type in argument 1
(different address spaces)
  module.c:165:68:expected void [noderef] *arg
  module.c:165:68:got void *arg
  module.c:209:47: warning: incorrect type in argument 3
(different address spaces)
  module.c:209:47:expected void *arg
  module.c:209:47:got void [noderef] *arg

The need to have the __user annotation is supported by the fact that
libcfs_ioctl_handle passes its third argument to a helper function
(libcfs_ioctl_popdata) which also has a __user annotation for its
corresponding argument.

Signed-off-by: M. Vefa Bicakci <m@runbox.com>
---
 drivers/staging/lustre/lustre/libcfs/module.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/lustre/lustre/libcfs/module.c 
b/drivers/staging/lustre/lustre/libcfs/module.c
index 05e2c5625220..f3845dcee259 100644
--- a/drivers/staging/lustre/lustre/libcfs/module.c
+++ b/drivers/staging/lustre/lustre/libcfs/module.c
@@ -120,7 +120,7 @@ int libcfs_deregister_ioctl(struct libcfs_ioctl_handler 
*hand)
 EXPORT_SYMBOL(libcfs_deregister_ioctl);
 
 static int libcfs_ioctl_handle(struct cfs_psdev_file *pfile, unsigned long cmd,
-  void *arg, struct libcfs_ioctl_hdr *hdr)
+  void __user *arg, struct libcfs_ioctl_hdr *hdr)
 {
struct libcfs_ioctl_data *data = NULL;
int err = -EINVAL;
-- 
2.5.0



[PATCH 1/2] staging: lustre: Use const static file_operations struct

2016-02-28 Thread M. Vefa Bicakci
This commit corrects the following sparse warning regarding a
file_operations structure being non-static and constifies the
structure in question as well.

  warning: symbol 'lprocfs_stats_seq_fops' was not declared.
Should it be static?

Signed-off-by: M. Vefa Bicakci <m@runbox.com>
---
 drivers/staging/lustre/lustre/obdclass/lprocfs_status.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c 
b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
index 28bb4e53adaa..1c39e90979df 100644
--- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
@@ -1196,7 +1196,7 @@ static int lprocfs_stats_seq_open(struct inode *inode, 
struct file *file)
return 0;
 }
 
-struct file_operations lprocfs_stats_seq_fops = {
+static const struct file_operations lprocfs_stats_seq_fops = {
.owner   = THIS_MODULE,
.open= lprocfs_stats_seq_open,
.read= seq_read,
-- 
2.5.0



[PATCH 2/2] staging: lustre: Use __user for a pointer to a user space address

2016-02-28 Thread M. Vefa Bicakci
This commit corrects two sparse warnings caused by the lack of a __user
annotation for the third argument of the libcfs_ioctl_handle function.

  module.c:165:68: warning: incorrect type in argument 1
(different address spaces)
  module.c:165:68:expected void [noderef] *arg
  module.c:165:68:got void *arg
  module.c:209:47: warning: incorrect type in argument 3
(different address spaces)
  module.c:209:47:expected void *arg
  module.c:209:47:got void [noderef] *arg

The need to have the __user annotation is supported by the fact that
libcfs_ioctl_handle passes its third argument to a helper function
(libcfs_ioctl_popdata) which also has a __user annotation for its
corresponding argument.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/lustre/lustre/libcfs/module.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/lustre/lustre/libcfs/module.c 
b/drivers/staging/lustre/lustre/libcfs/module.c
index 05e2c5625220..f3845dcee259 100644
--- a/drivers/staging/lustre/lustre/libcfs/module.c
+++ b/drivers/staging/lustre/lustre/libcfs/module.c
@@ -120,7 +120,7 @@ int libcfs_deregister_ioctl(struct libcfs_ioctl_handler 
*hand)
 EXPORT_SYMBOL(libcfs_deregister_ioctl);
 
 static int libcfs_ioctl_handle(struct cfs_psdev_file *pfile, unsigned long cmd,
-  void *arg, struct libcfs_ioctl_hdr *hdr)
+  void __user *arg, struct libcfs_ioctl_hdr *hdr)
 {
struct libcfs_ioctl_data *data = NULL;
int err = -EINVAL;
-- 
2.5.0



[PATCH 1/2] staging: lustre: Use const static file_operations struct

2016-02-28 Thread M. Vefa Bicakci
This commit corrects the following sparse warning regarding a
file_operations structure being non-static and constifies the
structure in question as well.

  warning: symbol 'lprocfs_stats_seq_fops' was not declared.
Should it be static?

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/lustre/lustre/obdclass/lprocfs_status.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c 
b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
index 28bb4e53adaa..1c39e90979df 100644
--- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
@@ -1196,7 +1196,7 @@ static int lprocfs_stats_seq_open(struct inode *inode, 
struct file *file)
return 0;
 }
 
-struct file_operations lprocfs_stats_seq_fops = {
+static const struct file_operations lprocfs_stats_seq_fops = {
.owner   = THIS_MODULE,
.open= lprocfs_stats_seq_open,
.read= seq_read,
-- 
2.5.0



[PATCH v5 07/15] staging: rtl8723au: Remove unneeded curly braces

2015-03-28 Thread M. Vefa Bicakci
Correct a number of checkpatch.pl warnings in rtl8723au's rtw_security.c
related to the existence of unnecessary curly braces around single
statement blocks:
WARNING: braces {} are not necessary for single statement blocks

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 16 +---
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index b85e5de5f136..e8efdcd06329 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -113,9 +113,8 @@ static void crc32_init(void)
for (i = 0; i < 256; ++i) {
k = crc32_reverseBit((u8)i);
 
-   for (c = ((u32)k) << 24, j = 8; j > 0; --j) {
+   for (c = ((u32)k) << 24, j = 8; j > 0; --j)
c = c & 0x8000 ? (c << 1) ^ CRC32_POLY : (c << 1);
-   }
 
p1 = (u8 *)_table[i];
 
@@ -264,9 +263,8 @@ static u32 secmicgetuint32(u8 *p)
s32 i;
u32 res = 0;
 
-   for (i = 0; i < 4; i++) {
+   for (i = 0; i < 4; i++)
res |= ((u32)(*p++)) << (8 * i);
-   }
 
return res;
 }
@@ -350,9 +348,8 @@ void rtw_secgetmic23a(struct mic_data *pmicdata, u8 *dst)
rtw_secmicappend23abyte23a(pmicdata, 0);
rtw_secmicappend23abyte23a(pmicdata, 0);
/*  and then zeroes until the length is a multiple of 4 */
-   while (pmicdata->nBytesInM != 0) {
+   while (pmicdata->nBytesInM != 0)
rtw_secmicappend23abyte23a(pmicdata, 0);
-   }
/*  The appendByte function has already computed the result. */
secmicputuint32(dst, pmicdata->L);
secmicputuint32(dst + 4, pmicdata->R);
@@ -888,10 +885,8 @@ static void byte_sub(u8 *in, u8 *out)
 {
int i;
 
-   for (i = 0; i < 16; i++) {
+   for (i = 0; i < 16; i++)
out[i] = sbox(in[i]);
-   }
-
 }
 
 static void shift_row(u8 *in, u8 *out)
@@ -952,9 +947,8 @@ static void mix_column(u8 *in, u8 *out)
 
for (i = 3; i > 0; i--) { /* logical shift left 1 bit */
andf7[i] = andf7[i] << 1;
-   if ((andf7[i - 1] & 0x80) == 0x80) {
+   if ((andf7[i - 1] & 0x80) == 0x80)
andf7[i] = (andf7[i] | 0x01);
-   }
}
andf7[0] = andf7[0] << 1;
andf7[0] = andf7[0] & 0xfe;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 01/15] staging: rtl8723au: Reformat whitespace to increase readability

2015-03-28 Thread M. Vefa Bicakci
Adjust the whitespace in the signature, local variable declaration and
initialization parts of a number of functions to increase readability
in rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci 

---

v2: Make sure that the arcfour_encrypt function's argument list is split
according to the kernel code style.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 79 +--
 1 file changed, 38 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index ea670afcc212..92882f60bc0e 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -31,11 +31,11 @@ struct arc4context {
 
 static void arcfour_init(struct arc4context *parc4ctx, u8 *key, u32 key_len)
 {
-   u32 t, u;
-   u32 keyindex;
-   u32 stateindex;
+   u32 t, u;
+   u32 keyindex;
+   u32 stateindex;
u8 *state;
-   u32 counter;
+   u32 counter;
 
state = parc4ctx->state;
parc4ctx->x = 0;
@@ -55,7 +55,8 @@ static void arcfour_init(struct arc4context *parc4ctx, u8 
*key, u32 key_len)
}
 
 }
-static u32 arcfour_byte(   struct arc4context  *parc4ctx)
+
+static u32 arcfour_byte(struct arc4context *parc4ctx)
 {
u32 x;
u32 y;
@@ -75,16 +76,13 @@ static u32 arcfour_byte(struct arc4context  
*parc4ctx)
return state[(sx + sy) & 0xff];
 }
 
-static void arcfour_encrypt(   struct arc4context  *parc4ctx,
-   u8 *dest,
-   u8 *src,
-   u32 len)
+static void arcfour_encrypt(struct arc4context *parc4ctx, u8 *dest,
+   u8 *src, u32 len)
 {
-   u32 i;
+   u32 i;
 
for (i = 0; i < len; i++)
dest[i] = src[i] ^ (unsigned char)arcfour_byte(parc4ctx);
-
 }
 
 static int bcrc32initialized;
@@ -365,7 +363,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
   u8 *mic_code, u8 pri)
 {
 
-   struct mic_data micdata;
+   struct mic_data micdata;
u8 priority[4]={0x0, 0x0, 0x0, 0x0};
 
rtw_secmicsetkey23a(, key);
@@ -601,21 +599,21 @@ static void phase2(u8 *rc4key, const u8 *tk, const u16 
*p1k, u16 iv16)
 int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
struct xmit_frame *pxmitframe)
 {
-   u16 pnl;
-   u32 pnh;
-   u8  rc4key[16];
-   u8   ttkey[16];
-   u8  crc[4];
-   u8   hw_hdr_offset = 0;
+   u16 pnl;
+   u32 pnh;
+   u8 rc4key[16];
+   u8 ttkey[16];
+   u8 crc[4];
+   u8 hw_hdr_offset = 0;
struct arc4context mycontext;
-   int curfragnum, length;
-   u32 prwskeylen;
-   u8  *pframe, *payload, *iv, *prwskey;
+   int curfragnum, length;
+   u32 prwskeylen;
+   u8 *pframe, *payload, *iv, *prwskey;
union pn48 dot11txpn;
-   struct  sta_info*stainfo;
-   struct  pkt_attrib   *pattrib = >attrib;
-   struct  security_priv   *psecuritypriv = >securitypriv;
-   struct  xmit_priv   *pxmitpriv = >xmitpriv;
+   struct sta_info *stainfo;
+   struct pkt_attrib *pattrib = >attrib;
+   struct security_priv *psecuritypriv = >securitypriv;
+   struct xmit_priv *pxmitpriv = >xmitpriv;
int res = _SUCCESS;
 
if (!pxmitframe->buf_addr)
@@ -708,17 +706,17 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 {
u16 pnl;
u32 pnh;
-   u8   rc4key[16];
-   u8   ttkey[16];
-   u8  crc[4];
+   u8 rc4key[16];
+   u8 ttkey[16];
+   u8 crc[4];
struct arc4context mycontext;
-   int length;
-   u32 prwskeylen;
-   u8  *pframe, *payload, *iv, *prwskey;
+   int length;
+   u32 prwskeylen;
+   u8 *pframe, *payload, *iv, *prwskey;
union pn48 dot11txpn;
-   struct  sta_info*stainfo;
-   struct  rx_pkt_attrib *prxattrib = >attrib;
-   struct  security_priv *psecuritypriv = >securitypriv;
+   struct sta_info *stainfo;
+   struct rx_pkt_attrib *prxattrib = >attrib;
+   struct security_priv *psecuritypriv = >securitypriv;
struct sk_buff *skb = precvframe->pkt;
int res = _SUCCESS;
 
@@ -1136,8 +1134,8 @@ static void bitwise_xor(u8 *ina, u8 *inb, u8 *out)
 
 static int aes_cipher(u8 *key, uint hdrlen, u8 *pframe, uint plen)
 {
-   uintqc_exists, a4_exists, i, j, payload_remainder,
-   num_blocks, payload_index;
+   uint qc_exists, a4_exists, i, j, payload_remainder,
+num_blocks, payload_index;
u8 pn_vector[6];
u8 mic_iv[16];
u8 mic_header1[16];
@@ -1353,12 +1351,11 @@ out:
return res;
 }
 
-static int aes_decipher(u8 *key, uint  hdrlen,
-   u8 *pframe, 

[PATCH v5 13/15] staging: rtl8723au: Rework two byte array comparisons

2015-03-28 Thread M. Vefa Bicakci
Prior to this commit, rtl8723au's rtw_security.c had two instances of
byte array comparisons (for CRC checks) where the individual elements
of the byte arrays were compared one by one and an error trace would
be output if the byte arrays were determined to be different.

This commit improves the readability of the CRC verification by
placing the individual 4 bytes of each byte array into an 32-bit
unsigned integer and comparing the two resulting integers.

Thanks to Larry Finger for spotting the code style issues in the
previous version of this commit, and thanks to Joe Perches for
suggesting the use of 32-bit integer comparisons instead of byte
array comparisons.

Signed-off-by: M. Vefa Bicakci 

---

v2: Correct code style issues and compare 32-bit integers instead of
byte arrays. Update the commit message to better reflect the nature
of the changes.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 34 +++
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index bcb5ea68acbe..0ed048fcb36f 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -210,7 +210,7 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
 struct recv_frame *precvframe)
 {
/*  exclude ICV */
-   u8 crc[4];
+   u32 actual_crc, expected_crc;
struct arc4context mycontext;
int length;
u32 keylength;
@@ -243,16 +243,14 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
arcfour_encrypt(, payload, payload, length);
 
/* calculate icv and compare the icv */
-   *((u32 *)crc) = le32_to_cpu(getcrc32(payload, length - 4));
+   actual_crc = le32_to_cpu(getcrc32(payload, length - 4));
+   expected_crc = le32_to_cpu(get_unaligned_le32([length - 4]));
 
-   if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
-   crc[1] != payload[length - 3] || crc[0] != payload[length - 4]) {
+   if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-"rtw_wep_decrypt23a:icv error crc[3](%x)!= 
payload[length-1](%x) || crc[2](%x)!= payload[length-2](%x) || crc[1](%x)!= 
payload[length-3](%x) || crc[0](%x)!= payload[length-4](%x)\n",
-crc[3], payload[length - 1],
-crc[2], payload[length - 2],
-crc[1], payload[length - 3],
-crc[0], payload[length - 4]);
+"rtw_wep_decrypt23a:icv CRC mismatch: "
+"actual: %08x, expected: %08x\n",
+actual_crc, expected_crc);
}
 }
 
@@ -714,7 +712,7 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
u32 pnh;
u8 rc4key[16];
u8 ttkey[16];
-   u8 crc[4];
+   u32 actual_crc, expected_crc;
struct arc4context mycontext;
int length;
u32 prwskeylen;
@@ -771,18 +769,14 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
arcfour_init(, rc4key, 16);
arcfour_encrypt(, payload, payload, length);
 
-   *((u32 *)crc) = le32_to_cpu(getcrc32(payload, length - 4));
+   actual_crc = le32_to_cpu(getcrc32(payload, length - 4));
+   expected_crc = le32_to_cpu(get_unaligned_le32([length - 4]));
 
-   if (crc[3] != payload[length - 1] ||
-   crc[2] != payload[length - 2] ||
-   crc[1] != payload[length - 3] ||
-   crc[0] != payload[length - 4]) {
+   if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-"rtw_wep_decrypt23a:icv error crc[3](%x)!= 
payload[length-1](%x) || crc[2](%x)!= payload[length-2](%x) || crc[1](%x)!= 
payload[length-3](%x) || crc[0](%x)!= payload[length-4](%x)\n",
-crc[3], payload[length - 1],
-crc[2], payload[length - 2],
-crc[1], payload[length - 3],
-crc[0], payload[length - 4]);
+"rtw_wep_decrypt23a:icv CRC mismatch: "
+"actual: %08x, expected: %08x\n",
+actual_crc, expected_crc);
res = _FAIL;
}
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 11/15] staging: rtl8723au: Adjust whitespace in and around comments

2015-03-28 Thread M. Vefa Bicakci
As the subject indicates, adjust whitespace in and around comments
in rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 113 +-
 1 file changed, 57 insertions(+), 56 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 31ef1bce1e2a..8e0e9fa0efdc 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -135,12 +135,12 @@ static u32 getcrc32(u8 *buf, int len)
if (bcrc32initialized == 0)
crc32_init();
 
-   crc = 0x;   /* preload shift register, per CRC-32 spec */
+   crc = 0x; /* preload shift register, per CRC-32 spec */
 
for (p = buf; len > 0; ++p, --len)
crc = crc32_table[(crc ^ *p) & 0xff] ^ (crc >> 8);
 
-   return ~crc;/* transmit complement, per CRC-32 spec */
+   return ~crc; /* transmit complement, per CRC-32 spec */
 }
 
 /* Need to consider the fragment  situation */
@@ -152,7 +152,7 @@ void rtw_wep_encrypt23a(struct rtw_adapter *padapter,
struct arc4context mycontext;
int curfragnum, length, index;
u32 keylength;
-   u8 *pframe, *payload, *iv;/* wepkey */
+   u8 *pframe, *payload, *iv; /* wepkey */
u8 wepkey[16];
u8 hw_hdr_offset = 0;
struct pkt_attrib *pattrib = >attrib;
@@ -370,15 +370,15 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
priority[0] = pri;
 
/* Michael MIC pseudo header: DA, SA, 3 x 0, Priority */
-   if (header[1]&1) {   /* ToDS == 1 */
-   rtw_secmicappend23a(, [16], 6);  /* DA */
-   if (header[1]&2)  /* From Ds == 1 */
+   if (header[1]&1) { /* ToDS == 1 */
+   rtw_secmicappend23a(, [16], 6); /* DA */
+   if (header[1]&2) /* From Ds == 1 */
rtw_secmicappend23a(, [24], 6);
else
rtw_secmicappend23a(, [10], 6);
-   } else {/* ToDS == 0 */
-   rtw_secmicappend23a(, [4], 6);   /* DA */
-   if (header[1]&2)  /* From Ds == 1 */
+   } else { /* ToDS == 0 */
+   rtw_secmicappend23a(, [4], 6); /* DA */
+   if (header[1]&2) /* From Ds == 1 */
rtw_secmicappend23a(, [16], 6);
else
rtw_secmicappend23a(, [10], 6);
@@ -400,7 +400,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define  Hi16(v32)   ((u16)(((v32) >> 16) & 0x))
 #define  Mk16(hi, lo) ((lo) ^ (((u16)(hi)) << 8))
 
-/* select the Nth 16-bit word of the temporal key unsigned char array TK[]   */
+/* select the Nth 16-bit word of the temporal key unsigned char array TK[] */
 #define  TK16(N) Mk16(tk[2 * (N) + 1], tk[2 * (N)])
 
 /* S-box lookup: 16 bits --> 16 bits */
@@ -507,7 +507,7 @@ static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, 
u32 iv32)
 {
int  i;
 
-   /* Initialize the 80 bits of P1K[] from IV32 and TA[0..5] */
+   /* Initialize the 80 bits of P1K[] from IV32 and TA[0..5] */
p1k[0]  = Lo16(iv32);
p1k[1]  = Hi16(iv32);
p1k[2]  = Mk16(ta[1], ta[0]); /* use TA[] as little-endian */
@@ -523,7 +523,7 @@ static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, 
u32 iv32)
p1k[2] += _S_(p1k[1] ^ TK16((i & 1) + 4));
p1k[3] += _S_(p1k[2] ^ TK16((i & 1) + 6));
p1k[4] += _S_(p1k[3] ^ TK16((i & 1) + 0));
-   p1k[4] +=  (unsigned short)i;/* avoid 
"slide attacks" */
+   p1k[4] +=  (unsigned short) i; /* avoid "slide attacks" */
}
 
 }
@@ -554,41 +554,41 @@ static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, 
u32 iv32)
 static void phase2(u8 *rc4key, const u8 *tk, const u16 *p1k, u16 iv16)
 {
int  i;
-   u16 PPK[6];  /* temporary key for mixing*/
+   u16 PPK[6]; /* temporary key for mixing*/
 
-   /* Note: all adds in the PPK[] equations below are mod 2**16 */
+   /* Note: all adds in the PPK[] equations below are mod 2**16 */
for (i = 0; i < 5; i++)
-   PPK[i] = p1k[i];/* first, copy P1K to PPK  */
+   PPK[i] = p1k[i]; /* first, copy P1K to PPK */
 
-   PPK[5] = p1k[4] + iv16; /* next,  add in IV16  */
+   PPK[5] = p1k[4] + iv16; /* next,  add in IV16 */
 
-   /* Bijective non-linear mixing of the 96 bits of PPK[0..5]   */
-   PPK[0] +=_S_(PPK[5] ^ TK16(0));   /* Mix key in each "round" */
-   PPK[1] +=_S_(PPK[0] ^ TK16(1));
-   PPK[2] +=_S_(PPK[1] ^ TK16(2));
-   PPK[3] +=_S_

[PATCH v5 02/15] staging: rtl8723au: Fix "before/around/after" whitespace issues

2015-03-28 Thread M. Vefa Bicakci
Correct a number of "space(s) required before/around/after" checkpatch.pl
issues in a number of functions in rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci 

---

v5: Correct even more whitespace issues.

v2: Correct one more whitespace issue ("length-4") in
rtw_tkip_decrypt23a.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 219 +-
 1 file changed, 113 insertions(+), 106 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 92882f60bc0e..572fcf3f936d 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -129,14 +129,14 @@ static void crc32_init(void)
 static u32 getcrc32(u8 *buf, int len)
 {
u8 *p;
-   u32  crc;
+   u32 crc;
 
if (bcrc32initialized == 0) crc32_init();
 
crc = 0x;   /* preload shift register, per CRC-32 spec */
 
for (p = buf; len > 0; ++p, --len)
-   crc = crc32_table[ (crc ^ *p) & 0xff] ^ (crc >> 8);
+   crc = crc32_table[(crc ^ *p) & 0xff] ^ (crc >> 8);
 
return ~crc;/* transmit complement, per CRC-32 spec */
 }
@@ -182,7 +182,7 @@ void rtw_wep_encrypt23a(struct rtw_adapter *padapter,
if ((curfragnum + 1) == pattrib->nr_frags) {
/* the last fragment */
length = pattrib->last_txcmdsz - pattrib->hdrlen -
-   pattrib->iv_len- pattrib->icv_len;
+   pattrib->iv_len - pattrib->icv_len;
 
*((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
 
@@ -262,8 +262,8 @@ static u32 secmicgetuint32(u8 *p)
s32 i;
u32 res = 0;
 
-   for (i = 0; i<4; i++) {
-   res |= ((u32)(*p++)) << (8*i);
+   for (i = 0; i < 4; i++) {
+   res |= ((u32)(*p++)) << (8 * i);
}
 
return res;
@@ -274,7 +274,7 @@ static void secmicputuint32(u8 *p, u32 val)
 {
long i;
 
-   for (i = 0; i<4; i++) {
+   for (i = 0; i < 4; i++) {
*p++ = (u8) (val & 0xff);
val >>= 8;
}
@@ -307,7 +307,7 @@ void rtw_secmicappend23abyte23a(struct mic_data *pmicdata, 
u8 b)
 {
 
/*  Append the byte to our word-sized buffer */
-   pmicdata->M |= ((unsigned long)b) << (8*pmicdata->nBytesInM);
+   pmicdata->M |= ((unsigned long)b) << (8 * pmicdata->nBytesInM);
pmicdata->nBytesInM++;
/*  Process the word if it is full. */
if (pmicdata->nBytesInM >= 4) {
@@ -331,7 +331,7 @@ void rtw_secmicappend23a(struct mic_data *pmicdata, u8 
*src, u32 nbytes)
 {
 
/*  This is simple */
-   while(nbytes > 0) {
+   while (nbytes > 0) {
rtw_secmicappend23abyte23a(pmicdata, *src++);
nbytes--;
}
@@ -348,12 +348,12 @@ void rtw_secgetmic23a(struct mic_data *pmicdata, u8 *dst)
rtw_secmicappend23abyte23a(pmicdata, 0);
rtw_secmicappend23abyte23a(pmicdata, 0);
/*  and then zeroes until the length is a multiple of 4 */
-   while(pmicdata->nBytesInM != 0) {
+   while (pmicdata->nBytesInM != 0) {
rtw_secmicappend23abyte23a(pmicdata, 0);
}
/*  The appendByte function has already computed the result. */
secmicputuint32(dst, pmicdata->L);
-   secmicputuint32(dst+4, pmicdata->R);
+   secmicputuint32(dst + 4, pmicdata->R);
/*  Reset to the empty message. */
secmicclear(pmicdata);
 
@@ -364,10 +364,10 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 {
 
struct mic_data micdata;
-   u8 priority[4]={0x0, 0x0, 0x0, 0x0};
+   u8 priority[4] = {0x0, 0x0, 0x0, 0x0};
 
rtw_secmicsetkey23a(, key);
-   priority[0]= pri;
+   priority[0] = pri;
 
/* Michael MIC pseudo header: DA, SA, 3 x 0, Priority */
if (header[1]&1) {   /* ToDS == 1 */
@@ -398,11 +398,11 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define   Lo8(v16)   ((u8)((v16)   & 0x00FF))
 #define   Hi8(v16)   ((u8)(((v16) >> 8) & 0x00FF))
 #define  Lo16(v32)   ((u16)((v32)   & 0x))
-#define  Hi16(v32)   ((u16)(((v32) >>16) & 0x))
+#define  Hi16(v32)   ((u16)(((v32) >> 16) & 0x))
 #define  Mk16(hi, lo) ((lo) ^ (((u16)(hi)) << 8))
 
 /* select the Nth 16-bit word of the temporal key unsigned char array TK[]   */
-#define  TK16(N) Mk16(tk[2*(N)+1], tk[2*(N)])
+#define  TK16(N) Mk16(tk[2 * (N) + 1], tk[2 * (N)])
 
 /* S-box lookup: 16 bits --> 16 bits */
 #define _S_(v16) (Sbox1[0][Lo8(v16)] ^ Sbox1[1][Hi8(v16)])
@@ -415,7 +415,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32

[PATCH v5 09/15] staging: rtl8723au: that open brace should be on the previous line

2015-03-28 Thread M. Vefa Bicakci
Correct two instances of the checkpatch.pl error indicating that the
opening curly braces should not be on new lines:
ERROR: that open brace { should be on the previous line

Signed-off-by: M. Vefa Bicakci 

---

v3: Make sure that all edited lines are at most 80 characters wide.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 63591ddeb628..2d50777b88fb 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -773,8 +773,10 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 
*((u32 *)crc) = le32_to_cpu(getcrc32(payload, length - 4));
 
-   if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] || 
crc[1] != payload[length - 3] || crc[0] != payload[length - 4])
-   {
+   if (crc[3] != payload[length - 1] ||
+   crc[2] != payload[length - 2] ||
+   crc[1] != payload[length - 3] ||
+   crc[0] != payload[length - 4]) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
 "rtw_wep_decrypt23a:icv error crc[3](%x)!= 
payload[length-1](%x) || crc[2](%x)!= payload[length-2](%x) || crc[1](%x)!= 
payload[length-3](%x) || crc[0](%x)!= payload[length-4](%x)\n",
 crc[3], payload[length - 1],
@@ -862,8 +864,7 @@ static void next_key(u8 *key, int round)
 {
u8 rcon;
u8 sbox_key[4];
-   u8 rcon_table[12] =
-   {
+   u8 rcon_table[12] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x1b, 0x36, 0x36, 0x36
};
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 15/15] staging: rtl8723au: Remove unneeded comments

2015-03-28 Thread M. Vefa Bicakci
This commit removes a number of unneeded comments. Two of the
aforementioned comments were most likely meant to aid with version
control, whereas the remaining two comments relate to (now unused)
local variable names.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 5ef16bb30dc4..af53c92fc3a2 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -679,7 +679,7 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
 "pattrib->iv_len =%x, pattrib->icv_len =%x\n",
 pattrib->iv_len,
 pattrib->icv_len);
-   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length)); 
/* modified by Amy */
+   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
 
arcfour_init(, rc4key, 16);
arcfour_encrypt(, payload, payload, length);
@@ -691,7 +691,7 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
  pattrib->iv_len -
  pattrib->icv_len);
 
-   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length)); 
/* modified by Amy */
+   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
arcfour_init(, rc4key, 16);
arcfour_encrypt(, payload, payload, length);
arcfour_encrypt(, payload + length, crc, 4);
@@ -1285,7 +1285,7 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
/* Intermediate Buffers */
int curfragnum, length;
u32 prwskeylen;
-   u8 *pframe, *prwskey; /* *payload, *iv */
+   u8 *pframe, *prwskey;
u8 hw_hdr_offset = 0;
struct sta_info *stainfo;
struct pkt_attrib *pattrib = >attrib;
@@ -1574,7 +1574,7 @@ int rtw_aes_decrypt23a(struct rtw_adapter *padapter,
struct security_priv *psecuritypriv = >securitypriv;
struct sk_buff *skb = precvframe->pkt;
int length;
-   u8 *pframe, *prwskey; /* *payload, *iv */
+   u8 *pframe, *prwskey;
int res = _SUCCESS;
 
pframe = skb->data;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 10/15] staging: rtl8723au: No spaces at the start of a line

2015-03-28 Thread M. Vefa Bicakci
Prior to this commit, a large block of constants used to represent
an AES S-box table were indented with spaces in rtl8723au's
rtw_security.c. Correct the checkpatch.pl warnings indicating that
spaces should not be used to indent lines:
WARNING: please, no spaces at the start of a line

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 140 +-
 1 file changed, 70 insertions(+), 70 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 2d50777b88fb..31ef1bce1e2a 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -414,76 +414,76 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define RC4_KEY_SIZE 16/* 128-bit RC4KEY (104 bits unknown) */
 
 /* 2-unsigned char by 2-unsigned char subset of the full AES S-box table */
-static const unsigned short Sbox1[2][256] =   /* Sbox for hash (can be in 
ROM) */
-{ {
-   0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
-   0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
-   0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B,
-   0x41EC, 0xB367, 0x5FFD, 0x45EA, 0x23BF, 0x53F7, 0xE496, 0x9B5B,
-   0x75C2, 0xE11C, 0x3DAE, 0x4C6A, 0x6C5A, 0x7E41, 0xF502, 0x834F,
-   0x685C, 0x51F4, 0xD134, 0xF908, 0xE293, 0xAB73, 0x6253, 0x2A3F,
-   0x080C, 0x9552, 0x4665, 0x9D5E, 0x3028, 0x37A1, 0x0A0F, 0x2FB5,
-   0x0E09, 0x2436, 0x1B9B, 0xDF3D, 0xCD26, 0x4E69, 0x7FCD, 0xEA9F,
-   0x121B, 0x1D9E, 0x5874, 0x342E, 0x362D, 0xDCB2, 0xB4EE, 0x5BFB,
-   0xA4F6, 0x764D, 0xB761, 0x7DCE, 0x527B, 0xDD3E, 0x5E71, 0x1397,
-   0xA6F5, 0xB968, 0x, 0xC12C, 0x4060, 0xE31F, 0x79C8, 0xB6ED,
-   0xD4BE, 0x8D46, 0x67D9, 0x724B, 0x94DE, 0x98D4, 0xB0E8, 0x854A,
-   0xBB6B, 0xC52A, 0x4FE5, 0xED16, 0x86C5, 0x9AD7, 0x6655, 0x1194,
-   0x8ACF, 0xE910, 0x0406, 0xFE81, 0xA0F0, 0x7844, 0x25BA, 0x4BE3,
-   0xA2F3, 0x5DFE, 0x80C0, 0x058A, 0x3FAD, 0x21BC, 0x7048, 0xF104,
-   0x63DF, 0x77C1, 0xAF75, 0x4263, 0x2030, 0xE51A, 0xFD0E, 0xBF6D,
-   0x814C, 0x1814, 0x2635, 0xC32F, 0xBEE1, 0x35A2, 0x88CC, 0x2E39,
-   0x9357, 0x55F2, 0xFC82, 0x7A47, 0xC8AC, 0xBAE7, 0x322B, 0xE695,
-   0xC0A0, 0x1998, 0x9ED1, 0xA37F, 0x4466, 0x547E, 0x3BAB, 0x0B83,
-   0x8CCA, 0xC729, 0x6BD3, 0x283C, 0xA779, 0xBCE2, 0x161D, 0xAD76,
-   0xDB3B, 0x6456, 0x744E, 0x141E, 0x92DB, 0x0C0A, 0x486C, 0xB8E4,
-   0x9F5D, 0xBD6E, 0x43EF, 0xC4A6, 0x39A8, 0x31A4, 0xD337, 0xF28B,
-   0xD532, 0x8B43, 0x6E59, 0xDAB7, 0x018C, 0xB164, 0x9CD2, 0x49E0,
-   0xD8B4, 0xACFA, 0xF307, 0xCF25, 0xCAAF, 0xF48E, 0x47E9, 0x1018,
-   0x6FD5, 0xF088, 0x4A6F, 0x5C72, 0x3824, 0x57F1, 0x73C7, 0x9751,
-   0xCB23, 0xA17C, 0xE89C, 0x3E21, 0x96DD, 0x61DC, 0x0D86, 0x0F85,
-   0xE090, 0x7C42, 0x71C4, 0xCCAA, 0x90D8, 0x0605, 0xF701, 0x1C12,
-   0xC2A3, 0x6A5F, 0xAEF9, 0x69D0, 0x1791, 0x9958, 0x3A27, 0x27B9,
-   0xD938, 0xEB13, 0x2BB3, 0x2233, 0xD2BB, 0xA970, 0x0789, 0x33A7,
-   0x2DB6, 0x3C22, 0x1592, 0xC920, 0x8749, 0xAAFF, 0x5078, 0xA57A,
-   0x038F, 0x59F8, 0x0980, 0x1A17, 0x65DA, 0xD731, 0x84C6, 0xD0B8,
-   0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A,
-  },
-
-  {  /* second half of table is unsigned char-reversed version of first! */
-   0xA5C6, 0x84F8, 0x99EE, 0x8DF6, 0x0DFF, 0xBDD6, 0xB1DE, 0x5491,
-   0x5060, 0x0302, 0xA9CE, 0x7D56, 0x19E7, 0x62B5, 0xE64D, 0x9AEC,
-   0x458F, 0x9D1F, 0x4089, 0x87FA, 0x15EF, 0xEBB2, 0xC98E, 0x0BFB,
-   0xEC41, 0x67B3, 0xFD5F, 0xEA45, 0xBF23, 0xF753, 0x96E4, 0x5B9B,
-   0xC275, 0x1CE1, 0xAE3D, 0x6A4C, 0x5A6C, 0x417E, 0x02F5, 0x4F83,
-   0x5C68, 0xF451, 0x34D1, 0x08F9, 0x93E2, 0x73AB, 0x5362, 0x3F2A,
-   0x0C08, 0x5295, 0x6546, 0x5E9D, 0x2830, 0xA137, 0x0F0A, 0xB52F,
-   0x090E, 0x3624, 0x9B1B, 0x3DDF, 0x26CD, 0x694E, 0xCD7F, 0x9FEA,
-   0x1B12, 0x9E1D, 0x7458, 0x2E34, 0x2D36, 0xB2DC, 0xEEB4, 0xFB5B,
-   0xF6A4, 0x4D76, 0x61B7, 0xCE7D, 0x7B52, 0x3EDD, 0x715E, 0x9713,
-   0xF5A6, 0x68B9, 0x, 0x2CC1, 0x6040, 0x1FE3, 0xC879, 0xEDB6,
-   0xBED4, 0x468D, 0xD967, 0x4B72, 0xDE94, 0xD498, 0xE8B0, 0x4A85,
-   0x6BBB, 0x2AC5, 0xE54F, 0x16ED, 0xC586, 0xD79A, 0x5566, 0x9411,
-   0xCF8A, 0x10E9, 0x0604, 0x81FE, 0xF0A0, 0x4478, 0xBA25, 0xE34B,
-   0xF3A2, 0xFE5D, 0xC080, 0x8A05, 0xAD3F, 0xBC21, 0x4870, 0x04F1,
-   0xDF63, 0xC177, 0x75AF, 0x6342, 0x3020, 0x1AE5, 0x0EFD, 0x6DBF,
-   0x4C81, 0x1418, 0x3526, 0x2FC3, 0xE1BE, 0xA235, 0xCC88, 0x392E,
-   0x5793, 0xF255, 0x82FC, 0x477A, 0xACC8, 0xE7BA, 0x2B32, 0x95E6,
-   0xA0C0, 0x9819, 0xD19E, 0x7FA3, 0x6644, 0x7E54, 0xAB3B, 0x830B,
-   0xCA8C, 0x29C7, 0xD36B, 0x3C28, 0x79A7, 0xE2BC, 0x1D16, 0x76AD,
-   0x3BDB, 0x5664, 0x4E74, 0x1E14, 0xDB92, 0x0A0C, 0x6C48, 0xE4B8,
-   0x5D9F, 0x6EBD, 0xEF43, 0xA6C4, 0xA839, 0xA431, 0x37D3, 0x8BF2,
-   0x32D5, 0x438B, 0x596E, 0xB7DA, 0x8C01, 0x64B1, 0xD29C, 0xE049,
-   0xB4D8, 0xFAAC, 0x07F3, 0x25CF, 0xAFCA, 0x8EF4, 0xE947, 0x1810,
-   0xD56F, 0x88F0, 0x6F4A, 0x725C, 0x2438

[PATCH v5 14/15] staging: rtl8723au: Use __func__ in trace logs

2015-03-28 Thread M. Vefa Bicakci
Rework the trace log-related lines in rtl8723au's rtw_security.c
to use the __func__ GCC magic variable instead of hardcoding the
function names into the trace log strings. This also corrects a
copy-paste-related typo in the function named rtw_tkip_decrypt23a.

Thanks to Jes Sorensen for the suggestion to use __func__.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 41 ++-
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 0ed048fcb36f..5ef16bb30dc4 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -248,9 +248,9 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
 
if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-"rtw_wep_decrypt23a:icv CRC mismatch: "
+"%s:icv CRC mismatch: "
 "actual: %08x, expected: %08x\n",
-actual_crc, expected_crc);
+__func__, actual_crc, expected_crc);
}
 }
 
@@ -635,13 +635,13 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
 
if (stainfo == NULL) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-"rtw_tkip_encrypt23a: stainfo == NULL!!!\n");
+"%s: stainfo == NULL!!!\n", __func__);
DBG_8723A("%s, psta == NUL\n", __func__);
return _FAIL;
}
 
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-"rtw_tkip_encrypt23a: stainfo!= NULL!!!\n");
+"%s: stainfo!= NULL!!!\n", __func__);
 
if (!(stainfo->state & _FW_LINKED)) {
DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, 
stainfo->state);
@@ -733,7 +733,7 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 >ta[0]);
if (stainfo == NULL) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-"rtw_tkip_decrypt23a: stainfo == NULL!!!\n");
+"%s: stainfo == NULL!!!\n", __func__);
return _FAIL;
}
 
@@ -748,7 +748,7 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
prwskeylen = 16;
} else {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-"rtw_tkip_decrypt23a: stainfo!= NULL!!!\n");
+"%s: stainfo!= NULL!!!\n", __func__);
prwskey = >dot118021x_UncstKey.skey[0];
prwskeylen = 16;
}
@@ -774,9 +774,9 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 
if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-"rtw_wep_decrypt23a:icv CRC mismatch: "
+"%s:icv CRC mismatch: "
 "actual: %08x, expected: %08x\n",
-actual_crc, expected_crc);
+__func__, actual_crc, expected_crc);
res = _FAIL;
}
 
@@ -1313,7 +1313,7 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
 
if (!stainfo) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-"rtw_aes_encrypt23a: stainfo == NULL!!!\n");
+"%s: stainfo == NULL!!!\n", __func__);
DBG_8723A("%s, psta == NUL\n", __func__);
res = _FAIL;
goto out;
@@ -1324,7 +1324,7 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
return _FAIL;
}
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-"rtw_aes_encrypt23a: stainfo!= NULL!!!\n");
+"%s: stainfo!= NULL!!!\n", __func__);
 
if (is_multicast_ether_addr(pattrib->ra))
prwskey = 
psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey;
@@ -1552,11 +1552,14 @@ static int aes_decipher(u8 *key, uint hdrlen, u8 
*pframe, uint plen)
for (i = 0; i < 8; i++) {
if (pframe[hdrlen + 8 + plen - 8 + i] != message[hdrlen + 8 + 
plen - 8 + i]) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-"aes_decipher:mic check error mic[%d]: 
pframe(%x) != message(%x)\n",
-i, pframe[hdrlen + 8 + plen - 8 + i],
+"%s:mic check error mic[%d]: pframe(%x) != 
message(%x)\n",
+   

[PATCH v5 04/15] staging: rtl8723au: Fix the indentation of two lines

2015-03-28 Thread M. Vefa Bicakci
Correct the indentation of two lines in rtw_tkip_encrypt23a function in
rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 9faf78bf23d8..3e79b66d0897 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -688,8 +688,8 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
arcfour_encrypt(, payload, 
payload, length);
arcfour_encrypt(, payload + 
length, crc, 4);
 
-   pframe += pxmitpriv->frag_len;
-   pframe  = PTR_ALIGN(pframe, 4);
+   pframe += pxmitpriv->frag_len;
+   pframe  = PTR_ALIGN(pframe, 4);
}
}
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 08/15] staging: rtl8723au: trailing statements should be on next line

2015-03-28 Thread M. Vefa Bicakci
Correct a number of checkpatch.pl errors in rtl8723au's rtw_security.c
related to trailing statements:
ERROR: trailing statements should be on next line

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index e8efdcd06329..63591ddeb628 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -132,7 +132,8 @@ static u32 getcrc32(u8 *buf, int len)
u8 *p;
u32 crc;
 
-   if (bcrc32initialized == 0) crc32_init();
+   if (bcrc32initialized == 0)
+   crc32_init();
 
crc = 0x;   /* preload shift register, per CRC-32 spec */
 
@@ -556,8 +557,10 @@ static void phase2(u8 *rc4key, const u8 *tk, const u16 
*p1k, u16 iv16)
u16 PPK[6];  /* temporary key for mixing*/
 
/* Note: all adds in the PPK[] equations below are mod 2**16 */
-   for (i = 0; i < 5; i++) PPK[i] = p1k[i];/* first, copy P1K to PPK   
   */
-   PPK[5] = p1k[4] + iv16; /* next,  add in IV16   
   */
+   for (i = 0; i < 5; i++)
+   PPK[i] = p1k[i];/* first, copy P1K to PPK  */
+
+   PPK[5] = p1k[4] + iv16; /* next,  add in IV16  */
 
/* Bijective non-linear mixing of the 96 bits of PPK[0..5]   */
PPK[0] +=_S_(PPK[5] ^ TK16(0));   /* Mix key in each "round" */
@@ -977,7 +980,8 @@ static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext)
u8 intermediateb[16];
u8 round_key[16];
 
-   for (i = 0; i < 16; i++) round_key[i] = key[i];
+   for (i = 0; i < 16; i++)
+   round_key[i] = key[i];
 
for (round = 0; round < 11; round++) {
if (round == 0) {
@@ -1061,7 +1065,8 @@ static void construct_mic_header2(u8 *mic_header2, u8 
*mpdu, int a4_exists,
 {
int i;
 
-   for (i = 0; i < 16; i++) mic_header2[i] = 0x00;
+   for (i = 0; i < 16; i++)
+   mic_header2[i] = 0x00;
 
mic_header2[0] = mpdu[16];/* A3 */
mic_header2[1] = mpdu[17];
@@ -1074,7 +1079,8 @@ static void construct_mic_header2(u8 *mic_header2, u8 
*mpdu, int a4_exists,
mic_header2[7] = 0x00; /* mpdu[23]; */
 
if (!qc_exists && a4_exists) {
-   for (i = 0; i < 6; i++) mic_header2[8+i] = mpdu[24+i];   /* A4 
*/
+   for (i = 0; i < 6; i++)
+   mic_header2[8+i] = mpdu[24+i];   /* A4 */
}
 
if (qc_exists && !a4_exists) {
@@ -1083,7 +1089,8 @@ static void construct_mic_header2(u8 *mic_header2, u8 
*mpdu, int a4_exists,
}
 
if (qc_exists && a4_exists) {
-   for (i = 0; i < 6; i++) mic_header2[8+i] = mpdu[24+i];   /* A4 
*/
+   for (i = 0; i < 6; i++)
+   mic_header2[8+i] = mpdu[24+i];   /* A4 */
 
mic_header2[14] = mpdu[30] & 0x0f;
mic_header2[15] = mpdu[31] & 0x00;
@@ -1101,7 +1108,9 @@ static void construct_ctr_preload(u8 *ctr_preload, int 
a4_exists, int qc_exists,
 {
int i = 0;
 
-   for (i = 0; i < 16; i++) ctr_preload[i] = 0x00;
+   for (i = 0; i < 16; i++)
+   ctr_preload[i] = 0x00;
+
i = 0;
 
ctr_preload[0] = 0x01;  /* flag */
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 03/15] staging: rtl8723au: else should follow close brace

2015-03-28 Thread M. Vefa Bicakci
Correct checkpatch.pl errors in rtl8723au's rtw_security.c indicating
that an else statement should follow the closing brace of the previous
if/else if code block:
ERROR: else should follow close brace '}'

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 572fcf3f936d..9faf78bf23d8 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -376,8 +376,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
rtw_secmicappend23a(, [24], 6);
else
rtw_secmicappend23a(, [10], 6);
-   }
-   else{   /* ToDS == 0 */
+   } else {/* ToDS == 0 */
rtw_secmicappend23a(, [4], 6);   /* DA */
if (header[1]&2)  /* From Ds == 1 */
rtw_secmicappend23a(, [16], 6);
@@ -678,8 +677,7 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
arcfour_encrypt(, payload, 
payload, length);
arcfour_encrypt(, payload + 
length, crc, 4);
 
-   }
-   else {
+   } else {
length = (pxmitpriv->frag_len -
  pattrib->hdrlen -
  pattrib->iv_len -
@@ -695,8 +693,7 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
}
}
 
-   }
-   else {
+   } else {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
 "rtw_tkip_encrypt23a: stainfo == NULL!!!\n");
DBG_8723A("%s, psta == NUL\n", __func__);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 12/15] staging: rtl8723au: suspect code indent for conditional statements

2015-03-28 Thread M. Vefa Bicakci
Correct a number of indentation-with-spaces-and-tabs issues in
rtl8723au's rtw_security.c, according to checkpatch.pl:
WARNING: suspect code indent for conditional statements

Signed-off-by: M. Vefa Bicakci 

---

v3: Make sure that all edited lines are at most 80 characters wide.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 34 +--
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 8e0e9fa0efdc..bcb5ea68acbe 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -929,9 +929,9 @@ static void mix_column(u8 *in, u8 *out)
 
for (i = 0; i < 4; i++) {
if ((in[i] & 0x80) == 0x80)
-   add1b[i] = 0x1b;
+   add1b[i] = 0x1b;
else
-   add1b[i] = 0x00;
+   add1b[i] = 0x00;
}
 
swap_halfs[0] = in[2]; /* Swap halfs */
@@ -986,21 +986,21 @@ static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext)
 
for (round = 0; round < 11; round++) {
if (round == 0) {
-   xor_128(round_key, data, ciphertext);
-   next_key(round_key, round);
+   xor_128(round_key, data, ciphertext);
+   next_key(round_key, round);
} else if (round == 10) {
-   byte_sub(ciphertext, intermediatea);
-   shift_row(intermediatea, intermediateb);
-   xor_128(intermediateb, round_key, ciphertext);
+   byte_sub(ciphertext, intermediatea);
+   shift_row(intermediatea, intermediateb);
+   xor_128(intermediateb, round_key, ciphertext);
} else { /* 1 - 9 */
-   byte_sub(ciphertext, intermediatea);
-   shift_row(intermediatea, intermediateb);
-   mix_column([0], [0]);
-   mix_column([4], [4]);
-   mix_column([8], [8]);
-   mix_column([12], [12]);
-   xor_128(intermediatea, round_key, ciphertext);
-   next_key(round_key, round);
+   byte_sub(ciphertext, intermediatea);
+   shift_row(intermediatea, intermediateb);
+   mix_column([0], [0]);
+   mix_column([4], [4]);
+   mix_column([8], [8]);
+   mix_column([12], [12]);
+   xor_128(intermediatea, round_key, ciphertext);
+   next_key(round_key, round);
}
}
 
@@ -1501,7 +1501,7 @@ static int aes_decipher(u8 *key, uint hdrlen, u8 *pframe, 
uint plen)
for (j = 0; j < 16; j++)
padded_buffer[j] = 0x00;
for (j = 0; j < payload_remainder; j++)
-   padded_buffer[j] = message[payload_index++];
+   padded_buffer[j] = message[payload_index++];
bitwise_xor(aes_out, padded_buffer, chain_buffer);
aes128k128d(key, chain_buffer, aes_out);
}
@@ -1531,7 +1531,7 @@ static int aes_decipher(u8 *key, uint hdrlen, u8 *pframe, 
uint plen)
  message, pn_vector, num_blocks + 1);
 
for (j = 0; j < 16; j++)
-padded_buffer[j] = 0x00;
+   padded_buffer[j] = 0x00;
for (j = 0; j < payload_remainder; j++)
padded_buffer[j] = message[payload_index + j];
aes128k128d(key, ctr_preload, aes_out);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 00/15] checkpatch clean-up of rtl8723au's rtw_security.c

2015-03-28 Thread M. Vefa Bicakci
These commits address a number of checkpatch.pl warnings and errors
in rtl8723au's rtw_security.c.

Prior to this set of commits, checkpatch.pl reported the following:
total: 75 errors, 124 warnings, 1631 lines checked

After applying this set of commits, checkpatch.pl reports the following:
total: 0 errors, 22 warnings, 1635 lines checked
where the only remaining warnings relate to lines longer than 80
characters and quoted strings split across multiple lines.

There are also a number of commits which improve the code in other ways.
For example, the commit titled "Reorganize a few functions to remove
indentation" reworks two functions to make them more readable, whereas
the commit titled "Rework two byte array comparisons" reworks two CRC
verifications for the same reason, and "Use __func__ in trace logs"
avoids hardcoding function names in trace logs to increase
maintainability.

All of the commits have been verified to compile successfully via the
use of the interactive rebase feature of git.

v5: Rebased onto Greg Kroah-Hartman's staging-testing tree, on top of
the following commit
  commit f8da055aafec0483c12132554504ec683868c655
  staging: sm750fb: Change "foo * bar" style to "foo *bar"

Please see the individual commit messages for the specific changes
since v5 aside from the rebase.

v4: Rebased onto Greg Kroah-Hartman's staging-next tree, on top of
the following commit
  commit 153fe946412b5da1a8808f79d4f7f4ebfa7586b0
  staging: fbtft: Do not use binary constants

In addition, fix-up the commit messages to move the patch revision
notes below the newly added "---" markers where needed.

v3: Rebased onto Greg Kroah-Hartman's staging-next tree, on top of
the following commit
  5ec293650827122df300581c17ca1d5de03bac3d.
  Staging: dgnc: release the lock before testing for nullity

Please see the individual commit messages for the changes
since v2. In summary, the following commits have been updated:
- that open brace should be on the previous line
- suspect code indent for conditional statements

The following commit is new:
- Use __func__ in trace logs

Finally, the following commit has been removed:
- Do not initialize a static to 0

v2: Please see the individual commit messages for the changes
since v1. In summary, the following commits have been updated:
- Reformat whitespace to increase readability
- Fix "before/around/after" whitespace issues
- Rework two byte array comparisons

M. Vefa Bicakci (15):
  staging: rtl8723au: Reformat whitespace to increase readability
  staging: rtl8723au: Fix "before/around/after" whitespace issues
  staging: rtl8723au: else should follow close brace
  staging: rtl8723au: Fix the indentation of two lines
  staging: rtl8723au: Reorganize a few functions to remove indentation
  staging: rtl8723au: else is not generally useful after a return
  staging: rtl8723au: Remove unneeded curly braces
  staging: rtl8723au: trailing statements should be on next line
  staging: rtl8723au: that open brace should be on the previous line
  staging: rtl8723au: No spaces at the start of a line
  staging: rtl8723au: Adjust whitespace in and around comments
  staging: rtl8723au: suspect code indent for conditional statements
  staging: rtl8723au: Rework two byte array comparisons
  staging: rtl8723au: Use __func__ in trace logs
  staging: rtl8723au: Remove unneeded comments

 drivers/staging/rtl8723au/core/rtw_security.c | 832 +-
 1 file changed, 418 insertions(+), 414 deletions(-)

-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 05/15] staging: rtl8723au: Reorganize a few functions to remove indentation

2015-03-28 Thread M. Vefa Bicakci
Prior to this commit, functions rtw_tkip_encrypt23a and rtw_tkip_decrypt23a had
large if blocks which contained the majority of the logic in the functions.

Rework these functions so that if the negated version of the aforementioned if
blocks' conditions are true, we return from the function with _FAIL, as
expected by the calling code.

This lets us remove two levels of indentation from the functions in
question, making them more readable.

Signed-off-by: M. Vefa Bicakci 

---

v5: Move the "start to encrypt each fragment" and "start to decrypt
recvframe" comments in the refactored functions to more sensible
positions.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 215 +-
 1 file changed, 107 insertions(+), 108 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 3e79b66d0897..df7261c045fe 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -615,91 +615,90 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
struct xmit_priv *pxmitpriv = >xmitpriv;
int res = _SUCCESS;
 
+   if (pattrib->encrypt != WLAN_CIPHER_SUITE_TKIP)
+   return _FAIL;
+
if (!pxmitframe->buf_addr)
return _FAIL;
 
hw_hdr_offset = TXDESC_OFFSET;
 
pframe = pxmitframe->buf_addr + hw_hdr_offset;
-   /* 4 start to encrypt each fragment */
-   if (pattrib->encrypt == WLAN_CIPHER_SUITE_TKIP) {
-   if (pattrib->psta)
-   stainfo = pattrib->psta;
-   else {
-   DBG_8723A("%s, call rtw_get_stainfo()\n", __func__);
-   stainfo = rtw_get_stainfo23a(>stapriv,
->ra[0]);
-   }
 
-   if (stainfo != NULL) {
+   if (pattrib->psta)
+   stainfo = pattrib->psta;
+   else {
+   DBG_8723A("%s, call rtw_get_stainfo()\n", __func__);
+   stainfo = rtw_get_stainfo23a(>stapriv,
+>ra[0]);
+   }
 
-   if (!(stainfo->state & _FW_LINKED)) {
-   DBG_8723A("%s, psta->state(0x%x) != 
_FW_LINKED\n", __func__, stainfo->state);
-   return _FAIL;
-   }
+   if (stainfo == NULL) {
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
+"rtw_tkip_encrypt23a: stainfo == NULL!!!\n");
+   DBG_8723A("%s, psta == NUL\n", __func__);
+   return _FAIL;
+   }
 
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-"rtw_tkip_encrypt23a: stainfo!= NULL!!!\n");
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
+"rtw_tkip_encrypt23a: stainfo!= NULL!!!\n");
 
-   if (is_multicast_ether_addr(pattrib->ra))
-   prwskey = 
psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey;
-   else
-   prwskey = >dot118021x_UncstKey.skey[0];
+   if (!(stainfo->state & _FW_LINKED)) {
+   DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, 
stainfo->state);
+   return _FAIL;
+   }
 
-   prwskeylen = 16;
+   if (is_multicast_ether_addr(pattrib->ra))
+   prwskey = 
psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey;
+   else
+   prwskey = >dot118021x_UncstKey.skey[0];
 
-   for (curfragnum = 0; curfragnum < pattrib->nr_frags; 
curfragnum++) {
-   iv = pframe + pattrib->hdrlen;
-   payload = pframe + pattrib->iv_len + 
pattrib->hdrlen;
+   prwskeylen = 16;
 
-   GET_TKIP_PN(iv, dot11txpn);
+   /* 4 start to encrypt each fragment */
+   for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) {
+   iv = pframe + pattrib->hdrlen;
+   payload = pframe + pattrib->iv_len + pattrib->hdrlen;
 
-   pnl = (u16)(dot11txpn.val);
-   pnh = (u32)(dot11txpn.val>>16);
+   GET_TKIP_PN(iv, dot11txpn);
 
-   phase1((u16 *)[0], prwskey, 
>ta[0], pnh);
+   pnl = (u16)(dot11txpn.val);
+   pnh = (u32)(dot11txpn.val>>16);
 
-   phase2([0], prwskey, (u16 *)[0], 
pnl);
+   phase1((u16 *)[0], prwskey, >ta[0], pnh);
 
-

[PATCH v5 06/15] staging: rtl8723au: else is not generally useful after a return

2015-03-28 Thread M. Vefa Bicakci
Correct a checkpatch.pl warning regarding rtl8723au's
rtw_security.c::crc32_init pointing out that having an else statement
after a break or a return is not useful.

drivers/staging/rtl8723au/core/rtw_security.c:105:
WARNING: else is not generally useful after a break or return

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 42 ++-
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index df7261c045fe..b85e5de5f136 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -99,31 +99,33 @@ static u8 crc32_reverseBit(u8 data)
 
 static void crc32_init(void)
 {
+   int i, j;
+   u32 c;
+   u8 *p, *p1;
+   u8 k;
 
if (bcrc32initialized == 1)
return;
-   else{
-   int i, j;
-   u32 c;
-   u8 *p = (u8 *), *p1;
-   u8 k;
-
-   c = 0x1234;
-
-   for (i = 0; i < 256; ++i) {
-   k = crc32_reverseBit((u8)i);
-   for (c = ((u32)k) << 24, j = 8; j > 0; --j) {
-   c = c & 0x8000 ? (c << 1) ^ CRC32_POLY : (c 
<< 1);
-   }
-   p1 = (u8 *)_table[i];
-
-   p1[0] = crc32_reverseBit(p[3]);
-   p1[1] = crc32_reverseBit(p[2]);
-   p1[2] = crc32_reverseBit(p[1]);
-   p1[3] = crc32_reverseBit(p[0]);
+
+   p = (u8 *) 
+   c = 0x1234;
+
+   for (i = 0; i < 256; ++i) {
+   k = crc32_reverseBit((u8)i);
+
+   for (c = ((u32)k) << 24, j = 8; j > 0; --j) {
+   c = c & 0x8000 ? (c << 1) ^ CRC32_POLY : (c << 1);
}
-   bcrc32initialized = 1;
+
+   p1 = (u8 *)_table[i];
+
+   p1[0] = crc32_reverseBit(p[3]);
+   p1[1] = crc32_reverseBit(p[2]);
+   p1[2] = crc32_reverseBit(p[1]);
+   p1[3] = crc32_reverseBit(p[0]);
}
+
+   bcrc32initialized = 1;
 }
 
 static u32 getcrc32(u8 *buf, int len)
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 00/15] checkpatch clean-up of rtl8723au's rtw_security.c

2015-03-28 Thread M. Vefa Bicakci
On Sat, March 28, 2015 12:52:54 Joe Perches wrote:
> On Sat, 2015-03-28 at 08:52 -0400, M. Vefa Bicakci wrote:
> > These commits address a number of checkpatch.pl warnings and errors
> > in rtl8723au's rtw_security.c.
> 
> Hello.
> 
> This is one of those patchsets that should be
> done against Greg's staging-testing branch.
> 
> There are some commits against rtl8723au in that
> branch that will conflict with your patches.

Hello Joe,

Thank you for letting me know. Given the discussion arising from the 3rd 
version of the patches, I should have used (or at least checked) the 
staging-testing branch.

I rebased the commits against the staging-testing branch and corrected 
the merge conflicts. I hope to send the 5th version of the patches out 
for review soon.

Vefa

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 03/15] staging: rtl8723au: else should follow close brace

2015-03-28 Thread M. Vefa Bicakci
Correct checkpatch.pl errors in rtl8723au's rtw_security.c indicating
that an else statement should follow the closing brace of the previous
if/else if code block:
ERROR: else should follow close brace '}'

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index cb78d6dd9c..17234e0bf1 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -379,8 +379,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
rtw_secmicappend23a(, [24], 6);
else
rtw_secmicappend23a(, [10], 6);
-   }
-   else{   /* ToDS == 0 */
+   } else {/* ToDS == 0 */
rtw_secmicappend23a(, [4], 6);   /* DA */
if (header[1]&2)  /* From Ds == 1 */
rtw_secmicappend23a(, [16], 6);
@@ -673,8 +672,7 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
arcfour_encrypt(, payload, 
payload, length);
arcfour_encrypt(, 
payload+length, crc, 4);
 
-   }
-   else {
+   } else {
length = 
pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
*((u32 *)crc) = 
cpu_to_le32(getcrc32(payload, length));/* modified by Amy*/
arcfour_init(, rc4key, 16);
@@ -686,8 +684,7 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
}
}
 
-   }
-   else {
+   } else {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
("rtw_tkip_encrypt23a: stainfo == NULL!!!\n"));
DBG_8723A("%s, psta == NUL\n", __func__);
res = _FAIL;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 08/15] staging: rtl8723au: trailing statements should be on next line

2015-03-28 Thread M. Vefa Bicakci
Correct a number of checkpatch.pl errors in rtl8723au's rtw_security.c
related to trailing statements:
ERROR: trailing statements should be on next line

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index b4327aaf71..803f8965a4 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -132,7 +132,8 @@ static u32 getcrc32(u8 *buf, int len)
u8 *p;
u32 crc;
 
-   if (bcrc32initialized == 0) crc32_init();
+   if (bcrc32initialized == 0)
+   crc32_init();
 
crc = 0x;   /* preload shift register, per CRC-32 spec */
 
@@ -559,8 +560,10 @@ static void phase2(u8 *rc4key, const u8 *tk, const u16 
*p1k, u16 iv16)
u16 PPK[6];  /* temporary key for mixing*/
 
/* Note: all adds in the PPK[] equations below are mod 2**16 */
-   for (i = 0; i < 5; i++) PPK[i] = p1k[i];/* first, copy P1K to PPK   
   */
-   PPK[5] = p1k[4] + iv16; /* next,  add in IV16   
   */
+   for (i = 0; i < 5; i++)
+   PPK[i] = p1k[i];/* first, copy P1K to PPK  */
+
+   PPK[5] = p1k[4] + iv16; /* next,  add in IV16  */
 
/* Bijective non-linear mixing of the 96 bits of PPK[0..5]   */
PPK[0] +=_S_(PPK[5] ^ TK16(0));   /* Mix key in each "round" */
@@ -960,7 +963,8 @@ static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext)
u8 intermediateb[16];
u8 round_key[16];
 
-   for (i = 0; i < 16; i++) round_key[i] = key[i];
+   for (i = 0; i < 16; i++)
+   round_key[i] = key[i];
 
for (round = 0; round < 11; round++) {
if (round == 0) {
@@ -1044,7 +1048,8 @@ static void construct_mic_header2(u8 *mic_header2, u8 
*mpdu, int a4_exists,
 {
int i;
 
-   for (i = 0; i < 16; i++) mic_header2[i] = 0x00;
+   for (i = 0; i < 16; i++)
+   mic_header2[i] = 0x00;
 
mic_header2[0] = mpdu[16];/* A3 */
mic_header2[1] = mpdu[17];
@@ -1057,7 +1062,8 @@ static void construct_mic_header2(u8 *mic_header2, u8 
*mpdu, int a4_exists,
mic_header2[7] = 0x00; /* mpdu[23]; */
 
if (!qc_exists && a4_exists) {
-   for (i = 0; i < 6; i++) mic_header2[8+i] = mpdu[24+i];   /* A4 
*/
+   for (i = 0; i < 6; i++)
+   mic_header2[8+i] = mpdu[24+i];   /* A4 */
}
 
if (qc_exists && !a4_exists) {
@@ -1066,7 +1072,8 @@ static void construct_mic_header2(u8 *mic_header2, u8 
*mpdu, int a4_exists,
}
 
if (qc_exists && a4_exists) {
-   for (i = 0; i < 6; i++) mic_header2[8+i] = mpdu[24+i];   /* A4 
*/
+   for (i = 0; i < 6; i++)
+   mic_header2[8+i] = mpdu[24+i];   /* A4 */
 
mic_header2[14] = mpdu[30] & 0x0f;
mic_header2[15] = mpdu[31] & 0x00;
@@ -1084,7 +1091,9 @@ static void construct_ctr_preload(u8 *ctr_preload, int 
a4_exists, int qc_exists,
 {
int i = 0;
 
-   for (i = 0; i < 16; i++) ctr_preload[i] = 0x00;
+   for (i = 0; i < 16; i++)
+   ctr_preload[i] = 0x00;
+
i = 0;
 
ctr_preload[0] = 0x01;  /* flag */
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 06/15] staging: rtl8723au: else is not generally useful after a return

2015-03-28 Thread M. Vefa Bicakci
Correct a checkpatch.pl warning regarding rtl8723au's
rtw_security.c::crc32_init pointing out that having an else statement
after a break or a return is not useful.

drivers/staging/rtl8723au/core/rtw_security.c:105:
WARNING: else is not generally useful after a break or return

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 42 ++-
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index f7b1d45981..f7571cf091 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -99,31 +99,33 @@ static u8 crc32_reverseBit(u8 data)
 
 static void crc32_init(void)
 {
+   int i, j;
+   u32 c;
+   u8 *p, *p1;
+   u8 k;
 
if (bcrc32initialized == 1)
return;
-   else{
-   int i, j;
-   u32 c;
-   u8 *p = (u8 *), *p1;
-   u8 k;
-
-   c = 0x1234;
-
-   for (i = 0; i < 256; ++i) {
-   k = crc32_reverseBit((u8)i);
-   for (c = ((u32)k) << 24, j = 8; j > 0; --j) {
-   c = c & 0x8000 ? (c << 1) ^ CRC32_POLY : (c 
<< 1);
-   }
-   p1 = (u8 *)_table[i];
-
-   p1[0] = crc32_reverseBit(p[3]);
-   p1[1] = crc32_reverseBit(p[2]);
-   p1[2] = crc32_reverseBit(p[1]);
-   p1[3] = crc32_reverseBit(p[0]);
+
+   p = (u8 *) 
+   c = 0x1234;
+
+   for (i = 0; i < 256; ++i) {
+   k = crc32_reverseBit((u8)i);
+
+   for (c = ((u32)k) << 24, j = 8; j > 0; --j) {
+   c = c & 0x8000 ? (c << 1) ^ CRC32_POLY : (c << 1);
}
-   bcrc32initialized = 1;
+
+   p1 = (u8 *)_table[i];
+
+   p1[0] = crc32_reverseBit(p[3]);
+   p1[1] = crc32_reverseBit(p[2]);
+   p1[2] = crc32_reverseBit(p[1]);
+   p1[3] = crc32_reverseBit(p[0]);
}
+
+   bcrc32initialized = 1;
 }
 
 static u32 getcrc32(u8 *buf, int len)
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 09/15] staging: rtl8723au: that open brace should be on the previous line

2015-03-28 Thread M. Vefa Bicakci
Correct two instances of the checkpatch.pl error indicating that the
opening curly braces should not be on new lines:
ERROR: that open brace { should be on the previous line

Signed-off-by: M. Vefa Bicakci 

---

v3: Make sure that all edited lines are at most 80 characters wide.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 803f8965a4..0557a0df52 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -760,8 +760,8 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 
*((u32 *)crc) = le32_to_cpu(getcrc32(payload, length - 4));
 
-   if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] || 
crc[1] != payload[length - 3] || crc[0] != payload[length - 4])
-   {
+   if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
+   crc[1] != payload[length - 3] || crc[0] != payload[length - 4]) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
("rtw_wep_decrypt23a:icv error crc[3](%x)!= payload[length-1](%x) || 
crc[2](%x)!= payload[length-2](%x) || crc[1](%x)!= payload[length-3](%x) || 
crc[0](%x)!= payload[length-4](%x)\n",
crc[3], payload[length - 1], crc[2], 
payload[length - 2], crc[1], payload[length - 3], crc[0], payload[length - 4]));
res = _FAIL;
@@ -845,8 +845,7 @@ static void next_key(u8 *key, int round)
 {
u8 rcon;
u8 sbox_key[4];
-   u8 rcon_table[12] =
-   {
+   u8 rcon_table[12] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x1b, 0x36, 0x36, 0x36
};
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 05/15] staging: rtl8723au: Reorganize a few functions to remove indentation

2015-03-28 Thread M. Vefa Bicakci
Prior to this commit, functions rtw_tkip_encrypt23a and rtw_tkip_decrypt23a had
large if blocks which contained the majority of the logic in the functions.

Rework these functions so that if the negated version of the aforementioned if
blocks' conditions are true, we return from the function with _FAIL, as
expected by the calling code.

This lets us remove two levels of indentation from the functions in
question, making them more readable.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 178 +-
 1 file changed, 88 insertions(+), 90 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index df1787f20e..f7b1d45981 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -618,6 +618,9 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
struct xmit_priv *pxmitpriv = >xmitpriv;
int res = _SUCCESS;
 
+   if (pattrib->encrypt != WLAN_CIPHER_SUITE_TKIP)
+   return _FAIL;
+
if (!pxmitframe->buf_addr)
return _FAIL;
 
@@ -625,71 +628,66 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
 
pframe = pxmitframe->buf_addr + hw_hdr_offset;
/* 4 start to encrypt each fragment */
-   if (pattrib->encrypt == WLAN_CIPHER_SUITE_TKIP) {
-   if (pattrib->psta)
-   stainfo = pattrib->psta;
-   else {
-   DBG_8723A("%s, call rtw_get_stainfo()\n", __func__);
-   stainfo = rtw_get_stainfo23a(>stapriv,
->ra[0]);
-   }
-
-   if (stainfo != NULL) {
-
-   if (!(stainfo->state & _FW_LINKED)) {
-   DBG_8723A("%s, psta->state(0x%x) != 
_FW_LINKED\n", __func__, stainfo->state);
-   return _FAIL;
-   }
+   if (pattrib->psta)
+   stainfo = pattrib->psta;
+   else {
+   DBG_8723A("%s, call rtw_get_stainfo()\n", __func__);
+   stainfo = rtw_get_stainfo23a(>stapriv,
+>ra[0]);
+   }
 
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
("rtw_tkip_encrypt23a: stainfo!= NULL!!!\n"));
+   if (stainfo == NULL) {
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
("rtw_tkip_encrypt23a: stainfo == NULL!!!\n"));
+   DBG_8723A("%s, psta == NUL\n", __func__);
+   return _FAIL;
+   }
 
-   if (is_multicast_ether_addr(pattrib->ra))
-   prwskey = 
psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey;
-   else
-   prwskey = >dot118021x_UncstKey.skey[0];
+   if (!(stainfo->state & _FW_LINKED)) {
+   DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, 
stainfo->state);
+   return _FAIL;
+   }
 
-   prwskeylen = 16;
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("rtw_tkip_encrypt23a: 
stainfo!= NULL!!!\n"));
 
-   for (curfragnum = 0; curfragnum < pattrib->nr_frags; 
curfragnum++) {
-   iv = pframe+pattrib->hdrlen;
-   payload = 
pframe+pattrib->iv_len+pattrib->hdrlen;
+   if (is_multicast_ether_addr(pattrib->ra))
+   prwskey = 
psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey;
+   else
+   prwskey = >dot118021x_UncstKey.skey[0];
 
-   GET_TKIP_PN(iv, dot11txpn);
+   prwskeylen = 16;
 
-   pnl = (u16)(dot11txpn.val);
-   pnh = (u32)(dot11txpn.val>>16);
+   for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) {
+   iv = pframe+pattrib->hdrlen;
+   payload = pframe+pattrib->iv_len+pattrib->hdrlen;
 
-   phase1((u16 *)[0], prwskey, 
>ta[0], pnh);
+   GET_TKIP_PN(iv, dot11txpn);
 
-   phase2([0], prwskey, (u16 *)[0], 
pnl);
+   pnl = (u16)(dot11txpn.val);
+   pnh = (u32)(dot11txpn.val>>16);
 
-   if ((curfragnum + 1) == pattrib->nr_frags) {
/* 4 the last fragment */
-   length = 
pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len - pattrib->icv_len;
-   RT_TRACE(_module_rtl871x_security_c_, 
_drv_info_, ("pattrib->iv_l

[PATCH v4 13/15] staging: rtl8723au: Rework two byte array comparisons

2015-03-28 Thread M. Vefa Bicakci
Prior to this commit, rtl8723au's rtw_security.c had two instances of
byte array comparisons (for CRC checks) where the individual elements
of the byte arrays were compared one by one and an error trace would
be output if the byte arrays were determined to be different.

This commit improves the readability of the CRC verification by
placing the individual 4 bytes of each byte array into an 32-bit
unsigned integer and comparing the two resulting integers.

Thanks to Larry Finger for spotting the code style issues in the
previous version of this commit, and thanks to Joe Perches for
suggesting the use of 32-bit integer comparisons instead of byte
array comparisons.

Signed-off-by: M. Vefa Bicakci 

---

v2: Correct code style issues and compare 32-bit integers instead of
byte arrays. Update the commit message to better reflect the nature
of the changes.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 39 ++-
 1 file changed, 14 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 4330479ee0..eb3544866a 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -210,7 +210,7 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
 struct recv_frame *precvframe)
 {
/*  exclude ICV */
-   u8 crc[4];
+   u32 actual_crc, expected_crc;
struct arc4context mycontext;
int length;
u32 keylength;
@@ -243,19 +243,14 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
arcfour_encrypt(, payload, payload, length);
 
/* calculate icv and compare the icv */
-   *((u32 *)crc) = le32_to_cpu(getcrc32(payload, length - 4));
+   actual_crc = le32_to_cpu(getcrc32(payload, length - 4));
+   expected_crc = le32_to_cpu(get_unaligned_le32([length - 4]));
 
-   if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
-   crc[1] != payload[length - 3] || crc[0] != payload[length - 4]) {
+   if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-("rtw_wep_decrypt23a:icv error crc[3](%x)!= payload"
- "[length-1](%x) || crc[2](%x)!= payload[length-2](%x)"
- " || crc[1](%x)!= payload[length-3](%x) || crc[0](%x)"
- "!= payload[length-4](%x)\n",
- crc[3], payload[length - 1],
- crc[2], payload[length - 2],
- crc[1], payload[length - 3],
- crc[0], payload[length - 4]));
+("rtw_wep_decrypt23a:icv CRC mismatch: "
+ "actual: %08x, expected: %08x\n",
+ actual_crc, expected_crc));
}
 }
 
@@ -702,7 +697,7 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
u32 pnh;
u8 rc4key[16];
u8 ttkey[16];
-   u8 crc[4];
+   u32 actual_crc, expected_crc;
struct arc4context mycontext;
int length;
u32 prwskeylen;
@@ -757,20 +752,14 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
arcfour_init(, rc4key, 16);
arcfour_encrypt(, payload, payload, length);
 
-   *((u32 *)crc) = le32_to_cpu(getcrc32(payload, length - 4));
+   actual_crc = le32_to_cpu(getcrc32(payload, length - 4));
+   expected_crc = le32_to_cpu(get_unaligned_le32([length - 4]));
 
-   if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
-   crc[1] != payload[length - 3] || crc[0] != payload[length - 4]) {
+   if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-("rtw_wep_decrypt23a:icv error "
- "crc[3](%x)!= payload[length-1](%x) || "
- "crc[2](%x)!= payload[length-2](%x) || "
- "crc[1](%x)!= payload[length-3](%x) || "
- "crc[0](%x)!= payload[length-4](%x)\n",
- crc[3], payload[length - 1],
- crc[2], payload[length - 2],
- crc[1], payload[length - 3],
- crc[0], payload[length - 4]));
+("rtw_wep_decrypt23a:icv CRC mismatch: "
+ "actual: %08x, expected: %08x\n",
+ actual_crc, expected_crc));
res = _FAIL;
}
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 07/15] staging: rtl8723au: Remove unneeded curly braces

2015-03-28 Thread M. Vefa Bicakci
Correct a number of checkpatch.pl warnings in rtl8723au's rtw_security.c
related to the existence of unnecessary curly braces around single
statement blocks:
WARNING: braces {} are not necessary for single statement blocks

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 16 +---
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index f7571cf091..b4327aaf71 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -113,9 +113,8 @@ static void crc32_init(void)
for (i = 0; i < 256; ++i) {
k = crc32_reverseBit((u8)i);
 
-   for (c = ((u32)k) << 24, j = 8; j > 0; --j) {
+   for (c = ((u32)k) << 24, j = 8; j > 0; --j)
c = c & 0x8000 ? (c << 1) ^ CRC32_POLY : (c << 1);
-   }
 
p1 = (u8 *)_table[i];
 
@@ -267,9 +266,8 @@ static u32 secmicgetuint32(u8 *p)
s32 i;
u32 res = 0;
 
-   for (i = 0; i < 4; i++) {
+   for (i = 0; i < 4; i++)
res |= ((u32)(*p++)) << (8 * i);
-   }
 
return res;
 }
@@ -353,9 +351,8 @@ void rtw_secgetmic23a(struct mic_data *pmicdata, u8 *dst)
rtw_secmicappend23abyte23a(pmicdata, 0);
rtw_secmicappend23abyte23a(pmicdata, 0);
/*  and then zeroes until the length is a multiple of 4 */
-   while (pmicdata->nBytesInM != 0) {
+   while (pmicdata->nBytesInM != 0)
rtw_secmicappend23abyte23a(pmicdata, 0);
-   }
/*  The appendByte function has already computed the result. */
secmicputuint32(dst, pmicdata->L);
secmicputuint32(dst + 4, pmicdata->R);
@@ -871,10 +868,8 @@ static void byte_sub(u8 *in, u8 *out)
 {
int i;
 
-   for (i = 0; i < 16; i++) {
+   for (i = 0; i < 16; i++)
out[i] = sbox(in[i]);
-   }
-
 }
 
 static void shift_row(u8 *in, u8 *out)
@@ -935,9 +930,8 @@ static void mix_column(u8 *in, u8 *out)
 
for (i = 3; i > 0; i--) { /* logical shift left 1 bit */
andf7[i] = andf7[i] << 1;
-   if ((andf7[i - 1] & 0x80) == 0x80) {
+   if ((andf7[i - 1] & 0x80) == 0x80)
andf7[i] = (andf7[i] | 0x01);
-   }
}
andf7[0] = andf7[0] << 1;
andf7[0] = andf7[0] & 0xfe;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 02/15] staging: rtl8723au: Fix "before/around/after" whitespace issues

2015-03-28 Thread M. Vefa Bicakci
Correct a number of "space(s) required before/around/after" checkpatch.pl
issues in a number of functions in rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci 

---

v2: Correct one more whitespace issue ("length-4") in
rtw_tkip_decrypt23a.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 175 +-
 1 file changed, 87 insertions(+), 88 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 088533c5b1..cb78d6dd9c 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -129,14 +129,14 @@ static void crc32_init(void)
 static u32 getcrc32(u8 *buf, int len)
 {
u8 *p;
-   u32  crc;
+   u32 crc;
 
if (bcrc32initialized == 0) crc32_init();
 
crc = 0x;   /* preload shift register, per CRC-32 spec */
 
for (p = buf; len > 0; ++p, --len)
-   crc = crc32_table[ (crc ^ *p) & 0xff] ^ (crc >> 8);
+   crc = crc32_table[(crc ^ *p) & 0xff] ^ (crc >> 8);
 
return ~crc;/* transmit complement, per CRC-32 spec */
 }
@@ -182,7 +182,7 @@ void rtw_wep_encrypt23a(struct rtw_adapter *padapter,
if ((curfragnum + 1) == pattrib->nr_frags) {
/* the last fragment */
length = pattrib->last_txcmdsz - pattrib->hdrlen -
-   pattrib->iv_len- pattrib->icv_len;
+   pattrib->iv_len - pattrib->icv_len;
 
*((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
 
@@ -265,8 +265,8 @@ static u32 secmicgetuint32(u8 *p)
s32 i;
u32 res = 0;
 
-   for (i = 0; i<4; i++) {
-   res |= ((u32)(*p++)) << (8*i);
+   for (i = 0; i < 4; i++) {
+   res |= ((u32)(*p++)) << (8 * i);
}
 
return res;
@@ -277,7 +277,7 @@ static void secmicputuint32(u8 *p, u32 val)
 {
long i;
 
-   for (i = 0; i<4; i++) {
+   for (i = 0; i < 4; i++) {
*p++ = (u8) (val & 0xff);
val >>= 8;
}
@@ -310,7 +310,7 @@ void rtw_secmicappend23abyte23a(struct mic_data *pmicdata, 
u8 b)
 {
 
/*  Append the byte to our word-sized buffer */
-   pmicdata->M |= ((unsigned long)b) << (8*pmicdata->nBytesInM);
+   pmicdata->M |= ((unsigned long)b) << (8 * pmicdata->nBytesInM);
pmicdata->nBytesInM++;
/*  Process the word if it is full. */
if (pmicdata->nBytesInM >= 4) {
@@ -334,7 +334,7 @@ void rtw_secmicappend23a(struct mic_data *pmicdata, u8 
*src, u32 nbytes)
 {
 
/*  This is simple */
-   while(nbytes > 0) {
+   while (nbytes > 0) {
rtw_secmicappend23abyte23a(pmicdata, *src++);
nbytes--;
}
@@ -351,12 +351,12 @@ void rtw_secgetmic23a(struct mic_data *pmicdata, u8 *dst)
rtw_secmicappend23abyte23a(pmicdata, 0);
rtw_secmicappend23abyte23a(pmicdata, 0);
/*  and then zeroes until the length is a multiple of 4 */
-   while(pmicdata->nBytesInM != 0) {
+   while (pmicdata->nBytesInM != 0) {
rtw_secmicappend23abyte23a(pmicdata, 0);
}
/*  The appendByte function has already computed the result. */
secmicputuint32(dst, pmicdata->L);
-   secmicputuint32(dst+4, pmicdata->R);
+   secmicputuint32(dst + 4, pmicdata->R);
/*  Reset to the empty message. */
secmicclear(pmicdata);
 
@@ -367,10 +367,10 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 {
 
struct mic_data micdata;
-   u8 priority[4]={0x0, 0x0, 0x0, 0x0};
+   u8 priority[4] = {0x0, 0x0, 0x0, 0x0};
 
rtw_secmicsetkey23a(, key);
-   priority[0]= pri;
+   priority[0] = pri;
 
/* Michael MIC pseudo header: DA, SA, 3 x 0, Priority */
if (header[1]&1) {   /* ToDS == 1 */
@@ -401,7 +401,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define   Lo8(v16)   ((u8)((v16)   & 0x00FF))
 #define   Hi8(v16)   ((u8)(((v16) >> 8) & 0x00FF))
 #define  Lo16(v32)   ((u16)((v32)   & 0x))
-#define  Hi16(v32)   ((u16)(((v32) >>16) & 0x))
+#define  Hi16(v32)   ((u16)(((v32) >> 16) & 0x))
 #define  Mk16(hi, lo) ((lo) ^ (((u16)(hi)) << 8))
 
 /* select the Nth 16-bit word of the temporal key unsigned char array TK[]   */
@@ -418,7 +418,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define RC4_KEY_SIZE 16/* 128-bit RC4KEY (104 bits unknown) */
 
 /* 2-unsigned char by 2-unsigned char subset of the full AES S-box table */
-static const unsigned short Sbox1[2][256]=   /* Sbox for hash (can be in 
ROM) */
+static const u

[PATCH v4 04/15] staging: rtl8723au: Fix the indentation of two lines

2015-03-28 Thread M. Vefa Bicakci
Correct the indentation of two lines in rtw_tkip_encrypt23a function in
rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 17234e0bf1..df1787f20e 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -679,8 +679,8 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
arcfour_encrypt(, payload, 
payload, length);
arcfour_encrypt(, 
payload+length, crc, 4);
 
-   pframe += pxmitpriv->frag_len;
-   pframe  = PTR_ALIGN(pframe, 4);
+   pframe += pxmitpriv->frag_len;
+   pframe  = PTR_ALIGN(pframe, 4);
}
}
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 14/15] staging: rtl8723au: Use __func__ in trace logs

2015-03-28 Thread M. Vefa Bicakci
Rework the trace log-related lines in rtl8723au's rtw_security.c
to use the __func__ GCC magic variable instead of hardcoding the
function names into the trace log strings. This also corrects a
copy-paste-related typo in the function named rtw_tkip_decrypt23a.

Thanks to Jes Sorensen for the suggestion to use __func__.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 49 ---
 1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index eb3544866a..cdb3707fb2 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -248,9 +248,9 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
 
if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-("rtw_wep_decrypt23a:icv CRC mismatch: "
+("%s:icv CRC mismatch: "
  "actual: %08x, expected: %08x\n",
- actual_crc, expected_crc));
+ __func__, actual_crc, expected_crc));
}
 }
 
@@ -634,7 +634,8 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
}
 
if (stainfo == NULL) {
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
("rtw_tkip_encrypt23a: stainfo == NULL!!!\n"));
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
+("%s: stainfo == NULL!!!\n", __func__));
DBG_8723A("%s, psta == NUL\n", __func__);
return _FAIL;
}
@@ -644,7 +645,8 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
return _FAIL;
}
 
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("rtw_tkip_encrypt23a: 
stainfo!= NULL!!!\n"));
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
+("%s: stainfo!= NULL!!!\n", __func__));
 
if (is_multicast_ether_addr(pattrib->ra))
prwskey = 
psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey;
@@ -718,7 +720,8 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
stainfo = rtw_get_stainfo23a(>stapriv,
 >ta[0]);
if (stainfo == NULL) {
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
("rtw_tkip_decrypt23a: stainfo == NULL!!!\n"));
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
+("%s: stainfo == NULL!!!\n", __func__));
return _FAIL;
}
 
@@ -731,7 +734,8 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
prwskey = 
psecuritypriv->dot118021XGrpKey[prxattrib->key_index].skey;
prwskeylen = 16;
} else {
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
("rtw_tkip_decrypt23a: stainfo!= NULL!!!\n"));
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
+("%s: stainfo!= NULL!!!\n", __func__));
prwskey = >dot118021x_UncstKey.skey[0];
prwskeylen = 16;
}
@@ -757,9 +761,9 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 
if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-("rtw_wep_decrypt23a:icv CRC mismatch: "
+("%s:icv CRC mismatch: "
  "actual: %08x, expected: %08x\n",
- actual_crc, expected_crc));
+ __func__, actual_crc, expected_crc));
res = _FAIL;
}
 
@@ -1296,7 +1300,7 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
 
if (!stainfo) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-("rtw_aes_encrypt23a: stainfo == NULL!!!\n"));
+("%s: stainfo == NULL!!!\n", __func__));
DBG_8723A("%s, psta == NUL\n", __func__);
res = _FAIL;
goto out;
@@ -1307,7 +1311,7 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
return _FAIL;
}
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-("rtw_aes_encrypt23a: stainfo!= NULL!!!\n"));
+("%s: stainfo!= NULL!!!\n", __func__));
 
if (is_multicast_ether_addr(pattrib->ra))
prwskey = 
psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey;
@@ -1535,10 +1539,16 @@ static int aes_decipher(u8 *key, uint hdrlen, u8 
*pframe, uint plen)
for (i = 0; i < 8; i++) {
if (pframe[hdrlen 

[PATCH v4 11/15] staging: rtl8723au: Adjust whitespace in and around comments

2015-03-28 Thread M. Vefa Bicakci
As the subject indicates, adjust whitespace in and around comments
in rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 114 +-
 1 file changed, 57 insertions(+), 57 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index f8d0c0a63f..8591b49664 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -135,12 +135,12 @@ static u32 getcrc32(u8 *buf, int len)
if (bcrc32initialized == 0)
crc32_init();
 
-   crc = 0x;   /* preload shift register, per CRC-32 spec */
+   crc = 0x; /* preload shift register, per CRC-32 spec */
 
for (p = buf; len > 0; ++p, --len)
crc = crc32_table[(crc ^ *p) & 0xff] ^ (crc >> 8);
 
-   return ~crc;/* transmit complement, per CRC-32 spec */
+   return ~crc; /* transmit complement, per CRC-32 spec */
 }
 
 /* Need to consider the fragment  situation */
@@ -152,7 +152,7 @@ void rtw_wep_encrypt23a(struct rtw_adapter *padapter,
struct arc4context mycontext;
int curfragnum, length, index;
u32 keylength;
-   u8 *pframe, *payload, *iv;/* wepkey */
+   u8 *pframe, *payload, *iv; /* wepkey */
u8 wepkey[16];
u8 hw_hdr_offset = 0;
struct pkt_attrib *pattrib = >attrib;
@@ -373,15 +373,15 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
priority[0] = pri;
 
/* Michael MIC pseudo header: DA, SA, 3 x 0, Priority */
-   if (header[1]&1) {   /* ToDS == 1 */
-   rtw_secmicappend23a(, [16], 6);  /* DA */
-   if (header[1]&2)  /* From Ds == 1 */
+   if (header[1]&1) { /* ToDS == 1 */
+   rtw_secmicappend23a(, [16], 6); /* DA */
+   if (header[1]&2) /* From Ds == 1 */
rtw_secmicappend23a(, [24], 6);
else
rtw_secmicappend23a(, [10], 6);
-   } else {/* ToDS == 0 */
-   rtw_secmicappend23a(, [4], 6);   /* DA */
-   if (header[1]&2)  /* From Ds == 1 */
+   } else { /* ToDS == 0 */
+   rtw_secmicappend23a(, [4], 6); /* DA */
+   if (header[1]&2) /* From Ds == 1 */
rtw_secmicappend23a(, [16], 6);
else
rtw_secmicappend23a(, [10], 6);
@@ -403,7 +403,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define  Hi16(v32)   ((u16)(((v32) >> 16) & 0x))
 #define  Mk16(hi, lo) ((lo) ^ (((u16)(hi)) << 8))
 
-/* select the Nth 16-bit word of the temporal key unsigned char array TK[]   */
+/* select the Nth 16-bit word of the temporal key unsigned char array TK[] */
 #define  TK16(N) Mk16(tk[2*(N)+1], tk[2*(N)])
 
 /* S-box lookup: 16 bits --> 16 bits */
@@ -510,7 +510,7 @@ static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, 
u32 iv32)
 {
int  i;
 
-   /* Initialize the 80 bits of P1K[] from IV32 and TA[0..5] */
+   /* Initialize the 80 bits of P1K[] from IV32 and TA[0..5] */
p1k[0]  = Lo16(iv32);
p1k[1]  = Hi16(iv32);
p1k[2]  = Mk16(ta[1], ta[0]); /* use TA[] as little-endian */
@@ -526,7 +526,7 @@ static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, 
u32 iv32)
p1k[2] += _S_(p1k[1] ^ TK16((i & 1) + 4));
p1k[3] += _S_(p1k[2] ^ TK16((i & 1) + 6));
p1k[4] += _S_(p1k[3] ^ TK16((i & 1) + 0));
-   p1k[4] +=  (unsigned short)i;/* avoid 
"slide attacks" */
+   p1k[4] +=  (unsigned short) i; /* avoid "slide attacks" */
}
 
 }
@@ -557,41 +557,41 @@ static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, 
u32 iv32)
 static void phase2(u8 *rc4key, const u8 *tk, const u16 *p1k, u16 iv16)
 {
int  i;
-   u16 PPK[6];  /* temporary key for mixing*/
+   u16 PPK[6]; /* temporary key for mixing*/
 
-   /* Note: all adds in the PPK[] equations below are mod 2**16 */
+   /* Note: all adds in the PPK[] equations below are mod 2**16 */
for (i = 0; i < 5; i++)
-   PPK[i] = p1k[i];/* first, copy P1K to PPK  */
+   PPK[i] = p1k[i]; /* first, copy P1K to PPK */
 
-   PPK[5] = p1k[4] + iv16; /* next,  add in IV16  */
+   PPK[5] = p1k[4] + iv16; /* next,  add in IV16 */
 
-   /* Bijective non-linear mixing of the 96 bits of PPK[0..5]   */
-   PPK[0] +=_S_(PPK[5] ^ TK16(0));   /* Mix key in each "round" */
-   PPK[1] +=_S_(PPK[0] ^ TK16(1));
-   PPK[2] +=_S_(PPK[1] ^ TK16(2));
-   PPK[3] +=_S_(PPK[2] ^ TK16(3))

[PATCH v4 12/15] staging: rtl8723au: suspect code indent for conditional statements

2015-03-28 Thread M. Vefa Bicakci
Correct a number of indentation-with-spaces-and-tabs issues in
rtl8723au's rtw_security.c, according to checkpatch.pl:
WARNING: suspect code indent for conditional statements

Signed-off-by: M. Vefa Bicakci 

---

v3: Make sure that all edited lines are at most 80 characters wide.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 46 ---
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 8591b49664..4330479ee0 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -761,8 +761,16 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 
if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
crc[1] != payload[length - 3] || crc[0] != payload[length - 4]) {
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
("rtw_wep_decrypt23a:icv error crc[3](%x)!= payload[length-1](%x) || 
crc[2](%x)!= payload[length-2](%x) || crc[1](%x)!= payload[length-3](%x) || 
crc[0](%x)!= payload[length-4](%x)\n",
-   crc[3], payload[length - 1], crc[2], 
payload[length - 2], crc[1], payload[length - 3], crc[0], payload[length - 4]));
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
+("rtw_wep_decrypt23a:icv error "
+ "crc[3](%x)!= payload[length-1](%x) || "
+ "crc[2](%x)!= payload[length-2](%x) || "
+ "crc[1](%x)!= payload[length-3](%x) || "
+ "crc[0](%x)!= payload[length-4](%x)\n",
+ crc[3], payload[length - 1],
+ crc[2], payload[length - 2],
+ crc[1], payload[length - 3],
+ crc[0], payload[length - 4]));
res = _FAIL;
}
 
@@ -909,9 +917,9 @@ static void mix_column(u8 *in, u8 *out)
 
for (i = 0; i < 4; i++) {
if ((in[i] & 0x80) == 0x80)
-   add1b[i] = 0x1b;
+   add1b[i] = 0x1b;
else
-   add1b[i] = 0x00;
+   add1b[i] = 0x00;
}
 
swap_halfs[0] = in[2]; /* Swap halfs */
@@ -966,21 +974,21 @@ static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext)
 
for (round = 0; round < 11; round++) {
if (round == 0) {
-   xor_128(round_key, data, ciphertext);
-   next_key(round_key, round);
+   xor_128(round_key, data, ciphertext);
+   next_key(round_key, round);
} else if (round == 10) {
-   byte_sub(ciphertext, intermediatea);
-   shift_row(intermediatea, intermediateb);
-   xor_128(intermediateb, round_key, ciphertext);
+   byte_sub(ciphertext, intermediatea);
+   shift_row(intermediatea, intermediateb);
+   xor_128(intermediateb, round_key, ciphertext);
} else { /* 1 - 9 */
-   byte_sub(ciphertext, intermediatea);
-   shift_row(intermediatea, intermediateb);
-   mix_column([0], [0]);
-   mix_column([4], [4]);
-   mix_column([8], [8]);
-   mix_column([12], [12]);
-   xor_128(intermediatea, round_key, ciphertext);
-   next_key(round_key, round);
+   byte_sub(ciphertext, intermediatea);
+   shift_row(intermediatea, intermediateb);
+   mix_column([0], [0]);
+   mix_column([4], [4]);
+   mix_column([8], [8]);
+   mix_column([12], [12]);
+   xor_128(intermediatea, round_key, ciphertext);
+   next_key(round_key, round);
}
}
 
@@ -1481,7 +1489,7 @@ static int aes_decipher(u8 *key, uint hdrlen, u8 *pframe, 
uint plen)
for (j = 0; j < 16; j++)
padded_buffer[j] = 0x00;
for (j = 0; j < payload_remainder; j++)
-   padded_buffer[j] = message[payload_index++];
+   padded_buffer[j] = message[payload_index++];
bitwise_xor(aes_out, padded_buffer, chain_buffer);
aes128k128d(key, chain_buffer, aes_out);
}
@@ -1511,7 +1519,7 @@ static int aes_decipher(u8 *key, uint hdrlen, u8 *pframe, 
uint plen)
  message, pn_vector, num_blocks+1);
 
for (j = 0; j < 16; j++)
-padded_buffer[j] = 0x00;
+   padded_buffer[j] = 0x00;
for (j = 0; j < payload_re

[PATCH v4 15/15] staging: rtl8723au: Remove unneeded comments

2015-03-28 Thread M. Vefa Bicakci
This commit removes a number of unneeded comments. Two of the
aforementioned comments were most likely meant to aid with version
control, whereas the remaining two comments relate to (now unused)
local variable names.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index cdb3707fb2..309f3d969e 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -671,14 +671,14 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
if ((curfragnum+1) == pattrib->nr_frags) { /* 4 the last 
fragment */
length = 
pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len - pattrib->icv_len;
RT_TRACE(_module_rtl871x_security_c_, _drv_info_, 
("pattrib->iv_len =%x, pattrib->icv_len =%x\n", pattrib->iv_len, 
pattrib->icv_len));
-   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length)); 
/* modified by Amy */
+   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
 
arcfour_init(, rc4key, 16);
arcfour_encrypt(, payload, payload, length);
arcfour_encrypt(, payload+length, crc, 4);
} else {
length = 
pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
-   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length)); 
/* modified by Amy */
+   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
arcfour_init(, rc4key, 16);
arcfour_encrypt(, payload, payload, length);
arcfour_encrypt(, payload+length, crc, 4);
@@ -1272,7 +1272,7 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
/* Intermediate Buffers */
int curfragnum, length;
u32 prwskeylen;
-   u8 *pframe, *prwskey; /* *payload, *iv */
+   u8 *pframe, *prwskey;
u8 hw_hdr_offset = 0;
struct sta_info *stainfo;
struct pkt_attrib *pattrib = >attrib;
@@ -1563,7 +1563,7 @@ int rtw_aes_decrypt23a(struct rtw_adapter *padapter,
struct security_priv *psecuritypriv = >securitypriv;
struct sk_buff *skb = precvframe->pkt;
int length;
-   u8 *pframe, *prwskey; /* *payload, *iv */
+   u8 *pframe, *prwskey;
int res = _SUCCESS;
 
pframe = skb->data;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 10/15] staging: rtl8723au: No spaces at the start of a line

2015-03-28 Thread M. Vefa Bicakci
Prior to this commit, a large block of constants used to represent
an AES S-box table were indented with spaces in rtl8723au's
rtw_security.c. Correct the checkpatch.pl warnings indicating that
spaces should not be used to indent lines:
WARNING: please, no spaces at the start of a line

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 140 +-
 1 file changed, 70 insertions(+), 70 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 0557a0df52..f8d0c0a63f 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -417,76 +417,76 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define RC4_KEY_SIZE 16/* 128-bit RC4KEY (104 bits unknown) */
 
 /* 2-unsigned char by 2-unsigned char subset of the full AES S-box table */
-static const unsigned short Sbox1[2][256] =   /* Sbox for hash (can be in 
ROM) */
-{ {
-   0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
-   0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
-   0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B,
-   0x41EC, 0xB367, 0x5FFD, 0x45EA, 0x23BF, 0x53F7, 0xE496, 0x9B5B,
-   0x75C2, 0xE11C, 0x3DAE, 0x4C6A, 0x6C5A, 0x7E41, 0xF502, 0x834F,
-   0x685C, 0x51F4, 0xD134, 0xF908, 0xE293, 0xAB73, 0x6253, 0x2A3F,
-   0x080C, 0x9552, 0x4665, 0x9D5E, 0x3028, 0x37A1, 0x0A0F, 0x2FB5,
-   0x0E09, 0x2436, 0x1B9B, 0xDF3D, 0xCD26, 0x4E69, 0x7FCD, 0xEA9F,
-   0x121B, 0x1D9E, 0x5874, 0x342E, 0x362D, 0xDCB2, 0xB4EE, 0x5BFB,
-   0xA4F6, 0x764D, 0xB761, 0x7DCE, 0x527B, 0xDD3E, 0x5E71, 0x1397,
-   0xA6F5, 0xB968, 0x, 0xC12C, 0x4060, 0xE31F, 0x79C8, 0xB6ED,
-   0xD4BE, 0x8D46, 0x67D9, 0x724B, 0x94DE, 0x98D4, 0xB0E8, 0x854A,
-   0xBB6B, 0xC52A, 0x4FE5, 0xED16, 0x86C5, 0x9AD7, 0x6655, 0x1194,
-   0x8ACF, 0xE910, 0x0406, 0xFE81, 0xA0F0, 0x7844, 0x25BA, 0x4BE3,
-   0xA2F3, 0x5DFE, 0x80C0, 0x058A, 0x3FAD, 0x21BC, 0x7048, 0xF104,
-   0x63DF, 0x77C1, 0xAF75, 0x4263, 0x2030, 0xE51A, 0xFD0E, 0xBF6D,
-   0x814C, 0x1814, 0x2635, 0xC32F, 0xBEE1, 0x35A2, 0x88CC, 0x2E39,
-   0x9357, 0x55F2, 0xFC82, 0x7A47, 0xC8AC, 0xBAE7, 0x322B, 0xE695,
-   0xC0A0, 0x1998, 0x9ED1, 0xA37F, 0x4466, 0x547E, 0x3BAB, 0x0B83,
-   0x8CCA, 0xC729, 0x6BD3, 0x283C, 0xA779, 0xBCE2, 0x161D, 0xAD76,
-   0xDB3B, 0x6456, 0x744E, 0x141E, 0x92DB, 0x0C0A, 0x486C, 0xB8E4,
-   0x9F5D, 0xBD6E, 0x43EF, 0xC4A6, 0x39A8, 0x31A4, 0xD337, 0xF28B,
-   0xD532, 0x8B43, 0x6E59, 0xDAB7, 0x018C, 0xB164, 0x9CD2, 0x49E0,
-   0xD8B4, 0xACFA, 0xF307, 0xCF25, 0xCAAF, 0xF48E, 0x47E9, 0x1018,
-   0x6FD5, 0xF088, 0x4A6F, 0x5C72, 0x3824, 0x57F1, 0x73C7, 0x9751,
-   0xCB23, 0xA17C, 0xE89C, 0x3E21, 0x96DD, 0x61DC, 0x0D86, 0x0F85,
-   0xE090, 0x7C42, 0x71C4, 0xCCAA, 0x90D8, 0x0605, 0xF701, 0x1C12,
-   0xC2A3, 0x6A5F, 0xAEF9, 0x69D0, 0x1791, 0x9958, 0x3A27, 0x27B9,
-   0xD938, 0xEB13, 0x2BB3, 0x2233, 0xD2BB, 0xA970, 0x0789, 0x33A7,
-   0x2DB6, 0x3C22, 0x1592, 0xC920, 0x8749, 0xAAFF, 0x5078, 0xA57A,
-   0x038F, 0x59F8, 0x0980, 0x1A17, 0x65DA, 0xD731, 0x84C6, 0xD0B8,
-   0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A,
-  },
-
-  {  /* second half of table is unsigned char-reversed version of first! */
-   0xA5C6, 0x84F8, 0x99EE, 0x8DF6, 0x0DFF, 0xBDD6, 0xB1DE, 0x5491,
-   0x5060, 0x0302, 0xA9CE, 0x7D56, 0x19E7, 0x62B5, 0xE64D, 0x9AEC,
-   0x458F, 0x9D1F, 0x4089, 0x87FA, 0x15EF, 0xEBB2, 0xC98E, 0x0BFB,
-   0xEC41, 0x67B3, 0xFD5F, 0xEA45, 0xBF23, 0xF753, 0x96E4, 0x5B9B,
-   0xC275, 0x1CE1, 0xAE3D, 0x6A4C, 0x5A6C, 0x417E, 0x02F5, 0x4F83,
-   0x5C68, 0xF451, 0x34D1, 0x08F9, 0x93E2, 0x73AB, 0x5362, 0x3F2A,
-   0x0C08, 0x5295, 0x6546, 0x5E9D, 0x2830, 0xA137, 0x0F0A, 0xB52F,
-   0x090E, 0x3624, 0x9B1B, 0x3DDF, 0x26CD, 0x694E, 0xCD7F, 0x9FEA,
-   0x1B12, 0x9E1D, 0x7458, 0x2E34, 0x2D36, 0xB2DC, 0xEEB4, 0xFB5B,
-   0xF6A4, 0x4D76, 0x61B7, 0xCE7D, 0x7B52, 0x3EDD, 0x715E, 0x9713,
-   0xF5A6, 0x68B9, 0x, 0x2CC1, 0x6040, 0x1FE3, 0xC879, 0xEDB6,
-   0xBED4, 0x468D, 0xD967, 0x4B72, 0xDE94, 0xD498, 0xE8B0, 0x4A85,
-   0x6BBB, 0x2AC5, 0xE54F, 0x16ED, 0xC586, 0xD79A, 0x5566, 0x9411,
-   0xCF8A, 0x10E9, 0x0604, 0x81FE, 0xF0A0, 0x4478, 0xBA25, 0xE34B,
-   0xF3A2, 0xFE5D, 0xC080, 0x8A05, 0xAD3F, 0xBC21, 0x4870, 0x04F1,
-   0xDF63, 0xC177, 0x75AF, 0x6342, 0x3020, 0x1AE5, 0x0EFD, 0x6DBF,
-   0x4C81, 0x1418, 0x3526, 0x2FC3, 0xE1BE, 0xA235, 0xCC88, 0x392E,
-   0x5793, 0xF255, 0x82FC, 0x477A, 0xACC8, 0xE7BA, 0x2B32, 0x95E6,
-   0xA0C0, 0x9819, 0xD19E, 0x7FA3, 0x6644, 0x7E54, 0xAB3B, 0x830B,
-   0xCA8C, 0x29C7, 0xD36B, 0x3C28, 0x79A7, 0xE2BC, 0x1D16, 0x76AD,
-   0x3BDB, 0x5664, 0x4E74, 0x1E14, 0xDB92, 0x0A0C, 0x6C48, 0xE4B8,
-   0x5D9F, 0x6EBD, 0xEF43, 0xA6C4, 0xA839, 0xA431, 0x37D3, 0x8BF2,
-   0x32D5, 0x438B, 0x596E, 0xB7DA, 0x8C01, 0x64B1, 0xD29C, 0xE049,
-   0xB4D8, 0xFAAC, 0x07F3, 0x25CF, 0xAFCA, 0x8EF4, 0xE947, 0x1810,
-   0xD56F, 0x88F0, 0x6F4A, 0x725C, 0x2438, 0xF157

[PATCH v4 01/15] staging: rtl8723au: Reformat whitespace to increase readability

2015-03-28 Thread M. Vefa Bicakci
Adjust the whitespace in the signature, local variable declaration and
initialization parts of a number of functions to increase readability
in rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci 

---

v2: Make sure that the arcfour_encrypt function's argument list is split
according to the kernel code style.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 79 +--
 1 file changed, 38 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 045a24c81b..088533c5b1 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -31,11 +31,11 @@ struct arc4context {
 
 static void arcfour_init(struct arc4context *parc4ctx, u8 *key, u32 key_len)
 {
-   u32 t, u;
-   u32 keyindex;
-   u32 stateindex;
+   u32 t, u;
+   u32 keyindex;
+   u32 stateindex;
u8 *state;
-   u32 counter;
+   u32 counter;
 
state = parc4ctx->state;
parc4ctx->x = 0;
@@ -55,7 +55,8 @@ static void arcfour_init(struct arc4context *parc4ctx, u8 
*key, u32 key_len)
}
 
 }
-static u32 arcfour_byte(   struct arc4context  *parc4ctx)
+
+static u32 arcfour_byte(struct arc4context *parc4ctx)
 {
u32 x;
u32 y;
@@ -75,16 +76,13 @@ static u32 arcfour_byte(struct arc4context  
*parc4ctx)
return state[(sx + sy) & 0xff];
 }
 
-static void arcfour_encrypt(   struct arc4context  *parc4ctx,
-   u8 *dest,
-   u8 *src,
-   u32 len)
+static void arcfour_encrypt(struct arc4context *parc4ctx, u8 *dest,
+   u8 *src, u32 len)
 {
-   u32 i;
+   u32 i;
 
for (i = 0; i < len; i++)
dest[i] = src[i] ^ (unsigned char)arcfour_byte(parc4ctx);
-
 }
 
 static int bcrc32initialized;
@@ -368,7 +366,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
   u8 *mic_code, u8 pri)
 {
 
-   struct mic_data micdata;
+   struct mic_data micdata;
u8 priority[4]={0x0, 0x0, 0x0, 0x0};
 
rtw_secmicsetkey23a(, key);
@@ -604,21 +602,21 @@ static void phase2(u8 *rc4key, const u8 *tk, const u16 
*p1k, u16 iv16)
 int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
struct xmit_frame *pxmitframe)
 {
-   u16 pnl;
-   u32 pnh;
-   u8  rc4key[16];
-   u8   ttkey[16];
-   u8  crc[4];
-   u8   hw_hdr_offset = 0;
+   u16 pnl;
+   u32 pnh;
+   u8 rc4key[16];
+   u8 ttkey[16];
+   u8 crc[4];
+   u8 hw_hdr_offset = 0;
struct arc4context mycontext;
-   int curfragnum, length;
-   u32 prwskeylen;
-   u8  *pframe, *payload, *iv, *prwskey;
+   int curfragnum, length;
+   u32 prwskeylen;
+   u8 *pframe, *payload, *iv, *prwskey;
union pn48 dot11txpn;
-   struct  sta_info*stainfo;
-   struct  pkt_attrib   *pattrib = >attrib;
-   struct  security_priv   *psecuritypriv = >securitypriv;
-   struct  xmit_priv   *pxmitpriv = >xmitpriv;
+   struct sta_info *stainfo;
+   struct pkt_attrib *pattrib = >attrib;
+   struct security_priv *psecuritypriv = >securitypriv;
+   struct xmit_priv *pxmitpriv = >xmitpriv;
int res = _SUCCESS;
 
if (!pxmitframe->buf_addr)
@@ -706,17 +704,17 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 {
u16 pnl;
u32 pnh;
-   u8   rc4key[16];
-   u8   ttkey[16];
-   u8  crc[4];
+   u8 rc4key[16];
+   u8 ttkey[16];
+   u8 crc[4];
struct arc4context mycontext;
-   int length;
-   u32 prwskeylen;
-   u8  *pframe, *payload, *iv, *prwskey;
+   int length;
+   u32 prwskeylen;
+   u8 *pframe, *payload, *iv, *prwskey;
union pn48 dot11txpn;
-   struct  sta_info*stainfo;
-   struct  rx_pkt_attrib *prxattrib = >attrib;
-   struct  security_priv *psecuritypriv = >securitypriv;
+   struct sta_info *stainfo;
+   struct rx_pkt_attrib *prxattrib = >attrib;
+   struct security_priv *psecuritypriv = >securitypriv;
struct sk_buff *skb = precvframe->pkt;
int res = _SUCCESS;
 
@@ -1128,8 +1126,8 @@ static void bitwise_xor(u8 *ina, u8 *inb, u8 *out)
 
 static int aes_cipher(u8 *key, uint hdrlen, u8 *pframe, uint plen)
 {
-   uintqc_exists, a4_exists, i, j, payload_remainder,
-   num_blocks, payload_index;
+   uint qc_exists, a4_exists, i, j, payload_remainder,
+num_blocks, payload_index;
u8 pn_vector[6];
u8 mic_iv[16];
u8 mic_header1[16];
@@ -1345,12 +1343,11 @@ out:
return res;
 }
 
-static int aes_decipher(u8 *key, uint  hdrlen,
-   u8 *pframe, uint pl

[PATCH v4 00/15] checkpatch clean-up of rtl8723au's rtw_security.c

2015-03-28 Thread M. Vefa Bicakci
These commits address a number of checkpatch.pl warnings and errors
in rtl8723au's rtw_security.c.

Prior to this set of commits, checkpatch.pl reported the following:
total: 76 errors, 138 warnings, 1621 lines checked

After applying this set of commits, checkpatch.pl reports the following:
total: 0 errors, 26 warnings, 1624 lines checked
where the only remaining warnings relate to lines longer than 80
characters and quoted strings split across multiple lines.

There are also a number of commits which improve the code in other ways.
For example, the commit titled "Reorganize a few functions to remove
indentation" reworks two functions to make them more readable, whereas
the commit titled "Rework two byte array comparisons" reworks two CRC
verifications for the same reason, and "Use __func__ in trace logs"
avoids hardcoding function names in trace logs to increase
maintainability.

All of the commits have been verified to compile successfully via the
use of the interactive rebase feature of git.

v4: Rebased onto Greg Kroah-Hartman's staging-next tree, on top of
the following commit
  commit 153fe946412b5da1a8808f79d4f7f4ebfa7586b0
  staging: fbtft: Do not use binary constants

In addition, fix-up the commit messages to move the patch revision
notes below the newly added "---" markers where needed.

v3: Rebased onto Greg Kroah-Hartman's staging-next tree, on top of
the following commit
  5ec293650827122df300581c17ca1d5de03bac3d.
  Staging: dgnc: release the lock before testing for nullity

Please see the individual commit messages for the changes
since v2. In summary, the following commits have been updated:
- that open brace should be on the previous line
- suspect code indent for conditional statements

The following commit is new:
- Use __func__ in trace logs

Finally, the following commit has been removed:
- Do not initialize a static to 0

v2: Please see the individual commit messages for the changes
since v1. In summary, the following commits have been updated:
- Reformat whitespace to increase readability
- Fix "before/around/after" whitespace issues
- Rework two byte array comparisons

M. Vefa Bicakci (15):
  staging: rtl8723au: Reformat whitespace to increase readability
  staging: rtl8723au: Fix "before/around/after" whitespace issues
  staging: rtl8723au: else should follow close brace
  staging: rtl8723au: Fix the indentation of two lines
  staging: rtl8723au: Reorganize a few functions to remove indentation
  staging: rtl8723au: else is not generally useful after a return
  staging: rtl8723au: Remove unneeded curly braces
  staging: rtl8723au: trailing statements should be on next line
  staging: rtl8723au: that open brace should be on the previous line
  staging: rtl8723au: No spaces at the start of a line
  staging: rtl8723au: Adjust whitespace in and around comments
  staging: rtl8723au: suspect code indent for conditional statements
  staging: rtl8723au: Rework two byte array comparisons
  staging: rtl8723au: Use __func__ in trace logs
  staging: rtl8723au: Remove unneeded comments

 drivers/staging/rtl8723au/core/rtw_security.c | 799 +-
 1 file changed, 401 insertions(+), 398 deletions(-)

-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 01/15] staging: rtl8723au: Reformat whitespace to increase readability

2015-03-28 Thread M. Vefa Bicakci
On 26/03/15 08:18 AM, Greg KH wrote:
> On Thu, Mar 19, 2015 at 12:39:04AM -0400, M. Vefa Bicakci wrote:
>> Adjust the whitespace in the signature, local variable declaration and
>> initialization parts of a number of functions to increase readability
>> in rtl8723au's rtw_security.c.
>>
>> v2: Make sure that the arcfour_encrypt function's argument list is split
>> according to the kernel code style.
> 
> The "v2" stuff here should go below the --- line, otherwise it will show
> up in the changelog :(
> 
> Please fix these all up and resend.

Hello Greg,

Thank you for the review!

I have addressed your comment in my local repository and I hope to send the 4th
revision of the patches soon.

Thanks again,

Vefa
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 02/15] staging: rtl8723au: Fix before/around/after whitespace issues

2015-03-28 Thread M. Vefa Bicakci
Correct a number of space(s) required before/around/after checkpatch.pl
issues in a number of functions in rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci m@runbox.com

---

v5: Correct even more whitespace issues.

v2: Correct one more whitespace issue (length-4) in
rtw_tkip_decrypt23a.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 219 +-
 1 file changed, 113 insertions(+), 106 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 92882f60bc0e..572fcf3f936d 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -129,14 +129,14 @@ static void crc32_init(void)
 static u32 getcrc32(u8 *buf, int len)
 {
u8 *p;
-   u32  crc;
+   u32 crc;
 
if (bcrc32initialized == 0) crc32_init();
 
crc = 0x;   /* preload shift register, per CRC-32 spec */
 
for (p = buf; len  0; ++p, --len)
-   crc = crc32_table[ (crc ^ *p)  0xff] ^ (crc  8);
+   crc = crc32_table[(crc ^ *p)  0xff] ^ (crc  8);
 
return ~crc;/* transmit complement, per CRC-32 spec */
 }
@@ -182,7 +182,7 @@ void rtw_wep_encrypt23a(struct rtw_adapter *padapter,
if ((curfragnum + 1) == pattrib-nr_frags) {
/* the last fragment */
length = pattrib-last_txcmdsz - pattrib-hdrlen -
-   pattrib-iv_len- pattrib-icv_len;
+   pattrib-iv_len - pattrib-icv_len;
 
*((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
 
@@ -262,8 +262,8 @@ static u32 secmicgetuint32(u8 *p)
s32 i;
u32 res = 0;
 
-   for (i = 0; i4; i++) {
-   res |= ((u32)(*p++))  (8*i);
+   for (i = 0; i  4; i++) {
+   res |= ((u32)(*p++))  (8 * i);
}
 
return res;
@@ -274,7 +274,7 @@ static void secmicputuint32(u8 *p, u32 val)
 {
long i;
 
-   for (i = 0; i4; i++) {
+   for (i = 0; i  4; i++) {
*p++ = (u8) (val  0xff);
val = 8;
}
@@ -307,7 +307,7 @@ void rtw_secmicappend23abyte23a(struct mic_data *pmicdata, 
u8 b)
 {
 
/*  Append the byte to our word-sized buffer */
-   pmicdata-M |= ((unsigned long)b)  (8*pmicdata-nBytesInM);
+   pmicdata-M |= ((unsigned long)b)  (8 * pmicdata-nBytesInM);
pmicdata-nBytesInM++;
/*  Process the word if it is full. */
if (pmicdata-nBytesInM = 4) {
@@ -331,7 +331,7 @@ void rtw_secmicappend23a(struct mic_data *pmicdata, u8 
*src, u32 nbytes)
 {
 
/*  This is simple */
-   while(nbytes  0) {
+   while (nbytes  0) {
rtw_secmicappend23abyte23a(pmicdata, *src++);
nbytes--;
}
@@ -348,12 +348,12 @@ void rtw_secgetmic23a(struct mic_data *pmicdata, u8 *dst)
rtw_secmicappend23abyte23a(pmicdata, 0);
rtw_secmicappend23abyte23a(pmicdata, 0);
/*  and then zeroes until the length is a multiple of 4 */
-   while(pmicdata-nBytesInM != 0) {
+   while (pmicdata-nBytesInM != 0) {
rtw_secmicappend23abyte23a(pmicdata, 0);
}
/*  The appendByte function has already computed the result. */
secmicputuint32(dst, pmicdata-L);
-   secmicputuint32(dst+4, pmicdata-R);
+   secmicputuint32(dst + 4, pmicdata-R);
/*  Reset to the empty message. */
secmicclear(pmicdata);
 
@@ -364,10 +364,10 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 {
 
struct mic_data micdata;
-   u8 priority[4]={0x0, 0x0, 0x0, 0x0};
+   u8 priority[4] = {0x0, 0x0, 0x0, 0x0};
 
rtw_secmicsetkey23a(micdata, key);
-   priority[0]= pri;
+   priority[0] = pri;
 
/* Michael MIC pseudo header: DA, SA, 3 x 0, Priority */
if (header[1]1) {   /* ToDS == 1 */
@@ -398,11 +398,11 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define   Lo8(v16)   ((u8)((v16)0x00FF))
 #define   Hi8(v16)   ((u8)(((v16)  8)  0x00FF))
 #define  Lo16(v32)   ((u16)((v32)0x))
-#define  Hi16(v32)   ((u16)(((v32) 16)  0x))
+#define  Hi16(v32)   ((u16)(((v32)  16)  0x))
 #define  Mk16(hi, lo) ((lo) ^ (((u16)(hi))  8))
 
 /* select the Nth 16-bit word of the temporal key unsigned char array TK[]   */
-#define  TK16(N) Mk16(tk[2*(N)+1], tk[2*(N)])
+#define  TK16(N) Mk16(tk[2 * (N) + 1], tk[2 * (N)])
 
 /* S-box lookup: 16 bits -- 16 bits */
 #define _S_(v16) (Sbox1[0][Lo8(v16)] ^ Sbox1[1][Hi8(v16)])
@@ -415,7 +415,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define RC4_KEY_SIZE 16/* 128-bit RC4KEY (104 bits unknown) */
 
 /* 2-unsigned char by 2-unsigned char subset of the full AES S-box table */
-static const unsigned short Sbox1[2][256]=   /* Sbox for hash (can

[PATCH v5 09/15] staging: rtl8723au: that open brace should be on the previous line

2015-03-28 Thread M. Vefa Bicakci
Correct two instances of the checkpatch.pl error indicating that the
opening curly braces should not be on new lines:
ERROR: that open brace { should be on the previous line

Signed-off-by: M. Vefa Bicakci m@runbox.com

---

v3: Make sure that all edited lines are at most 80 characters wide.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 63591ddeb628..2d50777b88fb 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -773,8 +773,10 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 
*((u32 *)crc) = le32_to_cpu(getcrc32(payload, length - 4));
 
-   if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] || 
crc[1] != payload[length - 3] || crc[0] != payload[length - 4])
-   {
+   if (crc[3] != payload[length - 1] ||
+   crc[2] != payload[length - 2] ||
+   crc[1] != payload[length - 3] ||
+   crc[0] != payload[length - 4]) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
 rtw_wep_decrypt23a:icv error crc[3](%x)!= 
payload[length-1](%x) || crc[2](%x)!= payload[length-2](%x) || crc[1](%x)!= 
payload[length-3](%x) || crc[0](%x)!= payload[length-4](%x)\n,
 crc[3], payload[length - 1],
@@ -862,8 +864,7 @@ static void next_key(u8 *key, int round)
 {
u8 rcon;
u8 sbox_key[4];
-   u8 rcon_table[12] =
-   {
+   u8 rcon_table[12] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x1b, 0x36, 0x36, 0x36
};
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 15/15] staging: rtl8723au: Remove unneeded comments

2015-03-28 Thread M. Vefa Bicakci
This commit removes a number of unneeded comments. Two of the
aforementioned comments were most likely meant to aid with version
control, whereas the remaining two comments relate to (now unused)
local variable names.

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 5ef16bb30dc4..af53c92fc3a2 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -679,7 +679,7 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
 pattrib-iv_len =%x, pattrib-icv_len =%x\n,
 pattrib-iv_len,
 pattrib-icv_len);
-   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length)); 
/* modified by Amy */
+   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
 
arcfour_init(mycontext, rc4key, 16);
arcfour_encrypt(mycontext, payload, payload, length);
@@ -691,7 +691,7 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
  pattrib-iv_len -
  pattrib-icv_len);
 
-   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length)); 
/* modified by Amy */
+   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
arcfour_init(mycontext, rc4key, 16);
arcfour_encrypt(mycontext, payload, payload, length);
arcfour_encrypt(mycontext, payload + length, crc, 4);
@@ -1285,7 +1285,7 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
/* Intermediate Buffers */
int curfragnum, length;
u32 prwskeylen;
-   u8 *pframe, *prwskey; /* *payload, *iv */
+   u8 *pframe, *prwskey;
u8 hw_hdr_offset = 0;
struct sta_info *stainfo;
struct pkt_attrib *pattrib = pxmitframe-attrib;
@@ -1574,7 +1574,7 @@ int rtw_aes_decrypt23a(struct rtw_adapter *padapter,
struct security_priv *psecuritypriv = padapter-securitypriv;
struct sk_buff *skb = precvframe-pkt;
int length;
-   u8 *pframe, *prwskey; /* *payload, *iv */
+   u8 *pframe, *prwskey;
int res = _SUCCESS;
 
pframe = skb-data;
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 10/15] staging: rtl8723au: No spaces at the start of a line

2015-03-28 Thread M. Vefa Bicakci
Prior to this commit, a large block of constants used to represent
an AES S-box table were indented with spaces in rtl8723au's
rtw_security.c. Correct the checkpatch.pl warnings indicating that
spaces should not be used to indent lines:
WARNING: please, no spaces at the start of a line

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 140 +-
 1 file changed, 70 insertions(+), 70 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 2d50777b88fb..31ef1bce1e2a 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -414,76 +414,76 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define RC4_KEY_SIZE 16/* 128-bit RC4KEY (104 bits unknown) */
 
 /* 2-unsigned char by 2-unsigned char subset of the full AES S-box table */
-static const unsigned short Sbox1[2][256] =   /* Sbox for hash (can be in 
ROM) */
-{ {
-   0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
-   0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
-   0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B,
-   0x41EC, 0xB367, 0x5FFD, 0x45EA, 0x23BF, 0x53F7, 0xE496, 0x9B5B,
-   0x75C2, 0xE11C, 0x3DAE, 0x4C6A, 0x6C5A, 0x7E41, 0xF502, 0x834F,
-   0x685C, 0x51F4, 0xD134, 0xF908, 0xE293, 0xAB73, 0x6253, 0x2A3F,
-   0x080C, 0x9552, 0x4665, 0x9D5E, 0x3028, 0x37A1, 0x0A0F, 0x2FB5,
-   0x0E09, 0x2436, 0x1B9B, 0xDF3D, 0xCD26, 0x4E69, 0x7FCD, 0xEA9F,
-   0x121B, 0x1D9E, 0x5874, 0x342E, 0x362D, 0xDCB2, 0xB4EE, 0x5BFB,
-   0xA4F6, 0x764D, 0xB761, 0x7DCE, 0x527B, 0xDD3E, 0x5E71, 0x1397,
-   0xA6F5, 0xB968, 0x, 0xC12C, 0x4060, 0xE31F, 0x79C8, 0xB6ED,
-   0xD4BE, 0x8D46, 0x67D9, 0x724B, 0x94DE, 0x98D4, 0xB0E8, 0x854A,
-   0xBB6B, 0xC52A, 0x4FE5, 0xED16, 0x86C5, 0x9AD7, 0x6655, 0x1194,
-   0x8ACF, 0xE910, 0x0406, 0xFE81, 0xA0F0, 0x7844, 0x25BA, 0x4BE3,
-   0xA2F3, 0x5DFE, 0x80C0, 0x058A, 0x3FAD, 0x21BC, 0x7048, 0xF104,
-   0x63DF, 0x77C1, 0xAF75, 0x4263, 0x2030, 0xE51A, 0xFD0E, 0xBF6D,
-   0x814C, 0x1814, 0x2635, 0xC32F, 0xBEE1, 0x35A2, 0x88CC, 0x2E39,
-   0x9357, 0x55F2, 0xFC82, 0x7A47, 0xC8AC, 0xBAE7, 0x322B, 0xE695,
-   0xC0A0, 0x1998, 0x9ED1, 0xA37F, 0x4466, 0x547E, 0x3BAB, 0x0B83,
-   0x8CCA, 0xC729, 0x6BD3, 0x283C, 0xA779, 0xBCE2, 0x161D, 0xAD76,
-   0xDB3B, 0x6456, 0x744E, 0x141E, 0x92DB, 0x0C0A, 0x486C, 0xB8E4,
-   0x9F5D, 0xBD6E, 0x43EF, 0xC4A6, 0x39A8, 0x31A4, 0xD337, 0xF28B,
-   0xD532, 0x8B43, 0x6E59, 0xDAB7, 0x018C, 0xB164, 0x9CD2, 0x49E0,
-   0xD8B4, 0xACFA, 0xF307, 0xCF25, 0xCAAF, 0xF48E, 0x47E9, 0x1018,
-   0x6FD5, 0xF088, 0x4A6F, 0x5C72, 0x3824, 0x57F1, 0x73C7, 0x9751,
-   0xCB23, 0xA17C, 0xE89C, 0x3E21, 0x96DD, 0x61DC, 0x0D86, 0x0F85,
-   0xE090, 0x7C42, 0x71C4, 0xCCAA, 0x90D8, 0x0605, 0xF701, 0x1C12,
-   0xC2A3, 0x6A5F, 0xAEF9, 0x69D0, 0x1791, 0x9958, 0x3A27, 0x27B9,
-   0xD938, 0xEB13, 0x2BB3, 0x2233, 0xD2BB, 0xA970, 0x0789, 0x33A7,
-   0x2DB6, 0x3C22, 0x1592, 0xC920, 0x8749, 0xAAFF, 0x5078, 0xA57A,
-   0x038F, 0x59F8, 0x0980, 0x1A17, 0x65DA, 0xD731, 0x84C6, 0xD0B8,
-   0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A,
-  },
-
-  {  /* second half of table is unsigned char-reversed version of first! */
-   0xA5C6, 0x84F8, 0x99EE, 0x8DF6, 0x0DFF, 0xBDD6, 0xB1DE, 0x5491,
-   0x5060, 0x0302, 0xA9CE, 0x7D56, 0x19E7, 0x62B5, 0xE64D, 0x9AEC,
-   0x458F, 0x9D1F, 0x4089, 0x87FA, 0x15EF, 0xEBB2, 0xC98E, 0x0BFB,
-   0xEC41, 0x67B3, 0xFD5F, 0xEA45, 0xBF23, 0xF753, 0x96E4, 0x5B9B,
-   0xC275, 0x1CE1, 0xAE3D, 0x6A4C, 0x5A6C, 0x417E, 0x02F5, 0x4F83,
-   0x5C68, 0xF451, 0x34D1, 0x08F9, 0x93E2, 0x73AB, 0x5362, 0x3F2A,
-   0x0C08, 0x5295, 0x6546, 0x5E9D, 0x2830, 0xA137, 0x0F0A, 0xB52F,
-   0x090E, 0x3624, 0x9B1B, 0x3DDF, 0x26CD, 0x694E, 0xCD7F, 0x9FEA,
-   0x1B12, 0x9E1D, 0x7458, 0x2E34, 0x2D36, 0xB2DC, 0xEEB4, 0xFB5B,
-   0xF6A4, 0x4D76, 0x61B7, 0xCE7D, 0x7B52, 0x3EDD, 0x715E, 0x9713,
-   0xF5A6, 0x68B9, 0x, 0x2CC1, 0x6040, 0x1FE3, 0xC879, 0xEDB6,
-   0xBED4, 0x468D, 0xD967, 0x4B72, 0xDE94, 0xD498, 0xE8B0, 0x4A85,
-   0x6BBB, 0x2AC5, 0xE54F, 0x16ED, 0xC586, 0xD79A, 0x5566, 0x9411,
-   0xCF8A, 0x10E9, 0x0604, 0x81FE, 0xF0A0, 0x4478, 0xBA25, 0xE34B,
-   0xF3A2, 0xFE5D, 0xC080, 0x8A05, 0xAD3F, 0xBC21, 0x4870, 0x04F1,
-   0xDF63, 0xC177, 0x75AF, 0x6342, 0x3020, 0x1AE5, 0x0EFD, 0x6DBF,
-   0x4C81, 0x1418, 0x3526, 0x2FC3, 0xE1BE, 0xA235, 0xCC88, 0x392E,
-   0x5793, 0xF255, 0x82FC, 0x477A, 0xACC8, 0xE7BA, 0x2B32, 0x95E6,
-   0xA0C0, 0x9819, 0xD19E, 0x7FA3, 0x6644, 0x7E54, 0xAB3B, 0x830B,
-   0xCA8C, 0x29C7, 0xD36B, 0x3C28, 0x79A7, 0xE2BC, 0x1D16, 0x76AD,
-   0x3BDB, 0x5664, 0x4E74, 0x1E14, 0xDB92, 0x0A0C, 0x6C48, 0xE4B8,
-   0x5D9F, 0x6EBD, 0xEF43, 0xA6C4, 0xA839, 0xA431, 0x37D3, 0x8BF2,
-   0x32D5, 0x438B, 0x596E, 0xB7DA, 0x8C01, 0x64B1, 0xD29C, 0xE049,
-   0xB4D8, 0xFAAC, 0x07F3, 0x25CF, 0xAFCA, 0x8EF4, 0xE947, 0x1810,
-   0xD56F, 0x88F0, 0x6F4A

[PATCH v5 13/15] staging: rtl8723au: Rework two byte array comparisons

2015-03-28 Thread M. Vefa Bicakci
Prior to this commit, rtl8723au's rtw_security.c had two instances of
byte array comparisons (for CRC checks) where the individual elements
of the byte arrays were compared one by one and an error trace would
be output if the byte arrays were determined to be different.

This commit improves the readability of the CRC verification by
placing the individual 4 bytes of each byte array into an 32-bit
unsigned integer and comparing the two resulting integers.

Thanks to Larry Finger for spotting the code style issues in the
previous version of this commit, and thanks to Joe Perches for
suggesting the use of 32-bit integer comparisons instead of byte
array comparisons.

Signed-off-by: M. Vefa Bicakci m@runbox.com

---

v2: Correct code style issues and compare 32-bit integers instead of
byte arrays. Update the commit message to better reflect the nature
of the changes.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 34 +++
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index bcb5ea68acbe..0ed048fcb36f 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -210,7 +210,7 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
 struct recv_frame *precvframe)
 {
/*  exclude ICV */
-   u8 crc[4];
+   u32 actual_crc, expected_crc;
struct arc4context mycontext;
int length;
u32 keylength;
@@ -243,16 +243,14 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
arcfour_encrypt(mycontext, payload, payload, length);
 
/* calculate icv and compare the icv */
-   *((u32 *)crc) = le32_to_cpu(getcrc32(payload, length - 4));
+   actual_crc = le32_to_cpu(getcrc32(payload, length - 4));
+   expected_crc = le32_to_cpu(get_unaligned_le32(payload[length - 4]));
 
-   if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
-   crc[1] != payload[length - 3] || crc[0] != payload[length - 4]) {
+   if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-rtw_wep_decrypt23a:icv error crc[3](%x)!= 
payload[length-1](%x) || crc[2](%x)!= payload[length-2](%x) || crc[1](%x)!= 
payload[length-3](%x) || crc[0](%x)!= payload[length-4](%x)\n,
-crc[3], payload[length - 1],
-crc[2], payload[length - 2],
-crc[1], payload[length - 3],
-crc[0], payload[length - 4]);
+rtw_wep_decrypt23a:icv CRC mismatch: 
+actual: %08x, expected: %08x\n,
+actual_crc, expected_crc);
}
 }
 
@@ -714,7 +712,7 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
u32 pnh;
u8 rc4key[16];
u8 ttkey[16];
-   u8 crc[4];
+   u32 actual_crc, expected_crc;
struct arc4context mycontext;
int length;
u32 prwskeylen;
@@ -771,18 +769,14 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
arcfour_init(mycontext, rc4key, 16);
arcfour_encrypt(mycontext, payload, payload, length);
 
-   *((u32 *)crc) = le32_to_cpu(getcrc32(payload, length - 4));
+   actual_crc = le32_to_cpu(getcrc32(payload, length - 4));
+   expected_crc = le32_to_cpu(get_unaligned_le32(payload[length - 4]));
 
-   if (crc[3] != payload[length - 1] ||
-   crc[2] != payload[length - 2] ||
-   crc[1] != payload[length - 3] ||
-   crc[0] != payload[length - 4]) {
+   if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-rtw_wep_decrypt23a:icv error crc[3](%x)!= 
payload[length-1](%x) || crc[2](%x)!= payload[length-2](%x) || crc[1](%x)!= 
payload[length-3](%x) || crc[0](%x)!= payload[length-4](%x)\n,
-crc[3], payload[length - 1],
-crc[2], payload[length - 2],
-crc[1], payload[length - 3],
-crc[0], payload[length - 4]);
+rtw_wep_decrypt23a:icv CRC mismatch: 
+actual: %08x, expected: %08x\n,
+actual_crc, expected_crc);
res = _FAIL;
}
 
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 11/15] staging: rtl8723au: Adjust whitespace in and around comments

2015-03-28 Thread M. Vefa Bicakci
As the subject indicates, adjust whitespace in and around comments
in rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 113 +-
 1 file changed, 57 insertions(+), 56 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 31ef1bce1e2a..8e0e9fa0efdc 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -135,12 +135,12 @@ static u32 getcrc32(u8 *buf, int len)
if (bcrc32initialized == 0)
crc32_init();
 
-   crc = 0x;   /* preload shift register, per CRC-32 spec */
+   crc = 0x; /* preload shift register, per CRC-32 spec */
 
for (p = buf; len  0; ++p, --len)
crc = crc32_table[(crc ^ *p)  0xff] ^ (crc  8);
 
-   return ~crc;/* transmit complement, per CRC-32 spec */
+   return ~crc; /* transmit complement, per CRC-32 spec */
 }
 
 /* Need to consider the fragment  situation */
@@ -152,7 +152,7 @@ void rtw_wep_encrypt23a(struct rtw_adapter *padapter,
struct arc4context mycontext;
int curfragnum, length, index;
u32 keylength;
-   u8 *pframe, *payload, *iv;/* wepkey */
+   u8 *pframe, *payload, *iv; /* wepkey */
u8 wepkey[16];
u8 hw_hdr_offset = 0;
struct pkt_attrib *pattrib = pxmitframe-attrib;
@@ -370,15 +370,15 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
priority[0] = pri;
 
/* Michael MIC pseudo header: DA, SA, 3 x 0, Priority */
-   if (header[1]1) {   /* ToDS == 1 */
-   rtw_secmicappend23a(micdata, header[16], 6);  /* DA */
-   if (header[1]2)  /* From Ds == 1 */
+   if (header[1]1) { /* ToDS == 1 */
+   rtw_secmicappend23a(micdata, header[16], 6); /* DA */
+   if (header[1]2) /* From Ds == 1 */
rtw_secmicappend23a(micdata, header[24], 6);
else
rtw_secmicappend23a(micdata, header[10], 6);
-   } else {/* ToDS == 0 */
-   rtw_secmicappend23a(micdata, header[4], 6);   /* DA */
-   if (header[1]2)  /* From Ds == 1 */
+   } else { /* ToDS == 0 */
+   rtw_secmicappend23a(micdata, header[4], 6); /* DA */
+   if (header[1]2) /* From Ds == 1 */
rtw_secmicappend23a(micdata, header[16], 6);
else
rtw_secmicappend23a(micdata, header[10], 6);
@@ -400,7 +400,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define  Hi16(v32)   ((u16)(((v32)  16)  0x))
 #define  Mk16(hi, lo) ((lo) ^ (((u16)(hi))  8))
 
-/* select the Nth 16-bit word of the temporal key unsigned char array TK[]   */
+/* select the Nth 16-bit word of the temporal key unsigned char array TK[] */
 #define  TK16(N) Mk16(tk[2 * (N) + 1], tk[2 * (N)])
 
 /* S-box lookup: 16 bits -- 16 bits */
@@ -507,7 +507,7 @@ static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, 
u32 iv32)
 {
int  i;
 
-   /* Initialize the 80 bits of P1K[] from IV32 and TA[0..5] */
+   /* Initialize the 80 bits of P1K[] from IV32 and TA[0..5] */
p1k[0]  = Lo16(iv32);
p1k[1]  = Hi16(iv32);
p1k[2]  = Mk16(ta[1], ta[0]); /* use TA[] as little-endian */
@@ -523,7 +523,7 @@ static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, 
u32 iv32)
p1k[2] += _S_(p1k[1] ^ TK16((i  1) + 4));
p1k[3] += _S_(p1k[2] ^ TK16((i  1) + 6));
p1k[4] += _S_(p1k[3] ^ TK16((i  1) + 0));
-   p1k[4] +=  (unsigned short)i;/* avoid 
slide attacks */
+   p1k[4] +=  (unsigned short) i; /* avoid slide attacks */
}
 
 }
@@ -554,41 +554,41 @@ static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, 
u32 iv32)
 static void phase2(u8 *rc4key, const u8 *tk, const u16 *p1k, u16 iv16)
 {
int  i;
-   u16 PPK[6];  /* temporary key for mixing*/
+   u16 PPK[6]; /* temporary key for mixing*/
 
-   /* Note: all adds in the PPK[] equations below are mod 2**16 */
+   /* Note: all adds in the PPK[] equations below are mod 2**16 */
for (i = 0; i  5; i++)
-   PPK[i] = p1k[i];/* first, copy P1K to PPK  */
+   PPK[i] = p1k[i]; /* first, copy P1K to PPK */
 
-   PPK[5] = p1k[4] + iv16; /* next,  add in IV16  */
+   PPK[5] = p1k[4] + iv16; /* next,  add in IV16 */
 
-   /* Bijective non-linear mixing of the 96 bits of PPK[0..5]   */
-   PPK[0] +=_S_(PPK[5] ^ TK16(0));   /* Mix key in each round */
-   PPK[1] +=_S_(PPK[0] ^ TK16(1));
-   PPK[2] +=_S_(PPK[1] ^ TK16(2));
-   PPK[3] +=_S_(PPK[2

[PATCH v5 01/15] staging: rtl8723au: Reformat whitespace to increase readability

2015-03-28 Thread M. Vefa Bicakci
Adjust the whitespace in the signature, local variable declaration and
initialization parts of a number of functions to increase readability
in rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci m@runbox.com

---

v2: Make sure that the arcfour_encrypt function's argument list is split
according to the kernel code style.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 79 +--
 1 file changed, 38 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index ea670afcc212..92882f60bc0e 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -31,11 +31,11 @@ struct arc4context {
 
 static void arcfour_init(struct arc4context *parc4ctx, u8 *key, u32 key_len)
 {
-   u32 t, u;
-   u32 keyindex;
-   u32 stateindex;
+   u32 t, u;
+   u32 keyindex;
+   u32 stateindex;
u8 *state;
-   u32 counter;
+   u32 counter;
 
state = parc4ctx-state;
parc4ctx-x = 0;
@@ -55,7 +55,8 @@ static void arcfour_init(struct arc4context *parc4ctx, u8 
*key, u32 key_len)
}
 
 }
-static u32 arcfour_byte(   struct arc4context  *parc4ctx)
+
+static u32 arcfour_byte(struct arc4context *parc4ctx)
 {
u32 x;
u32 y;
@@ -75,16 +76,13 @@ static u32 arcfour_byte(struct arc4context  
*parc4ctx)
return state[(sx + sy)  0xff];
 }
 
-static void arcfour_encrypt(   struct arc4context  *parc4ctx,
-   u8 *dest,
-   u8 *src,
-   u32 len)
+static void arcfour_encrypt(struct arc4context *parc4ctx, u8 *dest,
+   u8 *src, u32 len)
 {
-   u32 i;
+   u32 i;
 
for (i = 0; i  len; i++)
dest[i] = src[i] ^ (unsigned char)arcfour_byte(parc4ctx);
-
 }
 
 static int bcrc32initialized;
@@ -365,7 +363,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
   u8 *mic_code, u8 pri)
 {
 
-   struct mic_data micdata;
+   struct mic_data micdata;
u8 priority[4]={0x0, 0x0, 0x0, 0x0};
 
rtw_secmicsetkey23a(micdata, key);
@@ -601,21 +599,21 @@ static void phase2(u8 *rc4key, const u8 *tk, const u16 
*p1k, u16 iv16)
 int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
struct xmit_frame *pxmitframe)
 {
-   u16 pnl;
-   u32 pnh;
-   u8  rc4key[16];
-   u8   ttkey[16];
-   u8  crc[4];
-   u8   hw_hdr_offset = 0;
+   u16 pnl;
+   u32 pnh;
+   u8 rc4key[16];
+   u8 ttkey[16];
+   u8 crc[4];
+   u8 hw_hdr_offset = 0;
struct arc4context mycontext;
-   int curfragnum, length;
-   u32 prwskeylen;
-   u8  *pframe, *payload, *iv, *prwskey;
+   int curfragnum, length;
+   u32 prwskeylen;
+   u8 *pframe, *payload, *iv, *prwskey;
union pn48 dot11txpn;
-   struct  sta_info*stainfo;
-   struct  pkt_attrib   *pattrib = pxmitframe-attrib;
-   struct  security_priv   *psecuritypriv = padapter-securitypriv;
-   struct  xmit_priv   *pxmitpriv = padapter-xmitpriv;
+   struct sta_info *stainfo;
+   struct pkt_attrib *pattrib = pxmitframe-attrib;
+   struct security_priv *psecuritypriv = padapter-securitypriv;
+   struct xmit_priv *pxmitpriv = padapter-xmitpriv;
int res = _SUCCESS;
 
if (!pxmitframe-buf_addr)
@@ -708,17 +706,17 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 {
u16 pnl;
u32 pnh;
-   u8   rc4key[16];
-   u8   ttkey[16];
-   u8  crc[4];
+   u8 rc4key[16];
+   u8 ttkey[16];
+   u8 crc[4];
struct arc4context mycontext;
-   int length;
-   u32 prwskeylen;
-   u8  *pframe, *payload, *iv, *prwskey;
+   int length;
+   u32 prwskeylen;
+   u8 *pframe, *payload, *iv, *prwskey;
union pn48 dot11txpn;
-   struct  sta_info*stainfo;
-   struct  rx_pkt_attrib *prxattrib = precvframe-attrib;
-   struct  security_priv *psecuritypriv = padapter-securitypriv;
+   struct sta_info *stainfo;
+   struct rx_pkt_attrib *prxattrib = precvframe-attrib;
+   struct security_priv *psecuritypriv = padapter-securitypriv;
struct sk_buff *skb = precvframe-pkt;
int res = _SUCCESS;
 
@@ -1136,8 +1134,8 @@ static void bitwise_xor(u8 *ina, u8 *inb, u8 *out)
 
 static int aes_cipher(u8 *key, uint hdrlen, u8 *pframe, uint plen)
 {
-   uintqc_exists, a4_exists, i, j, payload_remainder,
-   num_blocks, payload_index;
+   uint qc_exists, a4_exists, i, j, payload_remainder,
+num_blocks, payload_index;
u8 pn_vector[6];
u8 mic_iv[16];
u8 mic_header1[16];
@@ -1353,12 +1351,11 @@ out:
return res;
 }
 
-static int aes_decipher(u8 *key

[PATCH v5 07/15] staging: rtl8723au: Remove unneeded curly braces

2015-03-28 Thread M. Vefa Bicakci
Correct a number of checkpatch.pl warnings in rtl8723au's rtw_security.c
related to the existence of unnecessary curly braces around single
statement blocks:
WARNING: braces {} are not necessary for single statement blocks

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 16 +---
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index b85e5de5f136..e8efdcd06329 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -113,9 +113,8 @@ static void crc32_init(void)
for (i = 0; i  256; ++i) {
k = crc32_reverseBit((u8)i);
 
-   for (c = ((u32)k)  24, j = 8; j  0; --j) {
+   for (c = ((u32)k)  24, j = 8; j  0; --j)
c = c  0x8000 ? (c  1) ^ CRC32_POLY : (c  1);
-   }
 
p1 = (u8 *)crc32_table[i];
 
@@ -264,9 +263,8 @@ static u32 secmicgetuint32(u8 *p)
s32 i;
u32 res = 0;
 
-   for (i = 0; i  4; i++) {
+   for (i = 0; i  4; i++)
res |= ((u32)(*p++))  (8 * i);
-   }
 
return res;
 }
@@ -350,9 +348,8 @@ void rtw_secgetmic23a(struct mic_data *pmicdata, u8 *dst)
rtw_secmicappend23abyte23a(pmicdata, 0);
rtw_secmicappend23abyte23a(pmicdata, 0);
/*  and then zeroes until the length is a multiple of 4 */
-   while (pmicdata-nBytesInM != 0) {
+   while (pmicdata-nBytesInM != 0)
rtw_secmicappend23abyte23a(pmicdata, 0);
-   }
/*  The appendByte function has already computed the result. */
secmicputuint32(dst, pmicdata-L);
secmicputuint32(dst + 4, pmicdata-R);
@@ -888,10 +885,8 @@ static void byte_sub(u8 *in, u8 *out)
 {
int i;
 
-   for (i = 0; i  16; i++) {
+   for (i = 0; i  16; i++)
out[i] = sbox(in[i]);
-   }
-
 }
 
 static void shift_row(u8 *in, u8 *out)
@@ -952,9 +947,8 @@ static void mix_column(u8 *in, u8 *out)
 
for (i = 3; i  0; i--) { /* logical shift left 1 bit */
andf7[i] = andf7[i]  1;
-   if ((andf7[i - 1]  0x80) == 0x80) {
+   if ((andf7[i - 1]  0x80) == 0x80)
andf7[i] = (andf7[i] | 0x01);
-   }
}
andf7[0] = andf7[0]  1;
andf7[0] = andf7[0]  0xfe;
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 03/15] staging: rtl8723au: else should follow close brace

2015-03-28 Thread M. Vefa Bicakci
Correct checkpatch.pl errors in rtl8723au's rtw_security.c indicating
that an else statement should follow the closing brace of the previous
if/else if code block:
ERROR: else should follow close brace '}'

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 572fcf3f936d..9faf78bf23d8 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -376,8 +376,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
rtw_secmicappend23a(micdata, header[24], 6);
else
rtw_secmicappend23a(micdata, header[10], 6);
-   }
-   else{   /* ToDS == 0 */
+   } else {/* ToDS == 0 */
rtw_secmicappend23a(micdata, header[4], 6);   /* DA */
if (header[1]2)  /* From Ds == 1 */
rtw_secmicappend23a(micdata, header[16], 6);
@@ -678,8 +677,7 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
arcfour_encrypt(mycontext, payload, 
payload, length);
arcfour_encrypt(mycontext, payload + 
length, crc, 4);
 
-   }
-   else {
+   } else {
length = (pxmitpriv-frag_len -
  pattrib-hdrlen -
  pattrib-iv_len -
@@ -695,8 +693,7 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
}
}
 
-   }
-   else {
+   } else {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
 rtw_tkip_encrypt23a: stainfo == NULL!!!\n);
DBG_8723A(%s, psta == NUL\n, __func__);
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 12/15] staging: rtl8723au: suspect code indent for conditional statements

2015-03-28 Thread M. Vefa Bicakci
Correct a number of indentation-with-spaces-and-tabs issues in
rtl8723au's rtw_security.c, according to checkpatch.pl:
WARNING: suspect code indent for conditional statements

Signed-off-by: M. Vefa Bicakci m@runbox.com

---

v3: Make sure that all edited lines are at most 80 characters wide.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 34 +--
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 8e0e9fa0efdc..bcb5ea68acbe 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -929,9 +929,9 @@ static void mix_column(u8 *in, u8 *out)
 
for (i = 0; i  4; i++) {
if ((in[i]  0x80) == 0x80)
-   add1b[i] = 0x1b;
+   add1b[i] = 0x1b;
else
-   add1b[i] = 0x00;
+   add1b[i] = 0x00;
}
 
swap_halfs[0] = in[2]; /* Swap halfs */
@@ -986,21 +986,21 @@ static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext)
 
for (round = 0; round  11; round++) {
if (round == 0) {
-   xor_128(round_key, data, ciphertext);
-   next_key(round_key, round);
+   xor_128(round_key, data, ciphertext);
+   next_key(round_key, round);
} else if (round == 10) {
-   byte_sub(ciphertext, intermediatea);
-   shift_row(intermediatea, intermediateb);
-   xor_128(intermediateb, round_key, ciphertext);
+   byte_sub(ciphertext, intermediatea);
+   shift_row(intermediatea, intermediateb);
+   xor_128(intermediateb, round_key, ciphertext);
} else { /* 1 - 9 */
-   byte_sub(ciphertext, intermediatea);
-   shift_row(intermediatea, intermediateb);
-   mix_column(intermediateb[0], intermediatea[0]);
-   mix_column(intermediateb[4], intermediatea[4]);
-   mix_column(intermediateb[8], intermediatea[8]);
-   mix_column(intermediateb[12], intermediatea[12]);
-   xor_128(intermediatea, round_key, ciphertext);
-   next_key(round_key, round);
+   byte_sub(ciphertext, intermediatea);
+   shift_row(intermediatea, intermediateb);
+   mix_column(intermediateb[0], intermediatea[0]);
+   mix_column(intermediateb[4], intermediatea[4]);
+   mix_column(intermediateb[8], intermediatea[8]);
+   mix_column(intermediateb[12], intermediatea[12]);
+   xor_128(intermediatea, round_key, ciphertext);
+   next_key(round_key, round);
}
}
 
@@ -1501,7 +1501,7 @@ static int aes_decipher(u8 *key, uint hdrlen, u8 *pframe, 
uint plen)
for (j = 0; j  16; j++)
padded_buffer[j] = 0x00;
for (j = 0; j  payload_remainder; j++)
-   padded_buffer[j] = message[payload_index++];
+   padded_buffer[j] = message[payload_index++];
bitwise_xor(aes_out, padded_buffer, chain_buffer);
aes128k128d(key, chain_buffer, aes_out);
}
@@ -1531,7 +1531,7 @@ static int aes_decipher(u8 *key, uint hdrlen, u8 *pframe, 
uint plen)
  message, pn_vector, num_blocks + 1);
 
for (j = 0; j  16; j++)
-padded_buffer[j] = 0x00;
+   padded_buffer[j] = 0x00;
for (j = 0; j  payload_remainder; j++)
padded_buffer[j] = message[payload_index + j];
aes128k128d(key, ctr_preload, aes_out);
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 04/15] staging: rtl8723au: Fix the indentation of two lines

2015-03-28 Thread M. Vefa Bicakci
Correct the indentation of two lines in rtw_tkip_encrypt23a function in
rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 9faf78bf23d8..3e79b66d0897 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -688,8 +688,8 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
arcfour_encrypt(mycontext, payload, 
payload, length);
arcfour_encrypt(mycontext, payload + 
length, crc, 4);
 
-   pframe += pxmitpriv-frag_len;
-   pframe  = PTR_ALIGN(pframe, 4);
+   pframe += pxmitpriv-frag_len;
+   pframe  = PTR_ALIGN(pframe, 4);
}
}
 
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 08/15] staging: rtl8723au: trailing statements should be on next line

2015-03-28 Thread M. Vefa Bicakci
Correct a number of checkpatch.pl errors in rtl8723au's rtw_security.c
related to trailing statements:
ERROR: trailing statements should be on next line

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index e8efdcd06329..63591ddeb628 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -132,7 +132,8 @@ static u32 getcrc32(u8 *buf, int len)
u8 *p;
u32 crc;
 
-   if (bcrc32initialized == 0) crc32_init();
+   if (bcrc32initialized == 0)
+   crc32_init();
 
crc = 0x;   /* preload shift register, per CRC-32 spec */
 
@@ -556,8 +557,10 @@ static void phase2(u8 *rc4key, const u8 *tk, const u16 
*p1k, u16 iv16)
u16 PPK[6];  /* temporary key for mixing*/
 
/* Note: all adds in the PPK[] equations below are mod 2**16 */
-   for (i = 0; i  5; i++) PPK[i] = p1k[i];/* first, copy P1K to PPK   
   */
-   PPK[5] = p1k[4] + iv16; /* next,  add in IV16   
   */
+   for (i = 0; i  5; i++)
+   PPK[i] = p1k[i];/* first, copy P1K to PPK  */
+
+   PPK[5] = p1k[4] + iv16; /* next,  add in IV16  */
 
/* Bijective non-linear mixing of the 96 bits of PPK[0..5]   */
PPK[0] +=_S_(PPK[5] ^ TK16(0));   /* Mix key in each round */
@@ -977,7 +980,8 @@ static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext)
u8 intermediateb[16];
u8 round_key[16];
 
-   for (i = 0; i  16; i++) round_key[i] = key[i];
+   for (i = 0; i  16; i++)
+   round_key[i] = key[i];
 
for (round = 0; round  11; round++) {
if (round == 0) {
@@ -1061,7 +1065,8 @@ static void construct_mic_header2(u8 *mic_header2, u8 
*mpdu, int a4_exists,
 {
int i;
 
-   for (i = 0; i  16; i++) mic_header2[i] = 0x00;
+   for (i = 0; i  16; i++)
+   mic_header2[i] = 0x00;
 
mic_header2[0] = mpdu[16];/* A3 */
mic_header2[1] = mpdu[17];
@@ -1074,7 +1079,8 @@ static void construct_mic_header2(u8 *mic_header2, u8 
*mpdu, int a4_exists,
mic_header2[7] = 0x00; /* mpdu[23]; */
 
if (!qc_exists  a4_exists) {
-   for (i = 0; i  6; i++) mic_header2[8+i] = mpdu[24+i];   /* A4 
*/
+   for (i = 0; i  6; i++)
+   mic_header2[8+i] = mpdu[24+i];   /* A4 */
}
 
if (qc_exists  !a4_exists) {
@@ -1083,7 +1089,8 @@ static void construct_mic_header2(u8 *mic_header2, u8 
*mpdu, int a4_exists,
}
 
if (qc_exists  a4_exists) {
-   for (i = 0; i  6; i++) mic_header2[8+i] = mpdu[24+i];   /* A4 
*/
+   for (i = 0; i  6; i++)
+   mic_header2[8+i] = mpdu[24+i];   /* A4 */
 
mic_header2[14] = mpdu[30]  0x0f;
mic_header2[15] = mpdu[31]  0x00;
@@ -1101,7 +1108,9 @@ static void construct_ctr_preload(u8 *ctr_preload, int 
a4_exists, int qc_exists,
 {
int i = 0;
 
-   for (i = 0; i  16; i++) ctr_preload[i] = 0x00;
+   for (i = 0; i  16; i++)
+   ctr_preload[i] = 0x00;
+
i = 0;
 
ctr_preload[0] = 0x01;  /* flag */
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 14/15] staging: rtl8723au: Use __func__ in trace logs

2015-03-28 Thread M. Vefa Bicakci
Rework the trace log-related lines in rtl8723au's rtw_security.c
to use the __func__ GCC magic variable instead of hardcoding the
function names into the trace log strings. This also corrects a
copy-paste-related typo in the function named rtw_tkip_decrypt23a.

Thanks to Jes Sorensen for the suggestion to use __func__.

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 41 ++-
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 0ed048fcb36f..5ef16bb30dc4 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -248,9 +248,9 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
 
if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-rtw_wep_decrypt23a:icv CRC mismatch: 
+%s:icv CRC mismatch: 
 actual: %08x, expected: %08x\n,
-actual_crc, expected_crc);
+__func__, actual_crc, expected_crc);
}
 }
 
@@ -635,13 +635,13 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
 
if (stainfo == NULL) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-rtw_tkip_encrypt23a: stainfo == NULL!!!\n);
+%s: stainfo == NULL!!!\n, __func__);
DBG_8723A(%s, psta == NUL\n, __func__);
return _FAIL;
}
 
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-rtw_tkip_encrypt23a: stainfo!= NULL!!!\n);
+%s: stainfo!= NULL!!!\n, __func__);
 
if (!(stainfo-state  _FW_LINKED)) {
DBG_8723A(%s, psta-state(0x%x) != _FW_LINKED\n, __func__, 
stainfo-state);
@@ -733,7 +733,7 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 prxattrib-ta[0]);
if (stainfo == NULL) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-rtw_tkip_decrypt23a: stainfo == NULL!!!\n);
+%s: stainfo == NULL!!!\n, __func__);
return _FAIL;
}
 
@@ -748,7 +748,7 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
prwskeylen = 16;
} else {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-rtw_tkip_decrypt23a: stainfo!= NULL!!!\n);
+%s: stainfo!= NULL!!!\n, __func__);
prwskey = stainfo-dot118021x_UncstKey.skey[0];
prwskeylen = 16;
}
@@ -774,9 +774,9 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 
if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-rtw_wep_decrypt23a:icv CRC mismatch: 
+%s:icv CRC mismatch: 
 actual: %08x, expected: %08x\n,
-actual_crc, expected_crc);
+__func__, actual_crc, expected_crc);
res = _FAIL;
}
 
@@ -1313,7 +1313,7 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
 
if (!stainfo) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-rtw_aes_encrypt23a: stainfo == NULL!!!\n);
+%s: stainfo == NULL!!!\n, __func__);
DBG_8723A(%s, psta == NUL\n, __func__);
res = _FAIL;
goto out;
@@ -1324,7 +1324,7 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
return _FAIL;
}
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-rtw_aes_encrypt23a: stainfo!= NULL!!!\n);
+%s: stainfo!= NULL!!!\n, __func__);
 
if (is_multicast_ether_addr(pattrib-ra))
prwskey = 
psecuritypriv-dot118021XGrpKey[psecuritypriv-dot118021XGrpKeyid].skey;
@@ -1552,11 +1552,14 @@ static int aes_decipher(u8 *key, uint hdrlen, u8 
*pframe, uint plen)
for (i = 0; i  8; i++) {
if (pframe[hdrlen + 8 + plen - 8 + i] != message[hdrlen + 8 + 
plen - 8 + i]) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-aes_decipher:mic check error mic[%d]: 
pframe(%x) != message(%x)\n,
-i, pframe[hdrlen + 8 + plen - 8 + i],
+%s:mic check error mic[%d]: pframe(%x) != 
message(%x)\n,
+__func__, i,
+pframe[hdrlen + 8 + plen - 8 + i],
 message[hdrlen + 8 + plen - 8 + i]);
-   DBG_8723A(aes_decipher:mic check error mic[%d]: 
pframe(%x) != message(%x)\n,
- i

[PATCH v5 00/15] checkpatch clean-up of rtl8723au's rtw_security.c

2015-03-28 Thread M. Vefa Bicakci
These commits address a number of checkpatch.pl warnings and errors
in rtl8723au's rtw_security.c.

Prior to this set of commits, checkpatch.pl reported the following:
total: 75 errors, 124 warnings, 1631 lines checked

After applying this set of commits, checkpatch.pl reports the following:
total: 0 errors, 22 warnings, 1635 lines checked
where the only remaining warnings relate to lines longer than 80
characters and quoted strings split across multiple lines.

There are also a number of commits which improve the code in other ways.
For example, the commit titled Reorganize a few functions to remove
indentation reworks two functions to make them more readable, whereas
the commit titled Rework two byte array comparisons reworks two CRC
verifications for the same reason, and Use __func__ in trace logs
avoids hardcoding function names in trace logs to increase
maintainability.

All of the commits have been verified to compile successfully via the
use of the interactive rebase feature of git.

v5: Rebased onto Greg Kroah-Hartman's staging-testing tree, on top of
the following commit
  commit f8da055aafec0483c12132554504ec683868c655
  staging: sm750fb: Change foo * bar style to foo *bar

Please see the individual commit messages for the specific changes
since v5 aside from the rebase.

v4: Rebased onto Greg Kroah-Hartman's staging-next tree, on top of
the following commit
  commit 153fe946412b5da1a8808f79d4f7f4ebfa7586b0
  staging: fbtft: Do not use binary constants

In addition, fix-up the commit messages to move the patch revision
notes below the newly added --- markers where needed.

v3: Rebased onto Greg Kroah-Hartman's staging-next tree, on top of
the following commit
  5ec293650827122df300581c17ca1d5de03bac3d.
  Staging: dgnc: release the lock before testing for nullity

Please see the individual commit messages for the changes
since v2. In summary, the following commits have been updated:
- that open brace should be on the previous line
- suspect code indent for conditional statements

The following commit is new:
- Use __func__ in trace logs

Finally, the following commit has been removed:
- Do not initialize a static to 0

v2: Please see the individual commit messages for the changes
since v1. In summary, the following commits have been updated:
- Reformat whitespace to increase readability
- Fix before/around/after whitespace issues
- Rework two byte array comparisons

M. Vefa Bicakci (15):
  staging: rtl8723au: Reformat whitespace to increase readability
  staging: rtl8723au: Fix before/around/after whitespace issues
  staging: rtl8723au: else should follow close brace
  staging: rtl8723au: Fix the indentation of two lines
  staging: rtl8723au: Reorganize a few functions to remove indentation
  staging: rtl8723au: else is not generally useful after a return
  staging: rtl8723au: Remove unneeded curly braces
  staging: rtl8723au: trailing statements should be on next line
  staging: rtl8723au: that open brace should be on the previous line
  staging: rtl8723au: No spaces at the start of a line
  staging: rtl8723au: Adjust whitespace in and around comments
  staging: rtl8723au: suspect code indent for conditional statements
  staging: rtl8723au: Rework two byte array comparisons
  staging: rtl8723au: Use __func__ in trace logs
  staging: rtl8723au: Remove unneeded comments

 drivers/staging/rtl8723au/core/rtw_security.c | 832 +-
 1 file changed, 418 insertions(+), 414 deletions(-)

-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 05/15] staging: rtl8723au: Reorganize a few functions to remove indentation

2015-03-28 Thread M. Vefa Bicakci
Prior to this commit, functions rtw_tkip_encrypt23a and rtw_tkip_decrypt23a had
large if blocks which contained the majority of the logic in the functions.

Rework these functions so that if the negated version of the aforementioned if
blocks' conditions are true, we return from the function with _FAIL, as
expected by the calling code.

This lets us remove two levels of indentation from the functions in
question, making them more readable.

Signed-off-by: M. Vefa Bicakci m@runbox.com

---

v5: Move the start to encrypt each fragment and start to decrypt
recvframe comments in the refactored functions to more sensible
positions.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 215 +-
 1 file changed, 107 insertions(+), 108 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 3e79b66d0897..df7261c045fe 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -615,91 +615,90 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
struct xmit_priv *pxmitpriv = padapter-xmitpriv;
int res = _SUCCESS;
 
+   if (pattrib-encrypt != WLAN_CIPHER_SUITE_TKIP)
+   return _FAIL;
+
if (!pxmitframe-buf_addr)
return _FAIL;
 
hw_hdr_offset = TXDESC_OFFSET;
 
pframe = pxmitframe-buf_addr + hw_hdr_offset;
-   /* 4 start to encrypt each fragment */
-   if (pattrib-encrypt == WLAN_CIPHER_SUITE_TKIP) {
-   if (pattrib-psta)
-   stainfo = pattrib-psta;
-   else {
-   DBG_8723A(%s, call rtw_get_stainfo()\n, __func__);
-   stainfo = rtw_get_stainfo23a(padapter-stapriv,
-pattrib-ra[0]);
-   }
 
-   if (stainfo != NULL) {
+   if (pattrib-psta)
+   stainfo = pattrib-psta;
+   else {
+   DBG_8723A(%s, call rtw_get_stainfo()\n, __func__);
+   stainfo = rtw_get_stainfo23a(padapter-stapriv,
+pattrib-ra[0]);
+   }
 
-   if (!(stainfo-state  _FW_LINKED)) {
-   DBG_8723A(%s, psta-state(0x%x) != 
_FW_LINKED\n, __func__, stainfo-state);
-   return _FAIL;
-   }
+   if (stainfo == NULL) {
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
+rtw_tkip_encrypt23a: stainfo == NULL!!!\n);
+   DBG_8723A(%s, psta == NUL\n, __func__);
+   return _FAIL;
+   }
 
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-rtw_tkip_encrypt23a: stainfo!= NULL!!!\n);
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
+rtw_tkip_encrypt23a: stainfo!= NULL!!!\n);
 
-   if (is_multicast_ether_addr(pattrib-ra))
-   prwskey = 
psecuritypriv-dot118021XGrpKey[psecuritypriv-dot118021XGrpKeyid].skey;
-   else
-   prwskey = stainfo-dot118021x_UncstKey.skey[0];
+   if (!(stainfo-state  _FW_LINKED)) {
+   DBG_8723A(%s, psta-state(0x%x) != _FW_LINKED\n, __func__, 
stainfo-state);
+   return _FAIL;
+   }
 
-   prwskeylen = 16;
+   if (is_multicast_ether_addr(pattrib-ra))
+   prwskey = 
psecuritypriv-dot118021XGrpKey[psecuritypriv-dot118021XGrpKeyid].skey;
+   else
+   prwskey = stainfo-dot118021x_UncstKey.skey[0];
 
-   for (curfragnum = 0; curfragnum  pattrib-nr_frags; 
curfragnum++) {
-   iv = pframe + pattrib-hdrlen;
-   payload = pframe + pattrib-iv_len + 
pattrib-hdrlen;
+   prwskeylen = 16;
 
-   GET_TKIP_PN(iv, dot11txpn);
+   /* 4 start to encrypt each fragment */
+   for (curfragnum = 0; curfragnum  pattrib-nr_frags; curfragnum++) {
+   iv = pframe + pattrib-hdrlen;
+   payload = pframe + pattrib-iv_len + pattrib-hdrlen;
 
-   pnl = (u16)(dot11txpn.val);
-   pnh = (u32)(dot11txpn.val16);
+   GET_TKIP_PN(iv, dot11txpn);
 
-   phase1((u16 *)ttkey[0], prwskey, 
pattrib-ta[0], pnh);
+   pnl = (u16)(dot11txpn.val);
+   pnh = (u32)(dot11txpn.val16);
 
-   phase2(rc4key[0], prwskey, (u16 *)ttkey[0], 
pnl);
+   phase1((u16 *)ttkey[0], prwskey, pattrib-ta[0], pnh);
 
-   if ((curfragnum + 1) == pattrib-nr_frags) {
/* 4 the last fragment */
-   length = (pattrib-last_txcmdsz

[PATCH v5 06/15] staging: rtl8723au: else is not generally useful after a return

2015-03-28 Thread M. Vefa Bicakci
Correct a checkpatch.pl warning regarding rtl8723au's
rtw_security.c::crc32_init pointing out that having an else statement
after a break or a return is not useful.

drivers/staging/rtl8723au/core/rtw_security.c:105:
WARNING: else is not generally useful after a break or return

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 42 ++-
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index df7261c045fe..b85e5de5f136 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -99,31 +99,33 @@ static u8 crc32_reverseBit(u8 data)
 
 static void crc32_init(void)
 {
+   int i, j;
+   u32 c;
+   u8 *p, *p1;
+   u8 k;
 
if (bcrc32initialized == 1)
return;
-   else{
-   int i, j;
-   u32 c;
-   u8 *p = (u8 *)c, *p1;
-   u8 k;
-
-   c = 0x1234;
-
-   for (i = 0; i  256; ++i) {
-   k = crc32_reverseBit((u8)i);
-   for (c = ((u32)k)  24, j = 8; j  0; --j) {
-   c = c  0x8000 ? (c  1) ^ CRC32_POLY : (c 
 1);
-   }
-   p1 = (u8 *)crc32_table[i];
-
-   p1[0] = crc32_reverseBit(p[3]);
-   p1[1] = crc32_reverseBit(p[2]);
-   p1[2] = crc32_reverseBit(p[1]);
-   p1[3] = crc32_reverseBit(p[0]);
+
+   p = (u8 *) c;
+   c = 0x1234;
+
+   for (i = 0; i  256; ++i) {
+   k = crc32_reverseBit((u8)i);
+
+   for (c = ((u32)k)  24, j = 8; j  0; --j) {
+   c = c  0x8000 ? (c  1) ^ CRC32_POLY : (c  1);
}
-   bcrc32initialized = 1;
+
+   p1 = (u8 *)crc32_table[i];
+
+   p1[0] = crc32_reverseBit(p[3]);
+   p1[1] = crc32_reverseBit(p[2]);
+   p1[2] = crc32_reverseBit(p[1]);
+   p1[3] = crc32_reverseBit(p[0]);
}
+
+   bcrc32initialized = 1;
 }
 
 static u32 getcrc32(u8 *buf, int len)
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 00/15] checkpatch clean-up of rtl8723au's rtw_security.c

2015-03-28 Thread M. Vefa Bicakci
On Sat, March 28, 2015 12:52:54 Joe Perches wrote:
 On Sat, 2015-03-28 at 08:52 -0400, M. Vefa Bicakci wrote:
  These commits address a number of checkpatch.pl warnings and errors
  in rtl8723au's rtw_security.c.
 
 Hello.
 
 This is one of those patchsets that should be
 done against Greg's staging-testing branch.
 
 There are some commits against rtl8723au in that
 branch that will conflict with your patches.

Hello Joe,

Thank you for letting me know. Given the discussion arising from the 3rd 
version of the patches, I should have used (or at least checked) the 
staging-testing branch.

I rebased the commits against the staging-testing branch and corrected 
the merge conflicts. I hope to send the 5th version of the patches out 
for review soon.

Vefa

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 11/15] staging: rtl8723au: Adjust whitespace in and around comments

2015-03-28 Thread M. Vefa Bicakci
As the subject indicates, adjust whitespace in and around comments
in rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 114 +-
 1 file changed, 57 insertions(+), 57 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index f8d0c0a63f..8591b49664 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -135,12 +135,12 @@ static u32 getcrc32(u8 *buf, int len)
if (bcrc32initialized == 0)
crc32_init();
 
-   crc = 0x;   /* preload shift register, per CRC-32 spec */
+   crc = 0x; /* preload shift register, per CRC-32 spec */
 
for (p = buf; len  0; ++p, --len)
crc = crc32_table[(crc ^ *p)  0xff] ^ (crc  8);
 
-   return ~crc;/* transmit complement, per CRC-32 spec */
+   return ~crc; /* transmit complement, per CRC-32 spec */
 }
 
 /* Need to consider the fragment  situation */
@@ -152,7 +152,7 @@ void rtw_wep_encrypt23a(struct rtw_adapter *padapter,
struct arc4context mycontext;
int curfragnum, length, index;
u32 keylength;
-   u8 *pframe, *payload, *iv;/* wepkey */
+   u8 *pframe, *payload, *iv; /* wepkey */
u8 wepkey[16];
u8 hw_hdr_offset = 0;
struct pkt_attrib *pattrib = pxmitframe-attrib;
@@ -373,15 +373,15 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
priority[0] = pri;
 
/* Michael MIC pseudo header: DA, SA, 3 x 0, Priority */
-   if (header[1]1) {   /* ToDS == 1 */
-   rtw_secmicappend23a(micdata, header[16], 6);  /* DA */
-   if (header[1]2)  /* From Ds == 1 */
+   if (header[1]1) { /* ToDS == 1 */
+   rtw_secmicappend23a(micdata, header[16], 6); /* DA */
+   if (header[1]2) /* From Ds == 1 */
rtw_secmicappend23a(micdata, header[24], 6);
else
rtw_secmicappend23a(micdata, header[10], 6);
-   } else {/* ToDS == 0 */
-   rtw_secmicappend23a(micdata, header[4], 6);   /* DA */
-   if (header[1]2)  /* From Ds == 1 */
+   } else { /* ToDS == 0 */
+   rtw_secmicappend23a(micdata, header[4], 6); /* DA */
+   if (header[1]2) /* From Ds == 1 */
rtw_secmicappend23a(micdata, header[16], 6);
else
rtw_secmicappend23a(micdata, header[10], 6);
@@ -403,7 +403,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define  Hi16(v32)   ((u16)(((v32)  16)  0x))
 #define  Mk16(hi, lo) ((lo) ^ (((u16)(hi))  8))
 
-/* select the Nth 16-bit word of the temporal key unsigned char array TK[]   */
+/* select the Nth 16-bit word of the temporal key unsigned char array TK[] */
 #define  TK16(N) Mk16(tk[2*(N)+1], tk[2*(N)])
 
 /* S-box lookup: 16 bits -- 16 bits */
@@ -510,7 +510,7 @@ static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, 
u32 iv32)
 {
int  i;
 
-   /* Initialize the 80 bits of P1K[] from IV32 and TA[0..5] */
+   /* Initialize the 80 bits of P1K[] from IV32 and TA[0..5] */
p1k[0]  = Lo16(iv32);
p1k[1]  = Hi16(iv32);
p1k[2]  = Mk16(ta[1], ta[0]); /* use TA[] as little-endian */
@@ -526,7 +526,7 @@ static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, 
u32 iv32)
p1k[2] += _S_(p1k[1] ^ TK16((i  1) + 4));
p1k[3] += _S_(p1k[2] ^ TK16((i  1) + 6));
p1k[4] += _S_(p1k[3] ^ TK16((i  1) + 0));
-   p1k[4] +=  (unsigned short)i;/* avoid 
slide attacks */
+   p1k[4] +=  (unsigned short) i; /* avoid slide attacks */
}
 
 }
@@ -557,41 +557,41 @@ static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, 
u32 iv32)
 static void phase2(u8 *rc4key, const u8 *tk, const u16 *p1k, u16 iv16)
 {
int  i;
-   u16 PPK[6];  /* temporary key for mixing*/
+   u16 PPK[6]; /* temporary key for mixing*/
 
-   /* Note: all adds in the PPK[] equations below are mod 2**16 */
+   /* Note: all adds in the PPK[] equations below are mod 2**16 */
for (i = 0; i  5; i++)
-   PPK[i] = p1k[i];/* first, copy P1K to PPK  */
+   PPK[i] = p1k[i]; /* first, copy P1K to PPK */
 
-   PPK[5] = p1k[4] + iv16; /* next,  add in IV16  */
+   PPK[5] = p1k[4] + iv16; /* next,  add in IV16 */
 
-   /* Bijective non-linear mixing of the 96 bits of PPK[0..5]   */
-   PPK[0] +=_S_(PPK[5] ^ TK16(0));   /* Mix key in each round */
-   PPK[1] +=_S_(PPK[0] ^ TK16(1));
-   PPK[2] +=_S_(PPK[1] ^ TK16(2));
-   PPK[3] +=_S_(PPK[2] ^ TK16(3

[PATCH v4 04/15] staging: rtl8723au: Fix the indentation of two lines

2015-03-28 Thread M. Vefa Bicakci
Correct the indentation of two lines in rtw_tkip_encrypt23a function in
rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 17234e0bf1..df1787f20e 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -679,8 +679,8 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
arcfour_encrypt(mycontext, payload, 
payload, length);
arcfour_encrypt(mycontext, 
payload+length, crc, 4);
 
-   pframe += pxmitpriv-frag_len;
-   pframe  = PTR_ALIGN(pframe, 4);
+   pframe += pxmitpriv-frag_len;
+   pframe  = PTR_ALIGN(pframe, 4);
}
}
 
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 14/15] staging: rtl8723au: Use __func__ in trace logs

2015-03-28 Thread M. Vefa Bicakci
Rework the trace log-related lines in rtl8723au's rtw_security.c
to use the __func__ GCC magic variable instead of hardcoding the
function names into the trace log strings. This also corrects a
copy-paste-related typo in the function named rtw_tkip_decrypt23a.

Thanks to Jes Sorensen for the suggestion to use __func__.

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 49 ---
 1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index eb3544866a..cdb3707fb2 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -248,9 +248,9 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
 
if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-(rtw_wep_decrypt23a:icv CRC mismatch: 
+(%s:icv CRC mismatch: 
  actual: %08x, expected: %08x\n,
- actual_crc, expected_crc));
+ __func__, actual_crc, expected_crc));
}
 }
 
@@ -634,7 +634,8 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
}
 
if (stainfo == NULL) {
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
(rtw_tkip_encrypt23a: stainfo == NULL!!!\n));
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
+(%s: stainfo == NULL!!!\n, __func__));
DBG_8723A(%s, psta == NUL\n, __func__);
return _FAIL;
}
@@ -644,7 +645,8 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
return _FAIL;
}
 
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, (rtw_tkip_encrypt23a: 
stainfo!= NULL!!!\n));
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
+(%s: stainfo!= NULL!!!\n, __func__));
 
if (is_multicast_ether_addr(pattrib-ra))
prwskey = 
psecuritypriv-dot118021XGrpKey[psecuritypriv-dot118021XGrpKeyid].skey;
@@ -718,7 +720,8 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
stainfo = rtw_get_stainfo23a(padapter-stapriv,
 prxattrib-ta[0]);
if (stainfo == NULL) {
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
(rtw_tkip_decrypt23a: stainfo == NULL!!!\n));
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
+(%s: stainfo == NULL!!!\n, __func__));
return _FAIL;
}
 
@@ -731,7 +734,8 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
prwskey = 
psecuritypriv-dot118021XGrpKey[prxattrib-key_index].skey;
prwskeylen = 16;
} else {
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
(rtw_tkip_decrypt23a: stainfo!= NULL!!!\n));
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
+(%s: stainfo!= NULL!!!\n, __func__));
prwskey = stainfo-dot118021x_UncstKey.skey[0];
prwskeylen = 16;
}
@@ -757,9 +761,9 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 
if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-(rtw_wep_decrypt23a:icv CRC mismatch: 
+(%s:icv CRC mismatch: 
  actual: %08x, expected: %08x\n,
- actual_crc, expected_crc));
+ __func__, actual_crc, expected_crc));
res = _FAIL;
}
 
@@ -1296,7 +1300,7 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
 
if (!stainfo) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-(rtw_aes_encrypt23a: stainfo == NULL!!!\n));
+(%s: stainfo == NULL!!!\n, __func__));
DBG_8723A(%s, psta == NUL\n, __func__);
res = _FAIL;
goto out;
@@ -1307,7 +1311,7 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
return _FAIL;
}
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-(rtw_aes_encrypt23a: stainfo!= NULL!!!\n));
+(%s: stainfo!= NULL!!!\n, __func__));
 
if (is_multicast_ether_addr(pattrib-ra))
prwskey = 
psecuritypriv-dot118021XGrpKey[psecuritypriv-dot118021XGrpKeyid].skey;
@@ -1535,10 +1539,16 @@ static int aes_decipher(u8 *key, uint hdrlen, u8 
*pframe, uint plen)
for (i = 0; i  8; i++) {
if (pframe[hdrlen + 8 + plen - 8 + i] != message[hdrlen + 8 + 
plen - 8 + i]) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-(aes_decipher:mic check error mic[%d]: 
pframe(%x) != message(%x)\n

[PATCH v4 15/15] staging: rtl8723au: Remove unneeded comments

2015-03-28 Thread M. Vefa Bicakci
This commit removes a number of unneeded comments. Two of the
aforementioned comments were most likely meant to aid with version
control, whereas the remaining two comments relate to (now unused)
local variable names.

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index cdb3707fb2..309f3d969e 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -671,14 +671,14 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
if ((curfragnum+1) == pattrib-nr_frags) { /* 4 the last 
fragment */
length = 
pattrib-last_txcmdsz-pattrib-hdrlen-pattrib-iv_len - pattrib-icv_len;
RT_TRACE(_module_rtl871x_security_c_, _drv_info_, 
(pattrib-iv_len =%x, pattrib-icv_len =%x\n, pattrib-iv_len, 
pattrib-icv_len));
-   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length)); 
/* modified by Amy */
+   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
 
arcfour_init(mycontext, rc4key, 16);
arcfour_encrypt(mycontext, payload, payload, length);
arcfour_encrypt(mycontext, payload+length, crc, 4);
} else {
length = 
pxmitpriv-frag_len-pattrib-hdrlen-pattrib-iv_len-pattrib-icv_len;
-   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length)); 
/* modified by Amy */
+   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
arcfour_init(mycontext, rc4key, 16);
arcfour_encrypt(mycontext, payload, payload, length);
arcfour_encrypt(mycontext, payload+length, crc, 4);
@@ -1272,7 +1272,7 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
/* Intermediate Buffers */
int curfragnum, length;
u32 prwskeylen;
-   u8 *pframe, *prwskey; /* *payload, *iv */
+   u8 *pframe, *prwskey;
u8 hw_hdr_offset = 0;
struct sta_info *stainfo;
struct pkt_attrib *pattrib = pxmitframe-attrib;
@@ -1563,7 +1563,7 @@ int rtw_aes_decrypt23a(struct rtw_adapter *padapter,
struct security_priv *psecuritypriv = padapter-securitypriv;
struct sk_buff *skb = precvframe-pkt;
int length;
-   u8 *pframe, *prwskey; /* *payload, *iv */
+   u8 *pframe, *prwskey;
int res = _SUCCESS;
 
pframe = skb-data;
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 10/15] staging: rtl8723au: No spaces at the start of a line

2015-03-28 Thread M. Vefa Bicakci
Prior to this commit, a large block of constants used to represent
an AES S-box table were indented with spaces in rtl8723au's
rtw_security.c. Correct the checkpatch.pl warnings indicating that
spaces should not be used to indent lines:
WARNING: please, no spaces at the start of a line

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 140 +-
 1 file changed, 70 insertions(+), 70 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 0557a0df52..f8d0c0a63f 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -417,76 +417,76 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define RC4_KEY_SIZE 16/* 128-bit RC4KEY (104 bits unknown) */
 
 /* 2-unsigned char by 2-unsigned char subset of the full AES S-box table */
-static const unsigned short Sbox1[2][256] =   /* Sbox for hash (can be in 
ROM) */
-{ {
-   0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
-   0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
-   0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B,
-   0x41EC, 0xB367, 0x5FFD, 0x45EA, 0x23BF, 0x53F7, 0xE496, 0x9B5B,
-   0x75C2, 0xE11C, 0x3DAE, 0x4C6A, 0x6C5A, 0x7E41, 0xF502, 0x834F,
-   0x685C, 0x51F4, 0xD134, 0xF908, 0xE293, 0xAB73, 0x6253, 0x2A3F,
-   0x080C, 0x9552, 0x4665, 0x9D5E, 0x3028, 0x37A1, 0x0A0F, 0x2FB5,
-   0x0E09, 0x2436, 0x1B9B, 0xDF3D, 0xCD26, 0x4E69, 0x7FCD, 0xEA9F,
-   0x121B, 0x1D9E, 0x5874, 0x342E, 0x362D, 0xDCB2, 0xB4EE, 0x5BFB,
-   0xA4F6, 0x764D, 0xB761, 0x7DCE, 0x527B, 0xDD3E, 0x5E71, 0x1397,
-   0xA6F5, 0xB968, 0x, 0xC12C, 0x4060, 0xE31F, 0x79C8, 0xB6ED,
-   0xD4BE, 0x8D46, 0x67D9, 0x724B, 0x94DE, 0x98D4, 0xB0E8, 0x854A,
-   0xBB6B, 0xC52A, 0x4FE5, 0xED16, 0x86C5, 0x9AD7, 0x6655, 0x1194,
-   0x8ACF, 0xE910, 0x0406, 0xFE81, 0xA0F0, 0x7844, 0x25BA, 0x4BE3,
-   0xA2F3, 0x5DFE, 0x80C0, 0x058A, 0x3FAD, 0x21BC, 0x7048, 0xF104,
-   0x63DF, 0x77C1, 0xAF75, 0x4263, 0x2030, 0xE51A, 0xFD0E, 0xBF6D,
-   0x814C, 0x1814, 0x2635, 0xC32F, 0xBEE1, 0x35A2, 0x88CC, 0x2E39,
-   0x9357, 0x55F2, 0xFC82, 0x7A47, 0xC8AC, 0xBAE7, 0x322B, 0xE695,
-   0xC0A0, 0x1998, 0x9ED1, 0xA37F, 0x4466, 0x547E, 0x3BAB, 0x0B83,
-   0x8CCA, 0xC729, 0x6BD3, 0x283C, 0xA779, 0xBCE2, 0x161D, 0xAD76,
-   0xDB3B, 0x6456, 0x744E, 0x141E, 0x92DB, 0x0C0A, 0x486C, 0xB8E4,
-   0x9F5D, 0xBD6E, 0x43EF, 0xC4A6, 0x39A8, 0x31A4, 0xD337, 0xF28B,
-   0xD532, 0x8B43, 0x6E59, 0xDAB7, 0x018C, 0xB164, 0x9CD2, 0x49E0,
-   0xD8B4, 0xACFA, 0xF307, 0xCF25, 0xCAAF, 0xF48E, 0x47E9, 0x1018,
-   0x6FD5, 0xF088, 0x4A6F, 0x5C72, 0x3824, 0x57F1, 0x73C7, 0x9751,
-   0xCB23, 0xA17C, 0xE89C, 0x3E21, 0x96DD, 0x61DC, 0x0D86, 0x0F85,
-   0xE090, 0x7C42, 0x71C4, 0xCCAA, 0x90D8, 0x0605, 0xF701, 0x1C12,
-   0xC2A3, 0x6A5F, 0xAEF9, 0x69D0, 0x1791, 0x9958, 0x3A27, 0x27B9,
-   0xD938, 0xEB13, 0x2BB3, 0x2233, 0xD2BB, 0xA970, 0x0789, 0x33A7,
-   0x2DB6, 0x3C22, 0x1592, 0xC920, 0x8749, 0xAAFF, 0x5078, 0xA57A,
-   0x038F, 0x59F8, 0x0980, 0x1A17, 0x65DA, 0xD731, 0x84C6, 0xD0B8,
-   0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A,
-  },
-
-  {  /* second half of table is unsigned char-reversed version of first! */
-   0xA5C6, 0x84F8, 0x99EE, 0x8DF6, 0x0DFF, 0xBDD6, 0xB1DE, 0x5491,
-   0x5060, 0x0302, 0xA9CE, 0x7D56, 0x19E7, 0x62B5, 0xE64D, 0x9AEC,
-   0x458F, 0x9D1F, 0x4089, 0x87FA, 0x15EF, 0xEBB2, 0xC98E, 0x0BFB,
-   0xEC41, 0x67B3, 0xFD5F, 0xEA45, 0xBF23, 0xF753, 0x96E4, 0x5B9B,
-   0xC275, 0x1CE1, 0xAE3D, 0x6A4C, 0x5A6C, 0x417E, 0x02F5, 0x4F83,
-   0x5C68, 0xF451, 0x34D1, 0x08F9, 0x93E2, 0x73AB, 0x5362, 0x3F2A,
-   0x0C08, 0x5295, 0x6546, 0x5E9D, 0x2830, 0xA137, 0x0F0A, 0xB52F,
-   0x090E, 0x3624, 0x9B1B, 0x3DDF, 0x26CD, 0x694E, 0xCD7F, 0x9FEA,
-   0x1B12, 0x9E1D, 0x7458, 0x2E34, 0x2D36, 0xB2DC, 0xEEB4, 0xFB5B,
-   0xF6A4, 0x4D76, 0x61B7, 0xCE7D, 0x7B52, 0x3EDD, 0x715E, 0x9713,
-   0xF5A6, 0x68B9, 0x, 0x2CC1, 0x6040, 0x1FE3, 0xC879, 0xEDB6,
-   0xBED4, 0x468D, 0xD967, 0x4B72, 0xDE94, 0xD498, 0xE8B0, 0x4A85,
-   0x6BBB, 0x2AC5, 0xE54F, 0x16ED, 0xC586, 0xD79A, 0x5566, 0x9411,
-   0xCF8A, 0x10E9, 0x0604, 0x81FE, 0xF0A0, 0x4478, 0xBA25, 0xE34B,
-   0xF3A2, 0xFE5D, 0xC080, 0x8A05, 0xAD3F, 0xBC21, 0x4870, 0x04F1,
-   0xDF63, 0xC177, 0x75AF, 0x6342, 0x3020, 0x1AE5, 0x0EFD, 0x6DBF,
-   0x4C81, 0x1418, 0x3526, 0x2FC3, 0xE1BE, 0xA235, 0xCC88, 0x392E,
-   0x5793, 0xF255, 0x82FC, 0x477A, 0xACC8, 0xE7BA, 0x2B32, 0x95E6,
-   0xA0C0, 0x9819, 0xD19E, 0x7FA3, 0x6644, 0x7E54, 0xAB3B, 0x830B,
-   0xCA8C, 0x29C7, 0xD36B, 0x3C28, 0x79A7, 0xE2BC, 0x1D16, 0x76AD,
-   0x3BDB, 0x5664, 0x4E74, 0x1E14, 0xDB92, 0x0A0C, 0x6C48, 0xE4B8,
-   0x5D9F, 0x6EBD, 0xEF43, 0xA6C4, 0xA839, 0xA431, 0x37D3, 0x8BF2,
-   0x32D5, 0x438B, 0x596E, 0xB7DA, 0x8C01, 0x64B1, 0xD29C, 0xE049,
-   0xB4D8, 0xFAAC, 0x07F3, 0x25CF, 0xAFCA, 0x8EF4, 0xE947, 0x1810,
-   0xD56F, 0x88F0, 0x6F4A, 0x725C

[PATCH v4 01/15] staging: rtl8723au: Reformat whitespace to increase readability

2015-03-28 Thread M. Vefa Bicakci
Adjust the whitespace in the signature, local variable declaration and
initialization parts of a number of functions to increase readability
in rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci m@runbox.com

---

v2: Make sure that the arcfour_encrypt function's argument list is split
according to the kernel code style.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 79 +--
 1 file changed, 38 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 045a24c81b..088533c5b1 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -31,11 +31,11 @@ struct arc4context {
 
 static void arcfour_init(struct arc4context *parc4ctx, u8 *key, u32 key_len)
 {
-   u32 t, u;
-   u32 keyindex;
-   u32 stateindex;
+   u32 t, u;
+   u32 keyindex;
+   u32 stateindex;
u8 *state;
-   u32 counter;
+   u32 counter;
 
state = parc4ctx-state;
parc4ctx-x = 0;
@@ -55,7 +55,8 @@ static void arcfour_init(struct arc4context *parc4ctx, u8 
*key, u32 key_len)
}
 
 }
-static u32 arcfour_byte(   struct arc4context  *parc4ctx)
+
+static u32 arcfour_byte(struct arc4context *parc4ctx)
 {
u32 x;
u32 y;
@@ -75,16 +76,13 @@ static u32 arcfour_byte(struct arc4context  
*parc4ctx)
return state[(sx + sy)  0xff];
 }
 
-static void arcfour_encrypt(   struct arc4context  *parc4ctx,
-   u8 *dest,
-   u8 *src,
-   u32 len)
+static void arcfour_encrypt(struct arc4context *parc4ctx, u8 *dest,
+   u8 *src, u32 len)
 {
-   u32 i;
+   u32 i;
 
for (i = 0; i  len; i++)
dest[i] = src[i] ^ (unsigned char)arcfour_byte(parc4ctx);
-
 }
 
 static int bcrc32initialized;
@@ -368,7 +366,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
   u8 *mic_code, u8 pri)
 {
 
-   struct mic_data micdata;
+   struct mic_data micdata;
u8 priority[4]={0x0, 0x0, 0x0, 0x0};
 
rtw_secmicsetkey23a(micdata, key);
@@ -604,21 +602,21 @@ static void phase2(u8 *rc4key, const u8 *tk, const u16 
*p1k, u16 iv16)
 int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
struct xmit_frame *pxmitframe)
 {
-   u16 pnl;
-   u32 pnh;
-   u8  rc4key[16];
-   u8   ttkey[16];
-   u8  crc[4];
-   u8   hw_hdr_offset = 0;
+   u16 pnl;
+   u32 pnh;
+   u8 rc4key[16];
+   u8 ttkey[16];
+   u8 crc[4];
+   u8 hw_hdr_offset = 0;
struct arc4context mycontext;
-   int curfragnum, length;
-   u32 prwskeylen;
-   u8  *pframe, *payload, *iv, *prwskey;
+   int curfragnum, length;
+   u32 prwskeylen;
+   u8 *pframe, *payload, *iv, *prwskey;
union pn48 dot11txpn;
-   struct  sta_info*stainfo;
-   struct  pkt_attrib   *pattrib = pxmitframe-attrib;
-   struct  security_priv   *psecuritypriv = padapter-securitypriv;
-   struct  xmit_priv   *pxmitpriv = padapter-xmitpriv;
+   struct sta_info *stainfo;
+   struct pkt_attrib *pattrib = pxmitframe-attrib;
+   struct security_priv *psecuritypriv = padapter-securitypriv;
+   struct xmit_priv *pxmitpriv = padapter-xmitpriv;
int res = _SUCCESS;
 
if (!pxmitframe-buf_addr)
@@ -706,17 +704,17 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 {
u16 pnl;
u32 pnh;
-   u8   rc4key[16];
-   u8   ttkey[16];
-   u8  crc[4];
+   u8 rc4key[16];
+   u8 ttkey[16];
+   u8 crc[4];
struct arc4context mycontext;
-   int length;
-   u32 prwskeylen;
-   u8  *pframe, *payload, *iv, *prwskey;
+   int length;
+   u32 prwskeylen;
+   u8 *pframe, *payload, *iv, *prwskey;
union pn48 dot11txpn;
-   struct  sta_info*stainfo;
-   struct  rx_pkt_attrib *prxattrib = precvframe-attrib;
-   struct  security_priv *psecuritypriv = padapter-securitypriv;
+   struct sta_info *stainfo;
+   struct rx_pkt_attrib *prxattrib = precvframe-attrib;
+   struct security_priv *psecuritypriv = padapter-securitypriv;
struct sk_buff *skb = precvframe-pkt;
int res = _SUCCESS;
 
@@ -1128,8 +1126,8 @@ static void bitwise_xor(u8 *ina, u8 *inb, u8 *out)
 
 static int aes_cipher(u8 *key, uint hdrlen, u8 *pframe, uint plen)
 {
-   uintqc_exists, a4_exists, i, j, payload_remainder,
-   num_blocks, payload_index;
+   uint qc_exists, a4_exists, i, j, payload_remainder,
+num_blocks, payload_index;
u8 pn_vector[6];
u8 mic_iv[16];
u8 mic_header1[16];
@@ -1345,12 +1343,11 @@ out:
return res;
 }
 
-static int aes_decipher(u8 *key

[PATCH v4 12/15] staging: rtl8723au: suspect code indent for conditional statements

2015-03-28 Thread M. Vefa Bicakci
Correct a number of indentation-with-spaces-and-tabs issues in
rtl8723au's rtw_security.c, according to checkpatch.pl:
WARNING: suspect code indent for conditional statements

Signed-off-by: M. Vefa Bicakci m@runbox.com

---

v3: Make sure that all edited lines are at most 80 characters wide.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 46 ---
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 8591b49664..4330479ee0 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -761,8 +761,16 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 
if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
crc[1] != payload[length - 3] || crc[0] != payload[length - 4]) {
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
(rtw_wep_decrypt23a:icv error crc[3](%x)!= payload[length-1](%x) || 
crc[2](%x)!= payload[length-2](%x) || crc[1](%x)!= payload[length-3](%x) || 
crc[0](%x)!= payload[length-4](%x)\n,
-   crc[3], payload[length - 1], crc[2], 
payload[length - 2], crc[1], payload[length - 3], crc[0], payload[length - 4]));
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
+(rtw_wep_decrypt23a:icv error 
+ crc[3](%x)!= payload[length-1](%x) || 
+ crc[2](%x)!= payload[length-2](%x) || 
+ crc[1](%x)!= payload[length-3](%x) || 
+ crc[0](%x)!= payload[length-4](%x)\n,
+ crc[3], payload[length - 1],
+ crc[2], payload[length - 2],
+ crc[1], payload[length - 3],
+ crc[0], payload[length - 4]));
res = _FAIL;
}
 
@@ -909,9 +917,9 @@ static void mix_column(u8 *in, u8 *out)
 
for (i = 0; i  4; i++) {
if ((in[i]  0x80) == 0x80)
-   add1b[i] = 0x1b;
+   add1b[i] = 0x1b;
else
-   add1b[i] = 0x00;
+   add1b[i] = 0x00;
}
 
swap_halfs[0] = in[2]; /* Swap halfs */
@@ -966,21 +974,21 @@ static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext)
 
for (round = 0; round  11; round++) {
if (round == 0) {
-   xor_128(round_key, data, ciphertext);
-   next_key(round_key, round);
+   xor_128(round_key, data, ciphertext);
+   next_key(round_key, round);
} else if (round == 10) {
-   byte_sub(ciphertext, intermediatea);
-   shift_row(intermediatea, intermediateb);
-   xor_128(intermediateb, round_key, ciphertext);
+   byte_sub(ciphertext, intermediatea);
+   shift_row(intermediatea, intermediateb);
+   xor_128(intermediateb, round_key, ciphertext);
} else { /* 1 - 9 */
-   byte_sub(ciphertext, intermediatea);
-   shift_row(intermediatea, intermediateb);
-   mix_column(intermediateb[0], intermediatea[0]);
-   mix_column(intermediateb[4], intermediatea[4]);
-   mix_column(intermediateb[8], intermediatea[8]);
-   mix_column(intermediateb[12], intermediatea[12]);
-   xor_128(intermediatea, round_key, ciphertext);
-   next_key(round_key, round);
+   byte_sub(ciphertext, intermediatea);
+   shift_row(intermediatea, intermediateb);
+   mix_column(intermediateb[0], intermediatea[0]);
+   mix_column(intermediateb[4], intermediatea[4]);
+   mix_column(intermediateb[8], intermediatea[8]);
+   mix_column(intermediateb[12], intermediatea[12]);
+   xor_128(intermediatea, round_key, ciphertext);
+   next_key(round_key, round);
}
}
 
@@ -1481,7 +1489,7 @@ static int aes_decipher(u8 *key, uint hdrlen, u8 *pframe, 
uint plen)
for (j = 0; j  16; j++)
padded_buffer[j] = 0x00;
for (j = 0; j  payload_remainder; j++)
-   padded_buffer[j] = message[payload_index++];
+   padded_buffer[j] = message[payload_index++];
bitwise_xor(aes_out, padded_buffer, chain_buffer);
aes128k128d(key, chain_buffer, aes_out);
}
@@ -1511,7 +1519,7 @@ static int aes_decipher(u8 *key, uint hdrlen, u8 *pframe, 
uint plen)
  message, pn_vector, num_blocks+1);
 
for (j = 0; j  16; j

[PATCH v4 00/15] checkpatch clean-up of rtl8723au's rtw_security.c

2015-03-28 Thread M. Vefa Bicakci
These commits address a number of checkpatch.pl warnings and errors
in rtl8723au's rtw_security.c.

Prior to this set of commits, checkpatch.pl reported the following:
total: 76 errors, 138 warnings, 1621 lines checked

After applying this set of commits, checkpatch.pl reports the following:
total: 0 errors, 26 warnings, 1624 lines checked
where the only remaining warnings relate to lines longer than 80
characters and quoted strings split across multiple lines.

There are also a number of commits which improve the code in other ways.
For example, the commit titled Reorganize a few functions to remove
indentation reworks two functions to make them more readable, whereas
the commit titled Rework two byte array comparisons reworks two CRC
verifications for the same reason, and Use __func__ in trace logs
avoids hardcoding function names in trace logs to increase
maintainability.

All of the commits have been verified to compile successfully via the
use of the interactive rebase feature of git.

v4: Rebased onto Greg Kroah-Hartman's staging-next tree, on top of
the following commit
  commit 153fe946412b5da1a8808f79d4f7f4ebfa7586b0
  staging: fbtft: Do not use binary constants

In addition, fix-up the commit messages to move the patch revision
notes below the newly added --- markers where needed.

v3: Rebased onto Greg Kroah-Hartman's staging-next tree, on top of
the following commit
  5ec293650827122df300581c17ca1d5de03bac3d.
  Staging: dgnc: release the lock before testing for nullity

Please see the individual commit messages for the changes
since v2. In summary, the following commits have been updated:
- that open brace should be on the previous line
- suspect code indent for conditional statements

The following commit is new:
- Use __func__ in trace logs

Finally, the following commit has been removed:
- Do not initialize a static to 0

v2: Please see the individual commit messages for the changes
since v1. In summary, the following commits have been updated:
- Reformat whitespace to increase readability
- Fix before/around/after whitespace issues
- Rework two byte array comparisons

M. Vefa Bicakci (15):
  staging: rtl8723au: Reformat whitespace to increase readability
  staging: rtl8723au: Fix before/around/after whitespace issues
  staging: rtl8723au: else should follow close brace
  staging: rtl8723au: Fix the indentation of two lines
  staging: rtl8723au: Reorganize a few functions to remove indentation
  staging: rtl8723au: else is not generally useful after a return
  staging: rtl8723au: Remove unneeded curly braces
  staging: rtl8723au: trailing statements should be on next line
  staging: rtl8723au: that open brace should be on the previous line
  staging: rtl8723au: No spaces at the start of a line
  staging: rtl8723au: Adjust whitespace in and around comments
  staging: rtl8723au: suspect code indent for conditional statements
  staging: rtl8723au: Rework two byte array comparisons
  staging: rtl8723au: Use __func__ in trace logs
  staging: rtl8723au: Remove unneeded comments

 drivers/staging/rtl8723au/core/rtw_security.c | 799 +-
 1 file changed, 401 insertions(+), 398 deletions(-)

-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 07/15] staging: rtl8723au: Remove unneeded curly braces

2015-03-28 Thread M. Vefa Bicakci
Correct a number of checkpatch.pl warnings in rtl8723au's rtw_security.c
related to the existence of unnecessary curly braces around single
statement blocks:
WARNING: braces {} are not necessary for single statement blocks

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 16 +---
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index f7571cf091..b4327aaf71 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -113,9 +113,8 @@ static void crc32_init(void)
for (i = 0; i  256; ++i) {
k = crc32_reverseBit((u8)i);
 
-   for (c = ((u32)k)  24, j = 8; j  0; --j) {
+   for (c = ((u32)k)  24, j = 8; j  0; --j)
c = c  0x8000 ? (c  1) ^ CRC32_POLY : (c  1);
-   }
 
p1 = (u8 *)crc32_table[i];
 
@@ -267,9 +266,8 @@ static u32 secmicgetuint32(u8 *p)
s32 i;
u32 res = 0;
 
-   for (i = 0; i  4; i++) {
+   for (i = 0; i  4; i++)
res |= ((u32)(*p++))  (8 * i);
-   }
 
return res;
 }
@@ -353,9 +351,8 @@ void rtw_secgetmic23a(struct mic_data *pmicdata, u8 *dst)
rtw_secmicappend23abyte23a(pmicdata, 0);
rtw_secmicappend23abyte23a(pmicdata, 0);
/*  and then zeroes until the length is a multiple of 4 */
-   while (pmicdata-nBytesInM != 0) {
+   while (pmicdata-nBytesInM != 0)
rtw_secmicappend23abyte23a(pmicdata, 0);
-   }
/*  The appendByte function has already computed the result. */
secmicputuint32(dst, pmicdata-L);
secmicputuint32(dst + 4, pmicdata-R);
@@ -871,10 +868,8 @@ static void byte_sub(u8 *in, u8 *out)
 {
int i;
 
-   for (i = 0; i  16; i++) {
+   for (i = 0; i  16; i++)
out[i] = sbox(in[i]);
-   }
-
 }
 
 static void shift_row(u8 *in, u8 *out)
@@ -935,9 +930,8 @@ static void mix_column(u8 *in, u8 *out)
 
for (i = 3; i  0; i--) { /* logical shift left 1 bit */
andf7[i] = andf7[i]  1;
-   if ((andf7[i - 1]  0x80) == 0x80) {
+   if ((andf7[i - 1]  0x80) == 0x80)
andf7[i] = (andf7[i] | 0x01);
-   }
}
andf7[0] = andf7[0]  1;
andf7[0] = andf7[0]  0xfe;
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 02/15] staging: rtl8723au: Fix before/around/after whitespace issues

2015-03-28 Thread M. Vefa Bicakci
Correct a number of space(s) required before/around/after checkpatch.pl
issues in a number of functions in rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci m@runbox.com

---

v2: Correct one more whitespace issue (length-4) in
rtw_tkip_decrypt23a.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 175 +-
 1 file changed, 87 insertions(+), 88 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 088533c5b1..cb78d6dd9c 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -129,14 +129,14 @@ static void crc32_init(void)
 static u32 getcrc32(u8 *buf, int len)
 {
u8 *p;
-   u32  crc;
+   u32 crc;
 
if (bcrc32initialized == 0) crc32_init();
 
crc = 0x;   /* preload shift register, per CRC-32 spec */
 
for (p = buf; len  0; ++p, --len)
-   crc = crc32_table[ (crc ^ *p)  0xff] ^ (crc  8);
+   crc = crc32_table[(crc ^ *p)  0xff] ^ (crc  8);
 
return ~crc;/* transmit complement, per CRC-32 spec */
 }
@@ -182,7 +182,7 @@ void rtw_wep_encrypt23a(struct rtw_adapter *padapter,
if ((curfragnum + 1) == pattrib-nr_frags) {
/* the last fragment */
length = pattrib-last_txcmdsz - pattrib-hdrlen -
-   pattrib-iv_len- pattrib-icv_len;
+   pattrib-iv_len - pattrib-icv_len;
 
*((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
 
@@ -265,8 +265,8 @@ static u32 secmicgetuint32(u8 *p)
s32 i;
u32 res = 0;
 
-   for (i = 0; i4; i++) {
-   res |= ((u32)(*p++))  (8*i);
+   for (i = 0; i  4; i++) {
+   res |= ((u32)(*p++))  (8 * i);
}
 
return res;
@@ -277,7 +277,7 @@ static void secmicputuint32(u8 *p, u32 val)
 {
long i;
 
-   for (i = 0; i4; i++) {
+   for (i = 0; i  4; i++) {
*p++ = (u8) (val  0xff);
val = 8;
}
@@ -310,7 +310,7 @@ void rtw_secmicappend23abyte23a(struct mic_data *pmicdata, 
u8 b)
 {
 
/*  Append the byte to our word-sized buffer */
-   pmicdata-M |= ((unsigned long)b)  (8*pmicdata-nBytesInM);
+   pmicdata-M |= ((unsigned long)b)  (8 * pmicdata-nBytesInM);
pmicdata-nBytesInM++;
/*  Process the word if it is full. */
if (pmicdata-nBytesInM = 4) {
@@ -334,7 +334,7 @@ void rtw_secmicappend23a(struct mic_data *pmicdata, u8 
*src, u32 nbytes)
 {
 
/*  This is simple */
-   while(nbytes  0) {
+   while (nbytes  0) {
rtw_secmicappend23abyte23a(pmicdata, *src++);
nbytes--;
}
@@ -351,12 +351,12 @@ void rtw_secgetmic23a(struct mic_data *pmicdata, u8 *dst)
rtw_secmicappend23abyte23a(pmicdata, 0);
rtw_secmicappend23abyte23a(pmicdata, 0);
/*  and then zeroes until the length is a multiple of 4 */
-   while(pmicdata-nBytesInM != 0) {
+   while (pmicdata-nBytesInM != 0) {
rtw_secmicappend23abyte23a(pmicdata, 0);
}
/*  The appendByte function has already computed the result. */
secmicputuint32(dst, pmicdata-L);
-   secmicputuint32(dst+4, pmicdata-R);
+   secmicputuint32(dst + 4, pmicdata-R);
/*  Reset to the empty message. */
secmicclear(pmicdata);
 
@@ -367,10 +367,10 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 {
 
struct mic_data micdata;
-   u8 priority[4]={0x0, 0x0, 0x0, 0x0};
+   u8 priority[4] = {0x0, 0x0, 0x0, 0x0};
 
rtw_secmicsetkey23a(micdata, key);
-   priority[0]= pri;
+   priority[0] = pri;
 
/* Michael MIC pseudo header: DA, SA, 3 x 0, Priority */
if (header[1]1) {   /* ToDS == 1 */
@@ -401,7 +401,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define   Lo8(v16)   ((u8)((v16)0x00FF))
 #define   Hi8(v16)   ((u8)(((v16)  8)  0x00FF))
 #define  Lo16(v32)   ((u16)((v32)0x))
-#define  Hi16(v32)   ((u16)(((v32) 16)  0x))
+#define  Hi16(v32)   ((u16)(((v32)  16)  0x))
 #define  Mk16(hi, lo) ((lo) ^ (((u16)(hi))  8))
 
 /* select the Nth 16-bit word of the temporal key unsigned char array TK[]   */
@@ -418,7 +418,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define RC4_KEY_SIZE 16/* 128-bit RC4KEY (104 bits unknown) */
 
 /* 2-unsigned char by 2-unsigned char subset of the full AES S-box table */
-static const unsigned short Sbox1[2][256]=   /* Sbox for hash (can be in 
ROM) */
+static const unsigned short Sbox1[2][256] =   /* Sbox for hash (can be in 
ROM) */
 { {
0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
@@ -520,13 +520,13

[PATCH v4 09/15] staging: rtl8723au: that open brace should be on the previous line

2015-03-28 Thread M. Vefa Bicakci
Correct two instances of the checkpatch.pl error indicating that the
opening curly braces should not be on new lines:
ERROR: that open brace { should be on the previous line

Signed-off-by: M. Vefa Bicakci m@runbox.com

---

v3: Make sure that all edited lines are at most 80 characters wide.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 803f8965a4..0557a0df52 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -760,8 +760,8 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
 
*((u32 *)crc) = le32_to_cpu(getcrc32(payload, length - 4));
 
-   if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] || 
crc[1] != payload[length - 3] || crc[0] != payload[length - 4])
-   {
+   if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
+   crc[1] != payload[length - 3] || crc[0] != payload[length - 4]) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
(rtw_wep_decrypt23a:icv error crc[3](%x)!= payload[length-1](%x) || 
crc[2](%x)!= payload[length-2](%x) || crc[1](%x)!= payload[length-3](%x) || 
crc[0](%x)!= payload[length-4](%x)\n,
crc[3], payload[length - 1], crc[2], 
payload[length - 2], crc[1], payload[length - 3], crc[0], payload[length - 4]));
res = _FAIL;
@@ -845,8 +845,7 @@ static void next_key(u8 *key, int round)
 {
u8 rcon;
u8 sbox_key[4];
-   u8 rcon_table[12] =
-   {
+   u8 rcon_table[12] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x1b, 0x36, 0x36, 0x36
};
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 05/15] staging: rtl8723au: Reorganize a few functions to remove indentation

2015-03-28 Thread M. Vefa Bicakci
Prior to this commit, functions rtw_tkip_encrypt23a and rtw_tkip_decrypt23a had
large if blocks which contained the majority of the logic in the functions.

Rework these functions so that if the negated version of the aforementioned if
blocks' conditions are true, we return from the function with _FAIL, as
expected by the calling code.

This lets us remove two levels of indentation from the functions in
question, making them more readable.

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 178 +-
 1 file changed, 88 insertions(+), 90 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index df1787f20e..f7b1d45981 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -618,6 +618,9 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
struct xmit_priv *pxmitpriv = padapter-xmitpriv;
int res = _SUCCESS;
 
+   if (pattrib-encrypt != WLAN_CIPHER_SUITE_TKIP)
+   return _FAIL;
+
if (!pxmitframe-buf_addr)
return _FAIL;
 
@@ -625,71 +628,66 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
 
pframe = pxmitframe-buf_addr + hw_hdr_offset;
/* 4 start to encrypt each fragment */
-   if (pattrib-encrypt == WLAN_CIPHER_SUITE_TKIP) {
-   if (pattrib-psta)
-   stainfo = pattrib-psta;
-   else {
-   DBG_8723A(%s, call rtw_get_stainfo()\n, __func__);
-   stainfo = rtw_get_stainfo23a(padapter-stapriv,
-pattrib-ra[0]);
-   }
-
-   if (stainfo != NULL) {
-
-   if (!(stainfo-state  _FW_LINKED)) {
-   DBG_8723A(%s, psta-state(0x%x) != 
_FW_LINKED\n, __func__, stainfo-state);
-   return _FAIL;
-   }
+   if (pattrib-psta)
+   stainfo = pattrib-psta;
+   else {
+   DBG_8723A(%s, call rtw_get_stainfo()\n, __func__);
+   stainfo = rtw_get_stainfo23a(padapter-stapriv,
+pattrib-ra[0]);
+   }
 
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
(rtw_tkip_encrypt23a: stainfo!= NULL!!!\n));
+   if (stainfo == NULL) {
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
(rtw_tkip_encrypt23a: stainfo == NULL!!!\n));
+   DBG_8723A(%s, psta == NUL\n, __func__);
+   return _FAIL;
+   }
 
-   if (is_multicast_ether_addr(pattrib-ra))
-   prwskey = 
psecuritypriv-dot118021XGrpKey[psecuritypriv-dot118021XGrpKeyid].skey;
-   else
-   prwskey = stainfo-dot118021x_UncstKey.skey[0];
+   if (!(stainfo-state  _FW_LINKED)) {
+   DBG_8723A(%s, psta-state(0x%x) != _FW_LINKED\n, __func__, 
stainfo-state);
+   return _FAIL;
+   }
 
-   prwskeylen = 16;
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, (rtw_tkip_encrypt23a: 
stainfo!= NULL!!!\n));
 
-   for (curfragnum = 0; curfragnum  pattrib-nr_frags; 
curfragnum++) {
-   iv = pframe+pattrib-hdrlen;
-   payload = 
pframe+pattrib-iv_len+pattrib-hdrlen;
+   if (is_multicast_ether_addr(pattrib-ra))
+   prwskey = 
psecuritypriv-dot118021XGrpKey[psecuritypriv-dot118021XGrpKeyid].skey;
+   else
+   prwskey = stainfo-dot118021x_UncstKey.skey[0];
 
-   GET_TKIP_PN(iv, dot11txpn);
+   prwskeylen = 16;
 
-   pnl = (u16)(dot11txpn.val);
-   pnh = (u32)(dot11txpn.val16);
+   for (curfragnum = 0; curfragnum  pattrib-nr_frags; curfragnum++) {
+   iv = pframe+pattrib-hdrlen;
+   payload = pframe+pattrib-iv_len+pattrib-hdrlen;
 
-   phase1((u16 *)ttkey[0], prwskey, 
pattrib-ta[0], pnh);
+   GET_TKIP_PN(iv, dot11txpn);
 
-   phase2(rc4key[0], prwskey, (u16 *)ttkey[0], 
pnl);
+   pnl = (u16)(dot11txpn.val);
+   pnh = (u32)(dot11txpn.val16);
 
-   if ((curfragnum + 1) == pattrib-nr_frags) {
/* 4 the last fragment */
-   length = 
pattrib-last_txcmdsz-pattrib-hdrlen-pattrib-iv_len - pattrib-icv_len;
-   RT_TRACE(_module_rtl871x_security_c_, 
_drv_info_, (pattrib-iv_len =%x, pattrib-icv_len =%x\n, pattrib-iv_len, 
pattrib-icv_len));
-   *((u32 *)crc) = 
cpu_to_le32(getcrc32(payload, length));/* modified by Amy*/
+   phase1

[PATCH v4 03/15] staging: rtl8723au: else should follow close brace

2015-03-28 Thread M. Vefa Bicakci
Correct checkpatch.pl errors in rtl8723au's rtw_security.c indicating
that an else statement should follow the closing brace of the previous
if/else if code block:
ERROR: else should follow close brace '}'

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index cb78d6dd9c..17234e0bf1 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -379,8 +379,7 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
rtw_secmicappend23a(micdata, header[24], 6);
else
rtw_secmicappend23a(micdata, header[10], 6);
-   }
-   else{   /* ToDS == 0 */
+   } else {/* ToDS == 0 */
rtw_secmicappend23a(micdata, header[4], 6);   /* DA */
if (header[1]2)  /* From Ds == 1 */
rtw_secmicappend23a(micdata, header[16], 6);
@@ -673,8 +672,7 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
arcfour_encrypt(mycontext, payload, 
payload, length);
arcfour_encrypt(mycontext, 
payload+length, crc, 4);
 
-   }
-   else {
+   } else {
length = 
pxmitpriv-frag_len-pattrib-hdrlen-pattrib-iv_len-pattrib-icv_len;
*((u32 *)crc) = 
cpu_to_le32(getcrc32(payload, length));/* modified by Amy*/
arcfour_init(mycontext, rc4key, 16);
@@ -686,8 +684,7 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
}
}
 
-   }
-   else {
+   } else {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
(rtw_tkip_encrypt23a: stainfo == NULL!!!\n));
DBG_8723A(%s, psta == NUL\n, __func__);
res = _FAIL;
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 08/15] staging: rtl8723au: trailing statements should be on next line

2015-03-28 Thread M. Vefa Bicakci
Correct a number of checkpatch.pl errors in rtl8723au's rtw_security.c
related to trailing statements:
ERROR: trailing statements should be on next line

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index b4327aaf71..803f8965a4 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -132,7 +132,8 @@ static u32 getcrc32(u8 *buf, int len)
u8 *p;
u32 crc;
 
-   if (bcrc32initialized == 0) crc32_init();
+   if (bcrc32initialized == 0)
+   crc32_init();
 
crc = 0x;   /* preload shift register, per CRC-32 spec */
 
@@ -559,8 +560,10 @@ static void phase2(u8 *rc4key, const u8 *tk, const u16 
*p1k, u16 iv16)
u16 PPK[6];  /* temporary key for mixing*/
 
/* Note: all adds in the PPK[] equations below are mod 2**16 */
-   for (i = 0; i  5; i++) PPK[i] = p1k[i];/* first, copy P1K to PPK   
   */
-   PPK[5] = p1k[4] + iv16; /* next,  add in IV16   
   */
+   for (i = 0; i  5; i++)
+   PPK[i] = p1k[i];/* first, copy P1K to PPK  */
+
+   PPK[5] = p1k[4] + iv16; /* next,  add in IV16  */
 
/* Bijective non-linear mixing of the 96 bits of PPK[0..5]   */
PPK[0] +=_S_(PPK[5] ^ TK16(0));   /* Mix key in each round */
@@ -960,7 +963,8 @@ static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext)
u8 intermediateb[16];
u8 round_key[16];
 
-   for (i = 0; i  16; i++) round_key[i] = key[i];
+   for (i = 0; i  16; i++)
+   round_key[i] = key[i];
 
for (round = 0; round  11; round++) {
if (round == 0) {
@@ -1044,7 +1048,8 @@ static void construct_mic_header2(u8 *mic_header2, u8 
*mpdu, int a4_exists,
 {
int i;
 
-   for (i = 0; i  16; i++) mic_header2[i] = 0x00;
+   for (i = 0; i  16; i++)
+   mic_header2[i] = 0x00;
 
mic_header2[0] = mpdu[16];/* A3 */
mic_header2[1] = mpdu[17];
@@ -1057,7 +1062,8 @@ static void construct_mic_header2(u8 *mic_header2, u8 
*mpdu, int a4_exists,
mic_header2[7] = 0x00; /* mpdu[23]; */
 
if (!qc_exists  a4_exists) {
-   for (i = 0; i  6; i++) mic_header2[8+i] = mpdu[24+i];   /* A4 
*/
+   for (i = 0; i  6; i++)
+   mic_header2[8+i] = mpdu[24+i];   /* A4 */
}
 
if (qc_exists  !a4_exists) {
@@ -1066,7 +1072,8 @@ static void construct_mic_header2(u8 *mic_header2, u8 
*mpdu, int a4_exists,
}
 
if (qc_exists  a4_exists) {
-   for (i = 0; i  6; i++) mic_header2[8+i] = mpdu[24+i];   /* A4 
*/
+   for (i = 0; i  6; i++)
+   mic_header2[8+i] = mpdu[24+i];   /* A4 */
 
mic_header2[14] = mpdu[30]  0x0f;
mic_header2[15] = mpdu[31]  0x00;
@@ -1084,7 +1091,9 @@ static void construct_ctr_preload(u8 *ctr_preload, int 
a4_exists, int qc_exists,
 {
int i = 0;
 
-   for (i = 0; i  16; i++) ctr_preload[i] = 0x00;
+   for (i = 0; i  16; i++)
+   ctr_preload[i] = 0x00;
+
i = 0;
 
ctr_preload[0] = 0x01;  /* flag */
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 06/15] staging: rtl8723au: else is not generally useful after a return

2015-03-28 Thread M. Vefa Bicakci
Correct a checkpatch.pl warning regarding rtl8723au's
rtw_security.c::crc32_init pointing out that having an else statement
after a break or a return is not useful.

drivers/staging/rtl8723au/core/rtw_security.c:105:
WARNING: else is not generally useful after a break or return

Signed-off-by: M. Vefa Bicakci m@runbox.com
---
 drivers/staging/rtl8723au/core/rtw_security.c | 42 ++-
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index f7b1d45981..f7571cf091 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -99,31 +99,33 @@ static u8 crc32_reverseBit(u8 data)
 
 static void crc32_init(void)
 {
+   int i, j;
+   u32 c;
+   u8 *p, *p1;
+   u8 k;
 
if (bcrc32initialized == 1)
return;
-   else{
-   int i, j;
-   u32 c;
-   u8 *p = (u8 *)c, *p1;
-   u8 k;
-
-   c = 0x1234;
-
-   for (i = 0; i  256; ++i) {
-   k = crc32_reverseBit((u8)i);
-   for (c = ((u32)k)  24, j = 8; j  0; --j) {
-   c = c  0x8000 ? (c  1) ^ CRC32_POLY : (c 
 1);
-   }
-   p1 = (u8 *)crc32_table[i];
-
-   p1[0] = crc32_reverseBit(p[3]);
-   p1[1] = crc32_reverseBit(p[2]);
-   p1[2] = crc32_reverseBit(p[1]);
-   p1[3] = crc32_reverseBit(p[0]);
+
+   p = (u8 *) c;
+   c = 0x1234;
+
+   for (i = 0; i  256; ++i) {
+   k = crc32_reverseBit((u8)i);
+
+   for (c = ((u32)k)  24, j = 8; j  0; --j) {
+   c = c  0x8000 ? (c  1) ^ CRC32_POLY : (c  1);
}
-   bcrc32initialized = 1;
+
+   p1 = (u8 *)crc32_table[i];
+
+   p1[0] = crc32_reverseBit(p[3]);
+   p1[1] = crc32_reverseBit(p[2]);
+   p1[2] = crc32_reverseBit(p[1]);
+   p1[3] = crc32_reverseBit(p[0]);
}
+
+   bcrc32initialized = 1;
 }
 
 static u32 getcrc32(u8 *buf, int len)
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 13/15] staging: rtl8723au: Rework two byte array comparisons

2015-03-28 Thread M. Vefa Bicakci
Prior to this commit, rtl8723au's rtw_security.c had two instances of
byte array comparisons (for CRC checks) where the individual elements
of the byte arrays were compared one by one and an error trace would
be output if the byte arrays were determined to be different.

This commit improves the readability of the CRC verification by
placing the individual 4 bytes of each byte array into an 32-bit
unsigned integer and comparing the two resulting integers.

Thanks to Larry Finger for spotting the code style issues in the
previous version of this commit, and thanks to Joe Perches for
suggesting the use of 32-bit integer comparisons instead of byte
array comparisons.

Signed-off-by: M. Vefa Bicakci m@runbox.com

---

v2: Correct code style issues and compare 32-bit integers instead of
byte arrays. Update the commit message to better reflect the nature
of the changes.
---
 drivers/staging/rtl8723au/core/rtw_security.c | 39 ++-
 1 file changed, 14 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 4330479ee0..eb3544866a 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -210,7 +210,7 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
 struct recv_frame *precvframe)
 {
/*  exclude ICV */
-   u8 crc[4];
+   u32 actual_crc, expected_crc;
struct arc4context mycontext;
int length;
u32 keylength;
@@ -243,19 +243,14 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
arcfour_encrypt(mycontext, payload, payload, length);
 
/* calculate icv and compare the icv */
-   *((u32 *)crc) = le32_to_cpu(getcrc32(payload, length - 4));
+   actual_crc = le32_to_cpu(getcrc32(payload, length - 4));
+   expected_crc = le32_to_cpu(get_unaligned_le32(payload[length - 4]));
 
-   if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
-   crc[1] != payload[length - 3] || crc[0] != payload[length - 4]) {
+   if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-(rtw_wep_decrypt23a:icv error crc[3](%x)!= payload
- [length-1](%x) || crc[2](%x)!= payload[length-2](%x)
-  || crc[1](%x)!= payload[length-3](%x) || crc[0](%x)
- != payload[length-4](%x)\n,
- crc[3], payload[length - 1],
- crc[2], payload[length - 2],
- crc[1], payload[length - 3],
- crc[0], payload[length - 4]));
+(rtw_wep_decrypt23a:icv CRC mismatch: 
+ actual: %08x, expected: %08x\n,
+ actual_crc, expected_crc));
}
 }
 
@@ -702,7 +697,7 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
u32 pnh;
u8 rc4key[16];
u8 ttkey[16];
-   u8 crc[4];
+   u32 actual_crc, expected_crc;
struct arc4context mycontext;
int length;
u32 prwskeylen;
@@ -757,20 +752,14 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
arcfour_init(mycontext, rc4key, 16);
arcfour_encrypt(mycontext, payload, payload, length);
 
-   *((u32 *)crc) = le32_to_cpu(getcrc32(payload, length - 4));
+   actual_crc = le32_to_cpu(getcrc32(payload, length - 4));
+   expected_crc = le32_to_cpu(get_unaligned_le32(payload[length - 4]));
 
-   if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
-   crc[1] != payload[length - 3] || crc[0] != payload[length - 4]) {
+   if (actual_crc != expected_crc) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
-(rtw_wep_decrypt23a:icv error 
- crc[3](%x)!= payload[length-1](%x) || 
- crc[2](%x)!= payload[length-2](%x) || 
- crc[1](%x)!= payload[length-3](%x) || 
- crc[0](%x)!= payload[length-4](%x)\n,
- crc[3], payload[length - 1],
- crc[2], payload[length - 2],
- crc[1], payload[length - 3],
- crc[0], payload[length - 4]));
+(rtw_wep_decrypt23a:icv CRC mismatch: 
+ actual: %08x, expected: %08x\n,
+ actual_crc, expected_crc));
res = _FAIL;
}
 
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 01/15] staging: rtl8723au: Reformat whitespace to increase readability

2015-03-28 Thread M. Vefa Bicakci
On 26/03/15 08:18 AM, Greg KH wrote:
 On Thu, Mar 19, 2015 at 12:39:04AM -0400, M. Vefa Bicakci wrote:
 Adjust the whitespace in the signature, local variable declaration and
 initialization parts of a number of functions to increase readability
 in rtl8723au's rtw_security.c.

 v2: Make sure that the arcfour_encrypt function's argument list is split
 according to the kernel code style.
 
 The v2 stuff here should go below the --- line, otherwise it will show
 up in the changelog :(
 
 Please fix these all up and resend.

Hello Greg,

Thank you for the review!

I have addressed your comment in my local repository and I hope to send the 4th
revision of the patches soon.

Thanks again,

Vefa
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 10/15] staging: rtl8723au: No spaces at the start of a line

2015-03-18 Thread M. Vefa Bicakci
Prior to this commit, a large block of constants used to represent
an AES S-box table were indented with spaces in rtl8723au's
rtw_security.c. Correct the checkpatch.pl warnings indicating that
spaces should not be used to indent lines:
WARNING: please, no spaces at the start of a line

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 140 +-
 1 file changed, 70 insertions(+), 70 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 0557a0df52..f8d0c0a63f 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -417,76 +417,76 @@ void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, 
u32 data_len,
 #define RC4_KEY_SIZE 16/* 128-bit RC4KEY (104 bits unknown) */
 
 /* 2-unsigned char by 2-unsigned char subset of the full AES S-box table */
-static const unsigned short Sbox1[2][256] =   /* Sbox for hash (can be in 
ROM) */
-{ {
-   0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
-   0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
-   0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B,
-   0x41EC, 0xB367, 0x5FFD, 0x45EA, 0x23BF, 0x53F7, 0xE496, 0x9B5B,
-   0x75C2, 0xE11C, 0x3DAE, 0x4C6A, 0x6C5A, 0x7E41, 0xF502, 0x834F,
-   0x685C, 0x51F4, 0xD134, 0xF908, 0xE293, 0xAB73, 0x6253, 0x2A3F,
-   0x080C, 0x9552, 0x4665, 0x9D5E, 0x3028, 0x37A1, 0x0A0F, 0x2FB5,
-   0x0E09, 0x2436, 0x1B9B, 0xDF3D, 0xCD26, 0x4E69, 0x7FCD, 0xEA9F,
-   0x121B, 0x1D9E, 0x5874, 0x342E, 0x362D, 0xDCB2, 0xB4EE, 0x5BFB,
-   0xA4F6, 0x764D, 0xB761, 0x7DCE, 0x527B, 0xDD3E, 0x5E71, 0x1397,
-   0xA6F5, 0xB968, 0x, 0xC12C, 0x4060, 0xE31F, 0x79C8, 0xB6ED,
-   0xD4BE, 0x8D46, 0x67D9, 0x724B, 0x94DE, 0x98D4, 0xB0E8, 0x854A,
-   0xBB6B, 0xC52A, 0x4FE5, 0xED16, 0x86C5, 0x9AD7, 0x6655, 0x1194,
-   0x8ACF, 0xE910, 0x0406, 0xFE81, 0xA0F0, 0x7844, 0x25BA, 0x4BE3,
-   0xA2F3, 0x5DFE, 0x80C0, 0x058A, 0x3FAD, 0x21BC, 0x7048, 0xF104,
-   0x63DF, 0x77C1, 0xAF75, 0x4263, 0x2030, 0xE51A, 0xFD0E, 0xBF6D,
-   0x814C, 0x1814, 0x2635, 0xC32F, 0xBEE1, 0x35A2, 0x88CC, 0x2E39,
-   0x9357, 0x55F2, 0xFC82, 0x7A47, 0xC8AC, 0xBAE7, 0x322B, 0xE695,
-   0xC0A0, 0x1998, 0x9ED1, 0xA37F, 0x4466, 0x547E, 0x3BAB, 0x0B83,
-   0x8CCA, 0xC729, 0x6BD3, 0x283C, 0xA779, 0xBCE2, 0x161D, 0xAD76,
-   0xDB3B, 0x6456, 0x744E, 0x141E, 0x92DB, 0x0C0A, 0x486C, 0xB8E4,
-   0x9F5D, 0xBD6E, 0x43EF, 0xC4A6, 0x39A8, 0x31A4, 0xD337, 0xF28B,
-   0xD532, 0x8B43, 0x6E59, 0xDAB7, 0x018C, 0xB164, 0x9CD2, 0x49E0,
-   0xD8B4, 0xACFA, 0xF307, 0xCF25, 0xCAAF, 0xF48E, 0x47E9, 0x1018,
-   0x6FD5, 0xF088, 0x4A6F, 0x5C72, 0x3824, 0x57F1, 0x73C7, 0x9751,
-   0xCB23, 0xA17C, 0xE89C, 0x3E21, 0x96DD, 0x61DC, 0x0D86, 0x0F85,
-   0xE090, 0x7C42, 0x71C4, 0xCCAA, 0x90D8, 0x0605, 0xF701, 0x1C12,
-   0xC2A3, 0x6A5F, 0xAEF9, 0x69D0, 0x1791, 0x9958, 0x3A27, 0x27B9,
-   0xD938, 0xEB13, 0x2BB3, 0x2233, 0xD2BB, 0xA970, 0x0789, 0x33A7,
-   0x2DB6, 0x3C22, 0x1592, 0xC920, 0x8749, 0xAAFF, 0x5078, 0xA57A,
-   0x038F, 0x59F8, 0x0980, 0x1A17, 0x65DA, 0xD731, 0x84C6, 0xD0B8,
-   0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A,
-  },
-
-  {  /* second half of table is unsigned char-reversed version of first! */
-   0xA5C6, 0x84F8, 0x99EE, 0x8DF6, 0x0DFF, 0xBDD6, 0xB1DE, 0x5491,
-   0x5060, 0x0302, 0xA9CE, 0x7D56, 0x19E7, 0x62B5, 0xE64D, 0x9AEC,
-   0x458F, 0x9D1F, 0x4089, 0x87FA, 0x15EF, 0xEBB2, 0xC98E, 0x0BFB,
-   0xEC41, 0x67B3, 0xFD5F, 0xEA45, 0xBF23, 0xF753, 0x96E4, 0x5B9B,
-   0xC275, 0x1CE1, 0xAE3D, 0x6A4C, 0x5A6C, 0x417E, 0x02F5, 0x4F83,
-   0x5C68, 0xF451, 0x34D1, 0x08F9, 0x93E2, 0x73AB, 0x5362, 0x3F2A,
-   0x0C08, 0x5295, 0x6546, 0x5E9D, 0x2830, 0xA137, 0x0F0A, 0xB52F,
-   0x090E, 0x3624, 0x9B1B, 0x3DDF, 0x26CD, 0x694E, 0xCD7F, 0x9FEA,
-   0x1B12, 0x9E1D, 0x7458, 0x2E34, 0x2D36, 0xB2DC, 0xEEB4, 0xFB5B,
-   0xF6A4, 0x4D76, 0x61B7, 0xCE7D, 0x7B52, 0x3EDD, 0x715E, 0x9713,
-   0xF5A6, 0x68B9, 0x, 0x2CC1, 0x6040, 0x1FE3, 0xC879, 0xEDB6,
-   0xBED4, 0x468D, 0xD967, 0x4B72, 0xDE94, 0xD498, 0xE8B0, 0x4A85,
-   0x6BBB, 0x2AC5, 0xE54F, 0x16ED, 0xC586, 0xD79A, 0x5566, 0x9411,
-   0xCF8A, 0x10E9, 0x0604, 0x81FE, 0xF0A0, 0x4478, 0xBA25, 0xE34B,
-   0xF3A2, 0xFE5D, 0xC080, 0x8A05, 0xAD3F, 0xBC21, 0x4870, 0x04F1,
-   0xDF63, 0xC177, 0x75AF, 0x6342, 0x3020, 0x1AE5, 0x0EFD, 0x6DBF,
-   0x4C81, 0x1418, 0x3526, 0x2FC3, 0xE1BE, 0xA235, 0xCC88, 0x392E,
-   0x5793, 0xF255, 0x82FC, 0x477A, 0xACC8, 0xE7BA, 0x2B32, 0x95E6,
-   0xA0C0, 0x9819, 0xD19E, 0x7FA3, 0x6644, 0x7E54, 0xAB3B, 0x830B,
-   0xCA8C, 0x29C7, 0xD36B, 0x3C28, 0x79A7, 0xE2BC, 0x1D16, 0x76AD,
-   0x3BDB, 0x5664, 0x4E74, 0x1E14, 0xDB92, 0x0A0C, 0x6C48, 0xE4B8,
-   0x5D9F, 0x6EBD, 0xEF43, 0xA6C4, 0xA839, 0xA431, 0x37D3, 0x8BF2,
-   0x32D5, 0x438B, 0x596E, 0xB7DA, 0x8C01, 0x64B1, 0xD29C, 0xE049,
-   0xB4D8, 0xFAAC, 0x07F3, 0x25CF, 0xAFCA, 0x8EF4, 0xE947, 0x1810,
-   0xD56F, 0x88F0, 0x6F4A, 0x725C, 0x2438, 0xF157

[PATCH v3 00/15] checkpatch clean-up of rtl8723au's rtw_security.c

2015-03-18 Thread M. Vefa Bicakci
These commits address a number of checkpatch.pl warnings and errors
in rtl8723au's rtw_security.c.

Prior to this set of commits, checkpatch.pl reported the following:
total: 77 errors, 138 warnings, 1621 lines checked

After applying this set of commits, checkpatch.pl reports the following:
total: 0 errors, 26 warnings, 1624 lines checked
where the only remaining warnings relate to lines longer than 80
characters and quoted strings split across multiple lines.

There are also a number of commits which improve the code in other ways.
For example, the commit titled "Reorganize a few functions to remove
indentation" reworks two functions to make them more readable, whereas
the commit titled "Rework two byte array comparisons" reworks two CRC
verifications for the same reason, and "Use __func__ in trace logs"
avoids hardcoding function names in trace logs to increase
maintainability.

All of the commits have been verified to compile successfully via the
use of the interactive rebase feature of git.

v3: Rebased onto Greg Kroah-Hartman's staging-next tree, on top of
the following commit
  5ec293650827122df300581c17ca1d5de03bac3d.
  Staging: dgnc: release the lock before testing for nullity

Please see the individual commit messages for the changes
since v2. In summary, the following commits have been updated:
- that open brace should be on the previous line
- suspect code indent for conditional statements

The following commit is new:
- Use __func__ in trace logs

Finally, the following commit has been removed:
- Do not initialize a static to 0

v2: Please see the individual commit messages for the changes
since v1. In summary, the following commits have been updated:
- Reformat whitespace to increase readability
- Fix "before/around/after" whitespace issues
    - Rework two byte array comparisons

M. Vefa Bicakci (15):
  staging: rtl8723au: Reformat whitespace to increase readability
  staging: rtl8723au: Fix "before/around/after" whitespace issues
  staging: rtl8723au: else should follow close brace
  staging: rtl8723au: Fix the indentation of two lines
  staging: rtl8723au: Reorganize a few functions to remove indentation
  staging: rtl8723au: else is not generally useful after a return
  staging: rtl8723au: Remove unneeded curly braces
  staging: rtl8723au: trailing statements should be on next line
  staging: rtl8723au: that open brace should be on the previous line
  staging: rtl8723au: No spaces at the start of a line
  staging: rtl8723au: Adjust whitespace in and around comments
  staging: rtl8723au: suspect code indent for conditional statements
  staging: rtl8723au: Rework two byte array comparisons
  staging: rtl8723au: Use __func__ in trace logs
  staging: rtl8723au: Remove unneeded comments

 drivers/staging/rtl8723au/core/rtw_security.c | 799 +-
 1 file changed, 401 insertions(+), 398 deletions(-)

-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 04/15] staging: rtl8723au: Fix the indentation of two lines

2015-03-18 Thread M. Vefa Bicakci
Correct the indentation of two lines in rtw_tkip_encrypt23a function in
rtl8723au's rtw_security.c.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index 17234e0bf1..df1787f20e 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -679,8 +679,8 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
arcfour_encrypt(, payload, 
payload, length);
arcfour_encrypt(, 
payload+length, crc, 4);
 
-   pframe += pxmitpriv->frag_len;
-   pframe  = PTR_ALIGN(pframe, 4);
+   pframe += pxmitpriv->frag_len;
+   pframe  = PTR_ALIGN(pframe, 4);
}
}
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 05/15] staging: rtl8723au: Reorganize a few functions to remove indentation

2015-03-18 Thread M. Vefa Bicakci
Prior to this commit, functions rtw_tkip_encrypt23a and rtw_tkip_decrypt23a had
large if blocks which contained the majority of the logic in the functions.

Rework these functions so that if the negated version of the aforementioned if
blocks' conditions are true, we return from the function with _FAIL, as
expected by the calling code.

This lets us remove two levels of indentation from the functions in
question, making them more readable.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 178 +-
 1 file changed, 88 insertions(+), 90 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index df1787f20e..f7b1d45981 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -618,6 +618,9 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
struct xmit_priv *pxmitpriv = >xmitpriv;
int res = _SUCCESS;
 
+   if (pattrib->encrypt != WLAN_CIPHER_SUITE_TKIP)
+   return _FAIL;
+
if (!pxmitframe->buf_addr)
return _FAIL;
 
@@ -625,71 +628,66 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
 
pframe = pxmitframe->buf_addr + hw_hdr_offset;
/* 4 start to encrypt each fragment */
-   if (pattrib->encrypt == WLAN_CIPHER_SUITE_TKIP) {
-   if (pattrib->psta)
-   stainfo = pattrib->psta;
-   else {
-   DBG_8723A("%s, call rtw_get_stainfo()\n", __func__);
-   stainfo = rtw_get_stainfo23a(>stapriv,
->ra[0]);
-   }
-
-   if (stainfo != NULL) {
-
-   if (!(stainfo->state & _FW_LINKED)) {
-   DBG_8723A("%s, psta->state(0x%x) != 
_FW_LINKED\n", __func__, stainfo->state);
-   return _FAIL;
-   }
+   if (pattrib->psta)
+   stainfo = pattrib->psta;
+   else {
+   DBG_8723A("%s, call rtw_get_stainfo()\n", __func__);
+   stainfo = rtw_get_stainfo23a(>stapriv,
+>ra[0]);
+   }
 
-   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
("rtw_tkip_encrypt23a: stainfo!= NULL!!!\n"));
+   if (stainfo == NULL) {
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, 
("rtw_tkip_encrypt23a: stainfo == NULL!!!\n"));
+   DBG_8723A("%s, psta == NUL\n", __func__);
+   return _FAIL;
+   }
 
-   if (is_multicast_ether_addr(pattrib->ra))
-   prwskey = 
psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey;
-   else
-   prwskey = >dot118021x_UncstKey.skey[0];
+   if (!(stainfo->state & _FW_LINKED)) {
+   DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, 
stainfo->state);
+   return _FAIL;
+   }
 
-   prwskeylen = 16;
+   RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("rtw_tkip_encrypt23a: 
stainfo!= NULL!!!\n"));
 
-   for (curfragnum = 0; curfragnum < pattrib->nr_frags; 
curfragnum++) {
-   iv = pframe+pattrib->hdrlen;
-   payload = 
pframe+pattrib->iv_len+pattrib->hdrlen;
+   if (is_multicast_ether_addr(pattrib->ra))
+   prwskey = 
psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey;
+   else
+   prwskey = >dot118021x_UncstKey.skey[0];
 
-   GET_TKIP_PN(iv, dot11txpn);
+   prwskeylen = 16;
 
-   pnl = (u16)(dot11txpn.val);
-   pnh = (u32)(dot11txpn.val>>16);
+   for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) {
+   iv = pframe+pattrib->hdrlen;
+   payload = pframe+pattrib->iv_len+pattrib->hdrlen;
 
-   phase1((u16 *)[0], prwskey, 
>ta[0], pnh);
+   GET_TKIP_PN(iv, dot11txpn);
 
-   phase2([0], prwskey, (u16 *)[0], 
pnl);
+   pnl = (u16)(dot11txpn.val);
+   pnh = (u32)(dot11txpn.val>>16);
 
-   if ((curfragnum + 1) == pattrib->nr_frags) {
/* 4 the last fragment */
-   length = 
pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len - pattrib->icv_len;
-   RT_TRACE(_module_rtl871x_security_c_, 
_drv_info_, ("pattrib->iv_l

[PATCH v3 06/15] staging: rtl8723au: else is not generally useful after a return

2015-03-18 Thread M. Vefa Bicakci
Correct a checkpatch.pl warning regarding rtl8723au's
rtw_security.c::crc32_init pointing out that having an else statement
after a break or a return is not useful.

drivers/staging/rtl8723au/core/rtw_security.c:105:
WARNING: else is not generally useful after a break or return

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 42 ++-
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index f7b1d45981..f7571cf091 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -99,31 +99,33 @@ static u8 crc32_reverseBit(u8 data)
 
 static void crc32_init(void)
 {
+   int i, j;
+   u32 c;
+   u8 *p, *p1;
+   u8 k;
 
if (bcrc32initialized == 1)
return;
-   else{
-   int i, j;
-   u32 c;
-   u8 *p = (u8 *), *p1;
-   u8 k;
-
-   c = 0x1234;
-
-   for (i = 0; i < 256; ++i) {
-   k = crc32_reverseBit((u8)i);
-   for (c = ((u32)k) << 24, j = 8; j > 0; --j) {
-   c = c & 0x8000 ? (c << 1) ^ CRC32_POLY : (c 
<< 1);
-   }
-   p1 = (u8 *)_table[i];
-
-   p1[0] = crc32_reverseBit(p[3]);
-   p1[1] = crc32_reverseBit(p[2]);
-   p1[2] = crc32_reverseBit(p[1]);
-   p1[3] = crc32_reverseBit(p[0]);
+
+   p = (u8 *) 
+   c = 0x1234;
+
+   for (i = 0; i < 256; ++i) {
+   k = crc32_reverseBit((u8)i);
+
+   for (c = ((u32)k) << 24, j = 8; j > 0; --j) {
+   c = c & 0x8000 ? (c << 1) ^ CRC32_POLY : (c << 1);
}
-   bcrc32initialized = 1;
+
+   p1 = (u8 *)_table[i];
+
+   p1[0] = crc32_reverseBit(p[3]);
+   p1[1] = crc32_reverseBit(p[2]);
+   p1[2] = crc32_reverseBit(p[1]);
+   p1[3] = crc32_reverseBit(p[0]);
}
+
+   bcrc32initialized = 1;
 }
 
 static u32 getcrc32(u8 *buf, int len)
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 15/15] staging: rtl8723au: Remove unneeded comments

2015-03-18 Thread M. Vefa Bicakci
This commit removes a number of unneeded comments. Two of the
aforementioned comments were most likely meant to aid with version
control, whereas the remaining two comments relate to (now unused)
local variable names.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/staging/rtl8723au/core/rtw_security.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_security.c 
b/drivers/staging/rtl8723au/core/rtw_security.c
index cdb3707fb2..309f3d969e 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -671,14 +671,14 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
if ((curfragnum+1) == pattrib->nr_frags) { /* 4 the last 
fragment */
length = 
pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len - pattrib->icv_len;
RT_TRACE(_module_rtl871x_security_c_, _drv_info_, 
("pattrib->iv_len =%x, pattrib->icv_len =%x\n", pattrib->iv_len, 
pattrib->icv_len));
-   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length)); 
/* modified by Amy */
+   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
 
arcfour_init(, rc4key, 16);
arcfour_encrypt(, payload, payload, length);
arcfour_encrypt(, payload+length, crc, 4);
} else {
length = 
pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
-   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length)); 
/* modified by Amy */
+   *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
arcfour_init(, rc4key, 16);
arcfour_encrypt(, payload, payload, length);
arcfour_encrypt(, payload+length, crc, 4);
@@ -1272,7 +1272,7 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
/* Intermediate Buffers */
int curfragnum, length;
u32 prwskeylen;
-   u8 *pframe, *prwskey; /* *payload, *iv */
+   u8 *pframe, *prwskey;
u8 hw_hdr_offset = 0;
struct sta_info *stainfo;
struct pkt_attrib *pattrib = >attrib;
@@ -1563,7 +1563,7 @@ int rtw_aes_decrypt23a(struct rtw_adapter *padapter,
struct security_priv *psecuritypriv = >securitypriv;
struct sk_buff *skb = precvframe->pkt;
int length;
-   u8 *pframe, *prwskey; /* *payload, *iv */
+   u8 *pframe, *prwskey;
int res = _SUCCESS;
 
pframe = skb->data;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


  1   2   3   >