Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 13 Jan 2016 02:57:02 +0000 (18:57 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 13 Jan 2016 02:57:02 +0000 (18:57 -0800)
Pull networking updates from Davic Miller:

 1) Support busy polling generically, for all NAPI drivers.  From Eric
    Dumazet.

 2) Add byte/packet counter support to nft_ct, from Floriani Westphal.

 3) Add RSS/XPS support to mvneta driver, from Gregory Clement.

 4) Implement IPV6_HDRINCL socket option for raw sockets, from Hannes
    Frederic Sowa.

 5) Add support for T6 adapter to cxgb4 driver, from Hariprasad Shenai.

 6) Add support for VLAN device bridging to mlxsw switch driver, from
    Ido Schimmel.

 7) Add driver for Netronome NFP4000/NFP6000, from Jakub Kicinski.

 8) Provide hwmon interface to mlxsw switch driver, from Jiri Pirko.

 9) Reorganize wireless drivers into per-vendor directories just like we
    do for ethernet drivers.  From Kalle Valo.

10) Provide a way for administrators "destroy" connected sockets via the
    SOCK_DESTROY socket netlink diag operation.  From Lorenzo Colitti.

11) Add support to add/remove multicast routes via netlink, from Nikolay
    Aleksandrov.

12) Make TCP keepalive settings per-namespace, from Nikolay Borisov.

13) Add forwarding and packet duplication facilities to nf_tables, from
    Pablo Neira Ayuso.

14) Dead route support in MPLS, from Roopa Prabhu.

15) TSO support for thunderx chips, from Sunil Goutham.

16) Add driver for IBM's System i/p VNIC protocol, from Thomas Falcon.

17) Rationalize, consolidate, and more completely document the checksum
    offloading facilities in the networking stack.  From Tom Herbert.

18) Support aborting an ongoing scan in mac80211/cfg80211, from
    Vidyullatha Kanchanapally.

19) Use per-bucket spinlock for bpf hash facility, from Tom Leiming.

* git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1375 commits)
  net: bnxt: always return values from _bnxt_get_max_rings
  net: bpf: reject invalid shifts
  phonet: properly unshare skbs in phonet_rcv()
  dwc_eth_qos: Fix dma address for multi-fragment skbs
  phy: remove an unneeded condition
  mdio: remove an unneed condition
  mdio_bus: NULL dereference on allocation error
  net: Fix typo in netdev_intersect_features
  net: freescale: mac-fec: Fix build error from phy_device API change
  net: freescale: ucc_geth: Fix build error from phy_device API change
  bonding: Prevent IPv6 link local address on enslaved devices
  IB/mlx5: Add flow steering support
  net/mlx5_core: Export flow steering API
  net/mlx5_core: Make ipv4/ipv6 location more clear
  net/mlx5_core: Enable flow steering support for the IB driver
  net/mlx5_core: Initialize namespaces only when supported by device
  net/mlx5_core: Set priority attributes
  net/mlx5_core: Connect flow tables
  net/mlx5_core: Introduce modify flow table command
  net/mlx5_core: Managing root flow table
  ...

1  2 
MAINTAINERS
crypto/algif_aead.c
crypto/algif_skcipher.c
drivers/net/wireless/marvell/libertas/debugfs.c
drivers/net/wireless/marvell/mwifiex/debugfs.c
drivers/net/wireless/ti/wlcore/debugfs.c
include/linux/sched.h
include/linux/wait.h
lib/Kconfig.debug

diff --cc MAINTAINERS
Simple merge
Simple merge
Simple merge
index 0000000000000000000000000000000000000000,26cbf1dcc6620f0502314daf8cac579794c8f6e4..faed1823c58ec2dfe0125038ff694bbb18842e5c
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,989 +1,936 @@@
 -      ssize_t buf_size, ret;
+ #include <linux/dcache.h>
+ #include <linux/debugfs.h>
+ #include <linux/delay.h>
+ #include <linux/hardirq.h>
+ #include <linux/mm.h>
+ #include <linux/string.h>
+ #include <linux/slab.h>
+ #include <linux/export.h>
+ #include "decl.h"
+ #include "cmd.h"
+ #include "debugfs.h"
+ static struct dentry *lbs_dir;
+ static char *szStates[] = {
+       "Connected",
+       "Disconnected"
+ };
+ #ifdef PROC_DEBUG
+ static void lbs_debug_init(struct lbs_private *priv);
+ #endif
+ static ssize_t write_file_dummy(struct file *file, const char __user *buf,
+                                 size_t count, loff_t *ppos)
+ {
+         return -EINVAL;
+ }
+ static const size_t len = PAGE_SIZE;
+ static ssize_t lbs_dev_info(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+ {
+       struct lbs_private *priv = file->private_data;
+       size_t pos = 0;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+       ssize_t res;
+       if (!buf)
+               return -ENOMEM;
+       pos += snprintf(buf+pos, len-pos, "state = %s\n",
+                               szStates[priv->connect_status]);
+       pos += snprintf(buf+pos, len-pos, "region_code = %02x\n",
+                               (u32) priv->regioncode);
+       res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+       free_page(addr);
+       return res;
+ }
+ static ssize_t lbs_sleepparams_write(struct file *file,
+                               const char __user *user_buf, size_t count,
+                               loff_t *ppos)
+ {
+       struct lbs_private *priv = file->private_data;
 -      unsigned long addr = get_zeroed_page(GFP_KERNEL);
 -      char *buf = (char *)addr;
 -      if (!buf)
 -              return -ENOMEM;
++      ssize_t ret;
+       struct sleep_params sp;
+       int p1, p2, p3, p4, p5, p6;
 -      buf_size = min(count, len - 1);
 -      if (copy_from_user(buf, user_buf, buf_size)) {
 -              ret = -EFAULT;
 -              goto out_unlock;
 -      }
++      char *buf;
++
++      buf = memdup_user_nul(user_buf, min(count, len - 1));
++      if (IS_ERR(buf))
++              return PTR_ERR(buf);
 -      free_page(addr);
+       ret = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6);
+       if (ret != 6) {
+               ret = -EINVAL;
+               goto out_unlock;
+       }
+       sp.sp_error = p1;
+       sp.sp_offset = p2;
+       sp.sp_stabletime = p3;
+       sp.sp_calcontrol = p4;
+       sp.sp_extsleepclk = p5;
+       sp.sp_reserved = p6;
+       ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_SET, &sp);
+       if (!ret)
+               ret = count;
+       else if (ret > 0)
+               ret = -EINVAL;
+ out_unlock:
 -      ssize_t buf_size, ret;
++      kfree(buf);
+       return ret;
+ }
+ static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+ {
+       struct lbs_private *priv = file->private_data;
+       ssize_t ret;
+       size_t pos = 0;
+       struct sleep_params sp;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+       if (!buf)
+               return -ENOMEM;
+       ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_GET, &sp);
+       if (ret)
+               goto out_unlock;
+       pos += snprintf(buf, len, "%d %d %d %d %d %d\n", sp.sp_error,
+                       sp.sp_offset, sp.sp_stabletime,
+                       sp.sp_calcontrol, sp.sp_extsleepclk,
+                       sp.sp_reserved);
+       ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+ out_unlock:
+       free_page(addr);
+       return ret;
+ }
+ static ssize_t lbs_host_sleep_write(struct file *file,
+                               const char __user *user_buf, size_t count,
+                               loff_t *ppos)
+ {
+       struct lbs_private *priv = file->private_data;
 -      unsigned long addr = get_zeroed_page(GFP_KERNEL);
 -      char *buf = (char *)addr;
 -      if (!buf)
 -              return -ENOMEM;
++      ssize_t ret;
+       int host_sleep;
 -      buf_size = min(count, len - 1);
 -      if (copy_from_user(buf, user_buf, buf_size)) {
 -              ret = -EFAULT;
 -              goto out_unlock;
 -      }
++      char *buf;
++
++      buf = memdup_user_nul(user_buf, min(count, len - 1));
++      if (IS_ERR(buf))
++              return PTR_ERR(buf);
 -      free_page(addr);
+       ret = sscanf(buf, "%d", &host_sleep);
+       if (ret != 1) {
+               ret = -EINVAL;
+               goto out_unlock;
+       }
+       if (host_sleep == 0)
+               ret = lbs_set_host_sleep(priv, 0);
+       else if (host_sleep == 1) {
+               if (priv->wol_criteria == EHS_REMOVE_WAKEUP) {
+                       netdev_info(priv->dev,
+                                   "wake parameters not configured\n");
+                       ret = -EINVAL;
+                       goto out_unlock;
+               }
+               ret = lbs_set_host_sleep(priv, 1);
+       } else {
+               netdev_err(priv->dev, "invalid option\n");
+               ret = -EINVAL;
+       }
+       if (!ret)
+               ret = count;
+ out_unlock:
 -      ssize_t buf_size;
++      kfree(buf);
+       return ret;
+ }
+ static ssize_t lbs_host_sleep_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+ {
+       struct lbs_private *priv = file->private_data;
+       ssize_t ret;
+       size_t pos = 0;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+       if (!buf)
+               return -ENOMEM;
+       pos += snprintf(buf, len, "%d\n", priv->is_host_sleep_activated);
+       ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+       free_page(addr);
+       return ret;
+ }
+ /*
+  * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
+  * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
+  * firmware. Here's an example:
+  *    04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
+  *    00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
+  *    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+  *
+  * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
+  * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
+  * defined in mrvlietypes_thresholds
+  *
+  * This function searches in this TLV data chunk for a given TLV type
+  * and returns a pointer to the first data byte of the TLV, or to NULL
+  * if the TLV hasn't been found.
+  */
+ static void *lbs_tlv_find(uint16_t tlv_type, const uint8_t *tlv, uint16_t size)
+ {
+       struct mrvl_ie_header *tlv_h;
+       uint16_t length;
+       ssize_t pos = 0;
+       while (pos < size) {
+               tlv_h = (struct mrvl_ie_header *) tlv;
+               if (!tlv_h->len)
+                       return NULL;
+               if (tlv_h->type == cpu_to_le16(tlv_type))
+                       return tlv_h;
+               length = le16_to_cpu(tlv_h->len) + sizeof(*tlv_h);
+               pos += length;
+               tlv += length;
+       }
+       return NULL;
+ }
+ static ssize_t lbs_threshold_read(uint16_t tlv_type, uint16_t event_mask,
+                                 struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+ {
+       struct cmd_ds_802_11_subscribe_event *subscribed;
+       struct mrvl_ie_thresholds *got;
+       struct lbs_private *priv = file->private_data;
+       ssize_t ret = 0;
+       size_t pos = 0;
+       char *buf;
+       u8 value;
+       u8 freq;
+       int events = 0;
+       buf = (char *)get_zeroed_page(GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+       subscribed = kzalloc(sizeof(*subscribed), GFP_KERNEL);
+       if (!subscribed) {
+               ret = -ENOMEM;
+               goto out_page;
+       }
+       subscribed->hdr.size = cpu_to_le16(sizeof(*subscribed));
+       subscribed->action = cpu_to_le16(CMD_ACT_GET);
+       ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, subscribed);
+       if (ret)
+               goto out_cmd;
+       got = lbs_tlv_find(tlv_type, subscribed->tlv, sizeof(subscribed->tlv));
+       if (got) {
+               value = got->value;
+               freq  = got->freq;
+               events = le16_to_cpu(subscribed->events);
+               pos += snprintf(buf, len, "%d %d %d\n", value, freq,
+                               !!(events & event_mask));
+       }
+       ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+  out_cmd:
+       kfree(subscribed);
+  out_page:
+       free_page((unsigned long)buf);
+       return ret;
+ }
+ static ssize_t lbs_threshold_write(uint16_t tlv_type, uint16_t event_mask,
+                                  struct file *file,
+                                  const char __user *userbuf, size_t count,
+                                  loff_t *ppos)
+ {
+       struct cmd_ds_802_11_subscribe_event *events;
+       struct mrvl_ie_thresholds *tlv;
+       struct lbs_private *priv = file->private_data;
 -      buf = (char *)get_zeroed_page(GFP_KERNEL);
 -      if (!buf)
 -              return -ENOMEM;
+       int value, freq, new_mask;
+       uint16_t curr_mask;
+       char *buf;
+       int ret;
 -      buf_size = min(count, len - 1);
 -      if (copy_from_user(buf, userbuf, buf_size)) {
 -              ret = -EFAULT;
 -              goto out_page;
 -      }
++      buf = memdup_user_nul(userbuf, min(count, len - 1));
++      if (IS_ERR(buf))
++              return PTR_ERR(buf);
 -      free_page((unsigned long)buf);
+       ret = sscanf(buf, "%d %d %d", &value, &freq, &new_mask);
+       if (ret != 3) {
+               ret = -EINVAL;
+               goto out_page;
+       }
+       events = kzalloc(sizeof(*events), GFP_KERNEL);
+       if (!events) {
+               ret = -ENOMEM;
+               goto out_page;
+       }
+       events->hdr.size = cpu_to_le16(sizeof(*events));
+       events->action = cpu_to_le16(CMD_ACT_GET);
+       ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events);
+       if (ret)
+               goto out_events;
+       curr_mask = le16_to_cpu(events->events);
+       if (new_mask)
+               new_mask = curr_mask | event_mask;
+       else
+               new_mask = curr_mask & ~event_mask;
+       /* Now everything is set and we can send stuff down to the firmware */
+       tlv = (void *)events->tlv;
+       events->action = cpu_to_le16(CMD_ACT_SET);
+       events->events = cpu_to_le16(new_mask);
+       tlv->header.type = cpu_to_le16(tlv_type);
+       tlv->header.len = cpu_to_le16(sizeof(*tlv) - sizeof(tlv->header));
+       tlv->value = value;
+       if (tlv_type != TLV_TYPE_BCNMISS)
+               tlv->freq = freq;
+       /* The command header, the action, the event mask, and one TLV */
+       events->hdr.size = cpu_to_le16(sizeof(events->hdr) + 4 + sizeof(*tlv));
+       ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events);
+       if (!ret)
+               ret = count;
+  out_events:
+       kfree(events);
+  out_page:
 -      ssize_t res, buf_size;
 -      unsigned long addr = get_zeroed_page(GFP_KERNEL);
 -      char *buf = (char *)addr;
 -      if (!buf)
 -              return -ENOMEM;
++      kfree(buf);
+       return ret;
+ }
+ static ssize_t lbs_lowrssi_read(struct file *file, char __user *userbuf,
+                               size_t count, loff_t *ppos)
+ {
+       return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
+                                 file, userbuf, count, ppos);
+ }
+ static ssize_t lbs_lowrssi_write(struct file *file, const char __user *userbuf,
+                                size_t count, loff_t *ppos)
+ {
+       return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
+                                  file, userbuf, count, ppos);
+ }
+ static ssize_t lbs_lowsnr_read(struct file *file, char __user *userbuf,
+                              size_t count, loff_t *ppos)
+ {
+       return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
+                                 file, userbuf, count, ppos);
+ }
+ static ssize_t lbs_lowsnr_write(struct file *file, const char __user *userbuf,
+                               size_t count, loff_t *ppos)
+ {
+       return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
+                                  file, userbuf, count, ppos);
+ }
+ static ssize_t lbs_failcount_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+ {
+       return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
+                                 file, userbuf, count, ppos);
+ }
+ static ssize_t lbs_failcount_write(struct file *file, const char __user *userbuf,
+                                  size_t count, loff_t *ppos)
+ {
+       return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
+                                  file, userbuf, count, ppos);
+ }
+ static ssize_t lbs_highrssi_read(struct file *file, char __user *userbuf,
+                                size_t count, loff_t *ppos)
+ {
+       return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
+                                 file, userbuf, count, ppos);
+ }
+ static ssize_t lbs_highrssi_write(struct file *file, const char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+ {
+       return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
+                                  file, userbuf, count, ppos);
+ }
+ static ssize_t lbs_highsnr_read(struct file *file, char __user *userbuf,
+                               size_t count, loff_t *ppos)
+ {
+       return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
+                                 file, userbuf, count, ppos);
+ }
+ static ssize_t lbs_highsnr_write(struct file *file, const char __user *userbuf,
+                                size_t count, loff_t *ppos)
+ {
+       return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
+                                  file, userbuf, count, ppos);
+ }
+ static ssize_t lbs_bcnmiss_read(struct file *file, char __user *userbuf,
+                               size_t count, loff_t *ppos)
+ {
+       return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
+                                 file, userbuf, count, ppos);
+ }
+ static ssize_t lbs_bcnmiss_write(struct file *file, const char __user *userbuf,
+                                size_t count, loff_t *ppos)
+ {
+       return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
+                                  file, userbuf, count, ppos);
+ }
+ static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+ {
+       struct lbs_private *priv = file->private_data;
+       ssize_t pos = 0;
+       int ret;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+       u32 val = 0;
+       if (!buf)
+               return -ENOMEM;
+       ret = lbs_get_reg(priv, CMD_MAC_REG_ACCESS, priv->mac_offset, &val);
+       mdelay(10);
+       if (!ret) {
+               pos = snprintf(buf, len, "MAC[0x%x] = 0x%08x\n",
+                               priv->mac_offset, val);
+               ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+       }
+       free_page(addr);
+       return ret;
+ }
+ static ssize_t lbs_rdmac_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+ {
+       struct lbs_private *priv = file->private_data;
 -      buf_size = min(count, len - 1);
 -      if (copy_from_user(buf, userbuf, buf_size)) {
 -              res = -EFAULT;
 -              goto out_unlock;
 -      }
++      char *buf;
++
++      buf = memdup_user_nul(userbuf, min(count, len - 1));
++      if (IS_ERR(buf))
++              return PTR_ERR(buf);
 -      res = count;
 -out_unlock:
 -      free_page(addr);
 -      return res;
+       priv->mac_offset = simple_strtoul(buf, NULL, 16);
 -      ssize_t res, buf_size;
++      kfree(buf);
++      return count;
+ }
+ static ssize_t lbs_wrmac_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+ {
+       struct lbs_private *priv = file->private_data;
 -      unsigned long addr = get_zeroed_page(GFP_KERNEL);
 -      char *buf = (char *)addr;
 -      if (!buf)
 -              return -ENOMEM;
++      ssize_t res;
+       u32 offset, value;
 -      buf_size = min(count, len - 1);
 -      if (copy_from_user(buf, userbuf, buf_size)) {
 -              res = -EFAULT;
 -              goto out_unlock;
 -      }
++      char *buf;
++
++      buf = memdup_user_nul(userbuf, min(count, len - 1));
++      if (IS_ERR(buf))
++              return PTR_ERR(buf);
 -      free_page(addr);
+       res = sscanf(buf, "%x %x", &offset, &value);
+       if (res != 2) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       res = lbs_set_reg(priv, CMD_MAC_REG_ACCESS, offset, value);
+       mdelay(10);
+       if (!res)
+               res = count;
+ out_unlock:
 -      ssize_t res, buf_size;
 -      unsigned long addr = get_zeroed_page(GFP_KERNEL);
 -      char *buf = (char *)addr;
 -      if (!buf)
 -              return -ENOMEM;
++      kfree(buf);
+       return res;
+ }
+ static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+ {
+       struct lbs_private *priv = file->private_data;
+       ssize_t pos = 0;
+       int ret;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+       u32 val;
+       if (!buf)
+               return -ENOMEM;
+       ret = lbs_get_reg(priv, CMD_BBP_REG_ACCESS, priv->bbp_offset, &val);
+       mdelay(10);
+       if (!ret) {
+               pos = snprintf(buf, len, "BBP[0x%x] = 0x%08x\n",
+                               priv->bbp_offset, val);
+               ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+       }
+       free_page(addr);
+       return ret;
+ }
+ static ssize_t lbs_rdbbp_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+ {
+       struct lbs_private *priv = file->private_data;
 -      buf_size = min(count, len - 1);
 -      if (copy_from_user(buf, userbuf, buf_size)) {
 -              res = -EFAULT;
 -              goto out_unlock;
 -      }
++      char *buf;
++
++      buf = memdup_user_nul(userbuf, min(count, len - 1));
++      if (IS_ERR(buf))
++              return PTR_ERR(buf);
 -      res = count;
 -out_unlock:
 -      free_page(addr);
 -      return res;
+       priv->bbp_offset = simple_strtoul(buf, NULL, 16);
 -      ssize_t res, buf_size;
++      kfree(buf);
++
++      return count;
+ }
+ static ssize_t lbs_wrbbp_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+ {
+       struct lbs_private *priv = file->private_data;
 -      unsigned long addr = get_zeroed_page(GFP_KERNEL);
 -      char *buf = (char *)addr;
 -      if (!buf)
 -              return -ENOMEM;
++      ssize_t res;
+       u32 offset, value;
 -      buf_size = min(count, len - 1);
 -      if (copy_from_user(buf, userbuf, buf_size)) {
 -              res = -EFAULT;
 -              goto out_unlock;
 -      }
++      char *buf;
++
++      buf = memdup_user_nul(userbuf, min(count, len - 1));
++      if (IS_ERR(buf))
++              return PTR_ERR(buf);
 -      free_page(addr);
+       res = sscanf(buf, "%x %x", &offset, &value);
+       if (res != 2) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       res = lbs_set_reg(priv, CMD_BBP_REG_ACCESS, offset, value);
+       mdelay(10);
+       if (!res)
+               res = count;
+ out_unlock:
 -      ssize_t res, buf_size;
 -      unsigned long addr = get_zeroed_page(GFP_KERNEL);
 -      char *buf = (char *)addr;
 -      if (!buf)
 -              return -ENOMEM;
++      kfree(buf);
+       return res;
+ }
+ static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+ {
+       struct lbs_private *priv = file->private_data;
+       ssize_t pos = 0;
+       int ret;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+       u32 val;
+       if (!buf)
+               return -ENOMEM;
+       ret = lbs_get_reg(priv, CMD_RF_REG_ACCESS, priv->rf_offset, &val);
+       mdelay(10);
+       if (!ret) {
+               pos = snprintf(buf, len, "RF[0x%x] = 0x%08x\n",
+                               priv->rf_offset, val);
+               ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+       }
+       free_page(addr);
+       return ret;
+ }
+ static ssize_t lbs_rdrf_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+ {
+       struct lbs_private *priv = file->private_data;
 -      buf_size = min(count, len - 1);
 -      if (copy_from_user(buf, userbuf, buf_size)) {
 -              res = -EFAULT;
 -              goto out_unlock;
 -      }
++      char *buf;
++
++      buf = memdup_user_nul(userbuf, min(count, len - 1));
++      if (IS_ERR(buf))
++              return PTR_ERR(buf);
 -      res = count;
 -out_unlock:
 -      free_page(addr);
 -      return res;
+       priv->rf_offset = simple_strtoul(buf, NULL, 16);
 -      ssize_t res, buf_size;
++      kfree(buf);
++      return count;
+ }
+ static ssize_t lbs_wrrf_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+ {
+       struct lbs_private *priv = file->private_data;
 -      unsigned long addr = get_zeroed_page(GFP_KERNEL);
 -      char *buf = (char *)addr;
 -      if (!buf)
 -              return -ENOMEM;
++      ssize_t res;
+       u32 offset, value;
 -      buf_size = min(count, len - 1);
 -      if (copy_from_user(buf, userbuf, buf_size)) {
 -              res = -EFAULT;
 -              goto out_unlock;
 -      }
++      char *buf;
++
++      buf = memdup_user_nul(userbuf, min(count, len - 1));
++      if (IS_ERR(buf))
++              return PTR_ERR(buf);
 -      free_page(addr);
+       res = sscanf(buf, "%x %x", &offset, &value);
+       if (res != 2) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       res = lbs_set_reg(priv, CMD_RF_REG_ACCESS, offset, value);
+       mdelay(10);
+       if (!res)
+               res = count;
+ out_unlock:
 -      pdata = kmalloc(cnt + 1, GFP_KERNEL);
 -      if (pdata == NULL)
 -              return 0;
 -
 -      if (copy_from_user(pdata, buf, cnt)) {
 -              lbs_deb_debugfs("Copy from user failed\n");
 -              kfree(pdata);
 -              return 0;
 -      }
 -      pdata[cnt] = '\0';
++      kfree(buf);
+       return res;
+ }
+ #define FOPS(fread, fwrite) { \
+       .owner = THIS_MODULE, \
+       .open = simple_open, \
+       .read = (fread), \
+       .write = (fwrite), \
+       .llseek = generic_file_llseek, \
+ }
+ struct lbs_debugfs_files {
+       const char *name;
+       umode_t perm;
+       struct file_operations fops;
+ };
+ static const struct lbs_debugfs_files debugfs_files[] = {
+       { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
+       { "sleepparams", 0644, FOPS(lbs_sleepparams_read,
+                               lbs_sleepparams_write), },
+       { "hostsleep", 0644, FOPS(lbs_host_sleep_read,
+                               lbs_host_sleep_write), },
+ };
+ static const struct lbs_debugfs_files debugfs_events_files[] = {
+       {"low_rssi", 0644, FOPS(lbs_lowrssi_read,
+                               lbs_lowrssi_write), },
+       {"low_snr", 0644, FOPS(lbs_lowsnr_read,
+                               lbs_lowsnr_write), },
+       {"failure_count", 0644, FOPS(lbs_failcount_read,
+                               lbs_failcount_write), },
+       {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
+                               lbs_bcnmiss_write), },
+       {"high_rssi", 0644, FOPS(lbs_highrssi_read,
+                               lbs_highrssi_write), },
+       {"high_snr", 0644, FOPS(lbs_highsnr_read,
+                               lbs_highsnr_write), },
+ };
+ static const struct lbs_debugfs_files debugfs_regs_files[] = {
+       {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
+       {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
+       {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
+       {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
+       {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
+       {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
+ };
+ void lbs_debugfs_init(void)
+ {
+       if (!lbs_dir)
+               lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
+ }
+ void lbs_debugfs_remove(void)
+ {
+       debugfs_remove(lbs_dir);
+ }
+ void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
+ {
+       int i;
+       const struct lbs_debugfs_files *files;
+       if (!lbs_dir)
+               goto exit;
+       priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
+       if (!priv->debugfs_dir)
+               goto exit;
+       for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
+               files = &debugfs_files[i];
+               priv->debugfs_files[i] = debugfs_create_file(files->name,
+                                                            files->perm,
+                                                            priv->debugfs_dir,
+                                                            priv,
+                                                            &files->fops);
+       }
+       priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
+       if (!priv->events_dir)
+               goto exit;
+       for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
+               files = &debugfs_events_files[i];
+               priv->debugfs_events_files[i] = debugfs_create_file(files->name,
+                                                            files->perm,
+                                                            priv->events_dir,
+                                                            priv,
+                                                            &files->fops);
+       }
+       priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
+       if (!priv->regs_dir)
+               goto exit;
+       for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
+               files = &debugfs_regs_files[i];
+               priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
+                                                            files->perm,
+                                                            priv->regs_dir,
+                                                            priv,
+                                                            &files->fops);
+       }
+ #ifdef PROC_DEBUG
+       lbs_debug_init(priv);
+ #endif
+ exit:
+       return;
+ }
+ void lbs_debugfs_remove_one(struct lbs_private *priv)
+ {
+       int i;
+       for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
+               debugfs_remove(priv->debugfs_regs_files[i]);
+       debugfs_remove(priv->regs_dir);
+       for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
+               debugfs_remove(priv->debugfs_events_files[i]);
+       debugfs_remove(priv->events_dir);
+ #ifdef PROC_DEBUG
+       debugfs_remove(priv->debugfs_debug);
+ #endif
+       for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
+               debugfs_remove(priv->debugfs_files[i]);
+       debugfs_remove(priv->debugfs_dir);
+ }
+ /* debug entry */
+ #ifdef PROC_DEBUG
+ #define item_size(n)  (FIELD_SIZEOF(struct lbs_private, n))
+ #define item_addr(n)  (offsetof(struct lbs_private, n))
+ struct debug_data {
+       char name[32];
+       u32 size;
+       size_t addr;
+ };
+ /* To debug any member of struct lbs_private, simply add one line here.
+  */
+ static struct debug_data items[] = {
+       {"psmode", item_size(psmode), item_addr(psmode)},
+       {"psstate", item_size(psstate), item_addr(psstate)},
+ };
+ static int num_of_items = ARRAY_SIZE(items);
+ /**
+  * lbs_debugfs_read - proc read function
+  *
+  * @file:     file to read
+  * @userbuf:  pointer to buffer
+  * @count:    number of bytes to read
+  * @ppos:     read data starting position
+  *
+  * returns:   amount of data read or negative error code
+  */
+ static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
+                       size_t count, loff_t *ppos)
+ {
+       int val = 0;
+       size_t pos = 0;
+       ssize_t res;
+       char *p;
+       int i;
+       struct debug_data *d;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+       if (!buf)
+               return -ENOMEM;
+       p = buf;
+       d = file->private_data;
+       for (i = 0; i < num_of_items; i++) {
+               if (d[i].size == 1)
+                       val = *((u8 *) d[i].addr);
+               else if (d[i].size == 2)
+                       val = *((u16 *) d[i].addr);
+               else if (d[i].size == 4)
+                       val = *((u32 *) d[i].addr);
+               else if (d[i].size == 8)
+                       val = *((u64 *) d[i].addr);
+               pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
+       }
+       res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
+       free_page(addr);
+       return res;
+ }
+ /**
+  * lbs_debugfs_write - proc write function
+  *
+  * @f:                file pointer
+  * @buf:      pointer to data buffer
+  * @cnt:      data number to write
+  * @ppos:     file position
+  *
+  * returns:   amount of data written
+  */
+ static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
+                           size_t cnt, loff_t *ppos)
+ {
+       int r, i;
+       char *pdata;
+       char *p;
+       char *p0;
+       char *p1;
+       char *p2;
+       struct debug_data *d = f->private_data;
+       if (cnt == 0)
+               return 0;
++      pdata = memdup_user_nul(buf, cnt);
++      if (IS_ERR(pdata))
++              return PTR_ERR(pdata);
+       p0 = pdata;
+       for (i = 0; i < num_of_items; i++) {
+               do {
+                       p = strstr(p0, d[i].name);
+                       if (p == NULL)
+                               break;
+                       p1 = strchr(p, '\n');
+                       if (p1 == NULL)
+                               break;
+                       p0 = p1++;
+                       p2 = strchr(p, '=');
+                       if (!p2)
+                               break;
+                       p2++;
+                       r = simple_strtoul(p2, NULL, 0);
+                       if (d[i].size == 1)
+                               *((u8 *) d[i].addr) = (u8) r;
+                       else if (d[i].size == 2)
+                               *((u16 *) d[i].addr) = (u16) r;
+                       else if (d[i].size == 4)
+                               *((u32 *) d[i].addr) = (u32) r;
+                       else if (d[i].size == 8)
+                               *((u64 *) d[i].addr) = (u64) r;
+                       break;
+               } while (1);
+       }
+       kfree(pdata);
+       return (ssize_t)cnt;
+ }
+ static const struct file_operations lbs_debug_fops = {
+       .owner = THIS_MODULE,
+       .open = simple_open,
+       .write = lbs_debugfs_write,
+       .read = lbs_debugfs_read,
+       .llseek = default_llseek,
+ };
+ /**
+  * lbs_debug_init - create debug proc file
+  *
+  * @priv:     pointer to &struct lbs_private
+  *
+  * returns:   N/A
+  */
+ static void lbs_debug_init(struct lbs_private *priv)
+ {
+       int i;
+       if (!priv->debugfs_dir)
+               return;
+       for (i = 0; i < num_of_items; i++)
+               items[i].addr += (size_t) priv;
+       priv->debugfs_debug = debugfs_create_file("debug", 0644,
+                                                 priv->debugfs_dir, &items[0],
+                                                 &lbs_debug_fops);
+ }
+ #endif
index 0000000000000000000000000000000000000000,5e5562909d9f1edfb3c62e173fac9e6a6b0f3ccc..0b9c580af988cd502e4ab4b05c351ffc030935ab
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,1035 +1,1003 @@@
 -      unsigned long addr = get_zeroed_page(GFP_KERNEL);
 -      char *buf = (char *) addr;
 -      size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
+ /*
+  * Marvell Wireless LAN device driver: debugfs
+  *
+  * Copyright (C) 2011-2014, Marvell International Ltd.
+  *
+  * This software file (the "File") is distributed by Marvell International
+  * Ltd. under the terms of the GNU General Public License Version 2, June 1991
+  * (the "License").  You may use, redistribute and/or modify this File in
+  * accordance with the terms and conditions of the License, a copy of which
+  * is available by writing to the Free Software Foundation, Inc.,
+  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
+  * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+  *
+  * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
+  * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
+  * this warranty disclaimer.
+  */
+ #include <linux/debugfs.h>
+ #include "main.h"
+ #include "11n.h"
+ static struct dentry *mwifiex_dfs_dir;
+ static char *bss_modes[] = {
+       "UNSPECIFIED",
+       "ADHOC",
+       "STATION",
+       "AP",
+       "AP_VLAN",
+       "WDS",
+       "MONITOR",
+       "MESH_POINT",
+       "P2P_CLIENT",
+       "P2P_GO",
+       "P2P_DEVICE",
+ };
+ /*
+  * Proc info file read handler.
+  *
+  * This function is called when the 'info' file is opened for reading.
+  * It prints the following driver related information -
+  *      - Driver name
+  *      - Driver version
+  *      - Driver extended version
+  *      - Interface name
+  *      - BSS mode
+  *      - Media state (connected or disconnected)
+  *      - MAC address
+  *      - Total number of Tx bytes
+  *      - Total number of Rx bytes
+  *      - Total number of Tx packets
+  *      - Total number of Rx packets
+  *      - Total number of dropped Tx packets
+  *      - Total number of dropped Rx packets
+  *      - Total number of corrupted Tx packets
+  *      - Total number of corrupted Rx packets
+  *      - Carrier status (on or off)
+  *      - Tx queue status (started or stopped)
+  *
+  * For STA mode drivers, it also prints the following extra -
+  *      - ESSID
+  *      - BSSID
+  *      - Channel
+  *      - Region code
+  *      - Multicast count
+  *      - Multicast addresses
+  */
+ static ssize_t
+ mwifiex_info_read(struct file *file, char __user *ubuf,
+                 size_t count, loff_t *ppos)
+ {
+       struct mwifiex_private *priv =
+               (struct mwifiex_private *) file->private_data;
+       struct net_device *netdev = priv->netdev;
+       struct netdev_hw_addr *ha;
+       struct netdev_queue *txq;
+       unsigned long page = get_zeroed_page(GFP_KERNEL);
+       char *p = (char *) page, fmt[64];
+       struct mwifiex_bss_info info;
+       ssize_t ret;
+       int i = 0;
+       if (!p)
+               return -ENOMEM;
+       memset(&info, 0, sizeof(info));
+       ret = mwifiex_get_bss_info(priv, &info);
+       if (ret)
+               goto free_and_exit;
+       mwifiex_drv_get_driver_version(priv->adapter, fmt, sizeof(fmt) - 1);
+       if (!priv->version_str[0])
+               mwifiex_get_ver_ext(priv);
+       p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
+       p += sprintf(p, "driver_version = %s", fmt);
+       p += sprintf(p, "\nverext = %s", priv->version_str);
+       p += sprintf(p, "\ninterface_name=\"%s\"\n", netdev->name);
+       if (info.bss_mode >= ARRAY_SIZE(bss_modes))
+               p += sprintf(p, "bss_mode=\"%d\"\n", info.bss_mode);
+       else
+               p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
+       p += sprintf(p, "media_state=\"%s\"\n",
+                    (!priv->media_connected ? "Disconnected" : "Connected"));
+       p += sprintf(p, "mac_address=\"%pM\"\n", netdev->dev_addr);
+       if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) {
+               p += sprintf(p, "multicast_count=\"%d\"\n",
+                            netdev_mc_count(netdev));
+               p += sprintf(p, "essid=\"%s\"\n", info.ssid.ssid);
+               p += sprintf(p, "bssid=\"%pM\"\n", info.bssid);
+               p += sprintf(p, "channel=\"%d\"\n", (int) info.bss_chan);
+               p += sprintf(p, "country_code = \"%s\"\n", info.country_code);
+               netdev_for_each_mc_addr(ha, netdev)
+                       p += sprintf(p, "multicast_address[%d]=\"%pM\"\n",
+                                       i++, ha->addr);
+       }
+       p += sprintf(p, "num_tx_bytes = %lu\n", priv->stats.tx_bytes);
+       p += sprintf(p, "num_rx_bytes = %lu\n", priv->stats.rx_bytes);
+       p += sprintf(p, "num_tx_pkts = %lu\n", priv->stats.tx_packets);
+       p += sprintf(p, "num_rx_pkts = %lu\n", priv->stats.rx_packets);
+       p += sprintf(p, "num_tx_pkts_dropped = %lu\n", priv->stats.tx_dropped);
+       p += sprintf(p, "num_rx_pkts_dropped = %lu\n", priv->stats.rx_dropped);
+       p += sprintf(p, "num_tx_pkts_err = %lu\n", priv->stats.tx_errors);
+       p += sprintf(p, "num_rx_pkts_err = %lu\n", priv->stats.rx_errors);
+       p += sprintf(p, "carrier %s\n", ((netif_carrier_ok(priv->netdev))
+                                        ? "on" : "off"));
+       p += sprintf(p, "tx queue");
+       for (i = 0; i < netdev->num_tx_queues; i++) {
+               txq = netdev_get_tx_queue(netdev, i);
+               p += sprintf(p, " %d:%s", i, netif_tx_queue_stopped(txq) ?
+                            "stopped" : "started");
+       }
+       p += sprintf(p, "\n");
+       ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
+                                     (unsigned long) p - page);
+ free_and_exit:
+       free_page(page);
+       return ret;
+ }
+ /*
+  * Proc device dump read handler.
+  *
+  * This function is called when the 'device_dump' file is opened for
+  * reading.
+  * This function dumps driver information and firmware memory segments
+  * (ex. DTCM, ITCM, SQRAM etc.) for
+  * debugging.
+  */
+ static ssize_t
+ mwifiex_device_dump_read(struct file *file, char __user *ubuf,
+                        size_t count, loff_t *ppos)
+ {
+       struct mwifiex_private *priv = file->private_data;
+       if (!priv->adapter->if_ops.device_dump)
+               return -EIO;
+       priv->adapter->if_ops.device_dump(priv->adapter);
+       return 0;
+ }
+ /*
+  * Proc getlog file read handler.
+  *
+  * This function is called when the 'getlog' file is opened for reading
+  * It prints the following log information -
+  *      - Number of multicast Tx frames
+  *      - Number of failed packets
+  *      - Number of Tx retries
+  *      - Number of multicast Tx retries
+  *      - Number of duplicate frames
+  *      - Number of RTS successes
+  *      - Number of RTS failures
+  *      - Number of ACK failures
+  *      - Number of fragmented Rx frames
+  *      - Number of multicast Rx frames
+  *      - Number of FCS errors
+  *      - Number of Tx frames
+  *      - WEP ICV error counts
+  *      - Number of received beacons
+  *      - Number of missed beacons
+  */
+ static ssize_t
+ mwifiex_getlog_read(struct file *file, char __user *ubuf,
+                   size_t count, loff_t *ppos)
+ {
+       struct mwifiex_private *priv =
+               (struct mwifiex_private *) file->private_data;
+       unsigned long page = get_zeroed_page(GFP_KERNEL);
+       char *p = (char *) page;
+       ssize_t ret;
+       struct mwifiex_ds_get_stats stats;
+       if (!p)
+               return -ENOMEM;
+       memset(&stats, 0, sizeof(stats));
+       ret = mwifiex_get_stats_info(priv, &stats);
+       if (ret)
+               goto free_and_exit;
+       p += sprintf(p, "\n"
+                    "mcasttxframe     %u\n"
+                    "failed           %u\n"
+                    "retry            %u\n"
+                    "multiretry       %u\n"
+                    "framedup         %u\n"
+                    "rtssuccess       %u\n"
+                    "rtsfailure       %u\n"
+                    "ackfailure       %u\n"
+                    "rxfrag           %u\n"
+                    "mcastrxframe     %u\n"
+                    "fcserror         %u\n"
+                    "txframe          %u\n"
+                    "wepicverrcnt-1   %u\n"
+                    "wepicverrcnt-2   %u\n"
+                    "wepicverrcnt-3   %u\n"
+                    "wepicverrcnt-4   %u\n"
+                    "bcn_rcv_cnt   %u\n"
+                    "bcn_miss_cnt   %u\n",
+                    stats.mcast_tx_frame,
+                    stats.failed,
+                    stats.retry,
+                    stats.multi_retry,
+                    stats.frame_dup,
+                    stats.rts_success,
+                    stats.rts_failure,
+                    stats.ack_failure,
+                    stats.rx_frag,
+                    stats.mcast_rx_frame,
+                    stats.fcs_error,
+                    stats.tx_frame,
+                    stats.wep_icv_error[0],
+                    stats.wep_icv_error[1],
+                    stats.wep_icv_error[2],
+                    stats.wep_icv_error[3],
+                    stats.bcn_rcv_cnt,
+                    stats.bcn_miss_cnt);
+       ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
+                                     (unsigned long) p - page);
+ free_and_exit:
+       free_page(page);
+       return ret;
+ }
+ /* Sysfs histogram file read handler.
+  *
+  * This function is called when the 'histogram' file is opened for reading
+  * It prints the following histogram information -
+  *      - Number of histogram samples
+  *      - Receive packet number of each rx_rate
+  *      - Receive packet number of each snr
+  *      - Receive packet number of each nosie_flr
+  *      - Receive packet number of each signal streath
+  */
+ static ssize_t
+ mwifiex_histogram_read(struct file *file, char __user *ubuf,
+                      size_t count, loff_t *ppos)
+ {
+       struct mwifiex_private *priv =
+               (struct mwifiex_private *)file->private_data;
+       ssize_t ret;
+       struct mwifiex_histogram_data *phist_data;
+       int i, value;
+       unsigned long page = get_zeroed_page(GFP_KERNEL);
+       char *p = (char *)page;
+       if (!p)
+               return -ENOMEM;
+       if (!priv || !priv->hist_data)
+               return -EFAULT;
+       phist_data = priv->hist_data;
+       p += sprintf(p, "\n"
+                    "total samples = %d\n",
+                    atomic_read(&phist_data->num_samples));
+       p += sprintf(p, "rx rates (in Mbps): 0=1M   1=2M");
+       p += sprintf(p, "2=5.5M  3=11M   4=6M   5=9M  6=12M\n");
+       p += sprintf(p, "7=18M  8=24M  9=36M  10=48M  11=54M");
+       p += sprintf(p, "12-27=MCS0-15(BW20) 28-43=MCS0-15(BW40)\n");
+       if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) {
+               p += sprintf(p, "44-53=MCS0-9(VHT:BW20)");
+               p += sprintf(p, "54-63=MCS0-9(VHT:BW40)");
+               p += sprintf(p, "64-73=MCS0-9(VHT:BW80)\n\n");
+       } else {
+               p += sprintf(p, "\n");
+       }
+       for (i = 0; i < MWIFIEX_MAX_RX_RATES; i++) {
+               value = atomic_read(&phist_data->rx_rate[i]);
+               if (value)
+                       p += sprintf(p, "rx_rate[%02d] = %d\n", i, value);
+       }
+       if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) {
+               for (i = MWIFIEX_MAX_RX_RATES; i < MWIFIEX_MAX_AC_RX_RATES;
+                    i++) {
+                       value = atomic_read(&phist_data->rx_rate[i]);
+                       if (value)
+                               p += sprintf(p, "rx_rate[%02d] = %d\n",
+                                          i, value);
+               }
+       }
+       for (i = 0; i < MWIFIEX_MAX_SNR; i++) {
+               value =  atomic_read(&phist_data->snr[i]);
+               if (value)
+                       p += sprintf(p, "snr[%02ddB] = %d\n", i, value);
+       }
+       for (i = 0; i < MWIFIEX_MAX_NOISE_FLR; i++) {
+               value = atomic_read(&phist_data->noise_flr[i]);
+               if (value)
+                       p += sprintf(p, "noise_flr[-%02ddBm] = %d\n",
+                               (int)(i-128), value);
+       }
+       for (i = 0; i < MWIFIEX_MAX_SIG_STRENGTH; i++) {
+               value = atomic_read(&phist_data->sig_str[i]);
+               if (value)
+                       p += sprintf(p, "sig_strength[-%02ddBm] = %d\n",
+                               i, value);
+       }
+       ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page,
+                                     (unsigned long)p - page);
+       return ret;
+ }
+ static ssize_t
+ mwifiex_histogram_write(struct file *file, const char __user *ubuf,
+                       size_t count, loff_t *ppos)
+ {
+       struct mwifiex_private *priv = (void *)file->private_data;
+       if (priv && priv->hist_data)
+               mwifiex_hist_data_reset(priv);
+       return 0;
+ }
+ static struct mwifiex_debug_info info;
+ /*
+  * Proc debug file read handler.
+  *
+  * This function is called when the 'debug' file is opened for reading
+  * It prints the following log information -
+  *      - Interrupt count
+  *      - WMM AC VO packets count
+  *      - WMM AC VI packets count
+  *      - WMM AC BE packets count
+  *      - WMM AC BK packets count
+  *      - Maximum Tx buffer size
+  *      - Tx buffer size
+  *      - Current Tx buffer size
+  *      - Power Save mode
+  *      - Power Save state
+  *      - Deep Sleep status
+  *      - Device wakeup required status
+  *      - Number of wakeup tries
+  *      - Host Sleep configured status
+  *      - Host Sleep activated status
+  *      - Number of Tx timeouts
+  *      - Number of command timeouts
+  *      - Last timed out command ID
+  *      - Last timed out command action
+  *      - Last command ID
+  *      - Last command action
+  *      - Last command index
+  *      - Last command response ID
+  *      - Last command response index
+  *      - Last event
+  *      - Last event index
+  *      - Number of host to card command failures
+  *      - Number of sleep confirm command failures
+  *      - Number of host to card data failure
+  *      - Number of deauthentication events
+  *      - Number of disassociation events
+  *      - Number of link lost events
+  *      - Number of deauthentication commands
+  *      - Number of association success commands
+  *      - Number of association failure commands
+  *      - Number of commands sent
+  *      - Number of data packets sent
+  *      - Number of command responses received
+  *      - Number of events received
+  *      - Tx BA stream table (TID, RA)
+  *      - Rx reorder table (TID, TA, Start window, Window size, Buffer)
+  */
+ static ssize_t
+ mwifiex_debug_read(struct file *file, char __user *ubuf,
+                  size_t count, loff_t *ppos)
+ {
+       struct mwifiex_private *priv =
+               (struct mwifiex_private *) file->private_data;
+       unsigned long page = get_zeroed_page(GFP_KERNEL);
+       char *p = (char *) page;
+       ssize_t ret;
+       if (!p)
+               return -ENOMEM;
+       ret = mwifiex_get_debug_info(priv, &info);
+       if (ret)
+               goto free_and_exit;
+       p += mwifiex_debug_info_to_buffer(priv, p, &info);
+       ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
+                                     (unsigned long) p - page);
+ free_and_exit:
+       free_page(page);
+       return ret;
+ }
+ static u32 saved_reg_type, saved_reg_offset, saved_reg_value;
+ /*
+  * Proc regrdwr file write handler.
+  *
+  * This function is called when the 'regrdwr' file is opened for writing
+  *
+  * This function can be used to write to a register.
+  */
+ static ssize_t
+ mwifiex_regrdwr_write(struct file *file,
+                     const char __user *ubuf, size_t count, loff_t *ppos)
+ {
 -      if (!buf)
 -              return -ENOMEM;
 -
 -
 -      if (copy_from_user(buf, ubuf, buf_size)) {
 -              ret = -EFAULT;
 -              goto done;
 -      }
++      char *buf;
+       int ret;
+       u32 reg_type = 0, reg_offset = 0, reg_value = UINT_MAX;
 -      free_page(addr);
++      buf = memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1)));
++      if (IS_ERR(buf))
++              return PTR_ERR(buf);
+       sscanf(buf, "%u %x %x", &reg_type, &reg_offset, &reg_value);
+       if (reg_type == 0 || reg_offset == 0) {
+               ret = -EINVAL;
+               goto done;
+       } else {
+               saved_reg_type = reg_type;
+               saved_reg_offset = reg_offset;
+               saved_reg_value = reg_value;
+               ret = count;
+       }
+ done:
 -      unsigned long addr = get_zeroed_page(GFP_KERNEL);
 -      char *buf = (void *)addr;
 -      size_t buf_size = min(count, (size_t)(PAGE_SIZE - 1));
++      kfree(buf);
+       return ret;
+ }
+ /*
+  * Proc regrdwr file read handler.
+  *
+  * This function is called when the 'regrdwr' file is opened for reading
+  *
+  * This function can be used to read from a register.
+  */
+ static ssize_t
+ mwifiex_regrdwr_read(struct file *file, char __user *ubuf,
+                    size_t count, loff_t *ppos)
+ {
+       struct mwifiex_private *priv =
+               (struct mwifiex_private *) file->private_data;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *) addr;
+       int pos = 0, ret = 0;
+       u32 reg_value;
+       if (!buf)
+               return -ENOMEM;
+       if (!saved_reg_type) {
+               /* No command has been given */
+               pos += snprintf(buf, PAGE_SIZE, "0");
+               goto done;
+       }
+       /* Set command has been given */
+       if (saved_reg_value != UINT_MAX) {
+               ret = mwifiex_reg_write(priv, saved_reg_type, saved_reg_offset,
+                                       saved_reg_value);
+               pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n",
+                               saved_reg_type, saved_reg_offset,
+                               saved_reg_value);
+               ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
+               goto done;
+       }
+       /* Get command has been given */
+       ret = mwifiex_reg_read(priv, saved_reg_type,
+                              saved_reg_offset, &reg_value);
+       if (ret) {
+               ret = -EINVAL;
+               goto done;
+       }
+       pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", saved_reg_type,
+                       saved_reg_offset, reg_value);
+       ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
+ done:
+       free_page(addr);
+       return ret;
+ }
+ /* Proc debug_mask file read handler.
+  * This function is called when the 'debug_mask' file is opened for reading
+  * This function can be used read driver debugging mask value.
+  */
+ static ssize_t
+ mwifiex_debug_mask_read(struct file *file, char __user *ubuf,
+                       size_t count, loff_t *ppos)
+ {
+       struct mwifiex_private *priv =
+               (struct mwifiex_private *)file->private_data;
+       unsigned long page = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)page;
+       size_t ret = 0;
+       int pos = 0;
+       if (!buf)
+               return -ENOMEM;
+       pos += snprintf(buf, PAGE_SIZE, "debug mask=0x%08x\n",
+                       priv->adapter->debug_mask);
+       ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
+       free_page(page);
+       return ret;
+ }
+ /* Proc debug_mask file read handler.
+  * This function is called when the 'debug_mask' file is opened for reading
+  * This function can be used read driver debugging mask value.
+  */
+ static ssize_t
+ mwifiex_debug_mask_write(struct file *file, const char __user *ubuf,
+                        size_t count, loff_t *ppos)
+ {
+       int ret;
+       unsigned long debug_mask;
+       struct mwifiex_private *priv = (void *)file->private_data;
 -      if (!buf)
 -              return -ENOMEM;
 -
 -      if (copy_from_user(buf, ubuf, buf_size)) {
 -              ret = -EFAULT;
 -              goto done;
 -      }
++      char *buf;
 -      free_page(addr);
++      buf = memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1)));
++      if (IS_ERR(buf))
++              return PTR_ERR(buf);
+       if (kstrtoul(buf, 0, &debug_mask)) {
+               ret = -EINVAL;
+               goto done;
+       }
+       priv->adapter->debug_mask = debug_mask;
+       ret = count;
+ done:
 -      unsigned long addr = get_zeroed_page(GFP_KERNEL);
 -      char *buf = (void *)addr;
 -      size_t buf_size = min(count, (size_t)(PAGE_SIZE - 1));
 -
 -      if (!buf)
 -              return -ENOMEM;
++      kfree(buf);
+       return ret;
+ }
+ /* Proc memrw file write handler.
+  * This function is called when the 'memrw' file is opened for writing
+  * This function can be used to write to a memory location.
+  */
+ static ssize_t
+ mwifiex_memrw_write(struct file *file, const char __user *ubuf, size_t count,
+                   loff_t *ppos)
+ {
+       int ret;
+       char cmd;
+       struct mwifiex_ds_mem_rw mem_rw;
+       u16 cmd_action;
+       struct mwifiex_private *priv = (void *)file->private_data;
 -      if (copy_from_user(buf, ubuf, buf_size)) {
 -              ret = -EFAULT;
 -              goto done;
 -      }
++      char *buf;
 -      free_page(addr);
++      buf = memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1)));
++      if (IS_ERR(buf))
++              return PTR_ERR(buf);
+       ret = sscanf(buf, "%c %x %x", &cmd, &mem_rw.addr, &mem_rw.value);
+       if (ret != 3) {
+               ret = -EINVAL;
+               goto done;
+       }
+       if ((cmd == 'r') || (cmd == 'R')) {
+               cmd_action = HostCmd_ACT_GEN_GET;
+               mem_rw.value = 0;
+       } else if ((cmd == 'w') || (cmd == 'W')) {
+               cmd_action = HostCmd_ACT_GEN_SET;
+       } else {
+               ret = -EINVAL;
+               goto done;
+       }
+       memcpy(&priv->mem_rw, &mem_rw, sizeof(mem_rw));
+       if (mwifiex_send_cmd(priv, HostCmd_CMD_MEM_ACCESS, cmd_action, 0,
+                            &mem_rw, true))
+               ret = -1;
+       else
+               ret = count;
+ done:
 -      unsigned long addr = get_zeroed_page(GFP_KERNEL);
 -      char *buf = (char *) addr;
 -      size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
++      kfree(buf);
+       return ret;
+ }
+ /* Proc memrw file read handler.
+  * This function is called when the 'memrw' file is opened for reading
+  * This function can be used to read from a memory location.
+  */
+ static ssize_t
+ mwifiex_memrw_read(struct file *file, char __user *ubuf,
+                  size_t count, loff_t *ppos)
+ {
+       struct mwifiex_private *priv = (void *)file->private_data;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+       int ret, pos = 0;
+       if (!buf)
+               return -ENOMEM;
+       pos += snprintf(buf, PAGE_SIZE, "0x%x 0x%x\n", priv->mem_rw.addr,
+                       priv->mem_rw.value);
+       ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
+       free_page(addr);
+       return ret;
+ }
+ static u32 saved_offset = -1, saved_bytes = -1;
+ /*
+  * Proc rdeeprom file write handler.
+  *
+  * This function is called when the 'rdeeprom' file is opened for writing
+  *
+  * This function can be used to write to a RDEEPROM location.
+  */
+ static ssize_t
+ mwifiex_rdeeprom_write(struct file *file,
+                      const char __user *ubuf, size_t count, loff_t *ppos)
+ {
 -      if (!buf)
 -              return -ENOMEM;
 -
 -
 -      if (copy_from_user(buf, ubuf, buf_size)) {
 -              ret = -EFAULT;
 -              goto done;
 -      }
++      char *buf;
+       int ret = 0;
+       int offset = -1, bytes = -1;
 -      free_page(addr);
++      buf = memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1)));
++      if (IS_ERR(buf))
++              return PTR_ERR(buf);
+       sscanf(buf, "%d %d", &offset, &bytes);
+       if (offset == -1 || bytes == -1) {
+               ret = -EINVAL;
+               goto done;
+       } else {
+               saved_offset = offset;
+               saved_bytes = bytes;
+               ret = count;
+       }
+ done:
 -      unsigned long addr = get_zeroed_page(GFP_KERNEL);
 -      char *buf = (char *)addr;
 -      size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
++      kfree(buf);
+       return ret;
+ }
+ /*
+  * Proc rdeeprom read write handler.
+  *
+  * This function is called when the 'rdeeprom' file is opened for reading
+  *
+  * This function can be used to read from a RDEEPROM location.
+  */
+ static ssize_t
+ mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
+                     size_t count, loff_t *ppos)
+ {
+       struct mwifiex_private *priv =
+               (struct mwifiex_private *) file->private_data;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *) addr;
+       int pos, ret, i;
+       u8 value[MAX_EEPROM_DATA];
+       if (!buf)
+               return -ENOMEM;
+       if (saved_offset == -1) {
+               /* No command has been given */
+               pos = snprintf(buf, PAGE_SIZE, "0");
+               goto done;
+       }
+       /* Get command has been given */
+       ret = mwifiex_eeprom_read(priv, (u16) saved_offset,
+                                 (u16) saved_bytes, value);
+       if (ret) {
+               ret = -EINVAL;
+               goto out_free;
+       }
+       pos = snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
+       for (i = 0; i < saved_bytes; i++)
+               pos += scnprintf(buf + pos, PAGE_SIZE - pos, "%d ", value[i]);
+ done:
+       ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
+ out_free:
+       free_page(addr);
+       return ret;
+ }
+ /* Proc hscfg file write handler
+  * This function can be used to configure the host sleep parameters.
+  */
+ static ssize_t
+ mwifiex_hscfg_write(struct file *file, const char __user *ubuf,
+                   size_t count, loff_t *ppos)
+ {
+       struct mwifiex_private *priv = (void *)file->private_data;
 -      if (!buf)
 -              return -ENOMEM;
 -
 -      if (copy_from_user(buf, ubuf, buf_size)) {
 -              ret = -EFAULT;
 -              goto done;
 -      }
++      char *buf;
+       int ret, arg_num;
+       struct mwifiex_ds_hs_cfg hscfg;
+       int conditions = HS_CFG_COND_DEF;
+       u32 gpio = HS_CFG_GPIO_DEF, gap = HS_CFG_GAP_DEF;
 -      free_page(addr);
++      buf = memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1)));
++      if (IS_ERR(buf))
++              return PTR_ERR(buf);
+       arg_num = sscanf(buf, "%d %x %x", &conditions, &gpio, &gap);
+       memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
+       if (arg_num > 3) {
+               mwifiex_dbg(priv->adapter, ERROR,
+                           "Too many arguments\n");
+               ret = -EINVAL;
+               goto done;
+       }
+       if (arg_num >= 1 && arg_num < 3)
+               mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_GET,
+                                     MWIFIEX_SYNC_CMD, &hscfg);
+       if (arg_num) {
+               if (conditions == HS_CFG_CANCEL) {
+                       mwifiex_cancel_hs(priv, MWIFIEX_ASYNC_CMD);
+                       ret = count;
+                       goto done;
+               }
+               hscfg.conditions = conditions;
+       }
+       if (arg_num >= 2)
+               hscfg.gpio = gpio;
+       if (arg_num == 3)
+               hscfg.gap = gap;
+       hscfg.is_invoke_hostcmd = false;
+       mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
+                             MWIFIEX_SYNC_CMD, &hscfg);
+       mwifiex_enable_hs(priv->adapter);
+       priv->adapter->hs_enabling = false;
+       ret = count;
+ done:
++      kfree(buf);
+       return ret;
+ }
+ /* Proc hscfg file read handler
+  * This function can be used to read host sleep configuration
+  * parameters from driver.
+  */
+ static ssize_t
+ mwifiex_hscfg_read(struct file *file, char __user *ubuf,
+                  size_t count, loff_t *ppos)
+ {
+       struct mwifiex_private *priv = (void *)file->private_data;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+       int pos, ret;
+       struct mwifiex_ds_hs_cfg hscfg;
+       if (!buf)
+               return -ENOMEM;
+       mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_GET,
+                             MWIFIEX_SYNC_CMD, &hscfg);
+       pos = snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", hscfg.conditions,
+                      hscfg.gpio, hscfg.gap);
+       ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
+       free_page(addr);
+       return ret;
+ }
+ static ssize_t
+ mwifiex_timeshare_coex_read(struct file *file, char __user *ubuf,
+                           size_t count, loff_t *ppos)
+ {
+       struct mwifiex_private *priv = file->private_data;
+       char buf[3];
+       bool timeshare_coex;
+       int ret;
+       unsigned int len;
+       if (priv->adapter->fw_api_ver != MWIFIEX_FW_V15)
+               return -EOPNOTSUPP;
+       ret = mwifiex_send_cmd(priv, HostCmd_CMD_ROBUST_COEX,
+                              HostCmd_ACT_GEN_GET, 0, &timeshare_coex, true);
+       if (ret)
+               return ret;
+       len = sprintf(buf, "%d\n", timeshare_coex);
+       return simple_read_from_buffer(ubuf, count, ppos, buf, len);
+ }
+ static ssize_t
+ mwifiex_timeshare_coex_write(struct file *file, const char __user *ubuf,
+                            size_t count, loff_t *ppos)
+ {
+       bool timeshare_coex;
+       struct mwifiex_private *priv = file->private_data;
+       char kbuf[16];
+       int ret;
+       if (priv->adapter->fw_api_ver != MWIFIEX_FW_V15)
+               return -EOPNOTSUPP;
+       memset(kbuf, 0, sizeof(kbuf));
+       if (copy_from_user(&kbuf, ubuf, min_t(size_t, sizeof(kbuf) - 1, count)))
+               return -EFAULT;
+       if (strtobool(kbuf, &timeshare_coex))
+               return -EINVAL;
+       ret = mwifiex_send_cmd(priv, HostCmd_CMD_ROBUST_COEX,
+                              HostCmd_ACT_GEN_SET, 0, &timeshare_coex, true);
+       if (ret)
+               return ret;
+       else
+               return count;
+ }
+ static ssize_t
+ mwifiex_reset_write(struct file *file,
+                   const char __user *ubuf, size_t count, loff_t *ppos)
+ {
+       struct mwifiex_private *priv = file->private_data;
+       struct mwifiex_adapter *adapter = priv->adapter;
+       char cmd;
+       bool result;
+       if (copy_from_user(&cmd, ubuf, sizeof(cmd)))
+               return -EFAULT;
+       if (strtobool(&cmd, &result))
+               return -EINVAL;
+       if (!result)
+               return -EINVAL;
+       if (adapter->if_ops.card_reset) {
+               dev_info(adapter->dev, "Resetting per request\n");
+               adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
+               mwifiex_cancel_all_pending_cmd(adapter);
+               adapter->if_ops.card_reset(adapter);
+       }
+       return count;
+ }
+ #define MWIFIEX_DFS_ADD_FILE(name) do {                                 \
+       if (!debugfs_create_file(#name, 0644, priv->dfs_dev_dir,        \
+                       priv, &mwifiex_dfs_##name##_fops))              \
+               return;                                                 \
+ } while (0);
+ #define MWIFIEX_DFS_FILE_OPS(name)                                      \
+ static const struct file_operations mwifiex_dfs_##name##_fops = {       \
+       .read = mwifiex_##name##_read,                                  \
+       .write = mwifiex_##name##_write,                                \
+       .open = simple_open,                                            \
+ };
+ #define MWIFIEX_DFS_FILE_READ_OPS(name)                                 \
+ static const struct file_operations mwifiex_dfs_##name##_fops = {       \
+       .read = mwifiex_##name##_read,                                  \
+       .open = simple_open,                                            \
+ };
+ #define MWIFIEX_DFS_FILE_WRITE_OPS(name)                                \
+ static const struct file_operations mwifiex_dfs_##name##_fops = {       \
+       .write = mwifiex_##name##_write,                                \
+       .open = simple_open,                                            \
+ };
+ MWIFIEX_DFS_FILE_READ_OPS(info);
+ MWIFIEX_DFS_FILE_READ_OPS(debug);
+ MWIFIEX_DFS_FILE_READ_OPS(getlog);
+ MWIFIEX_DFS_FILE_READ_OPS(device_dump);
+ MWIFIEX_DFS_FILE_OPS(regrdwr);
+ MWIFIEX_DFS_FILE_OPS(rdeeprom);
+ MWIFIEX_DFS_FILE_OPS(memrw);
+ MWIFIEX_DFS_FILE_OPS(hscfg);
+ MWIFIEX_DFS_FILE_OPS(histogram);
+ MWIFIEX_DFS_FILE_OPS(debug_mask);
+ MWIFIEX_DFS_FILE_OPS(timeshare_coex);
+ MWIFIEX_DFS_FILE_WRITE_OPS(reset);
+ /*
+  * This function creates the debug FS directory structure and the files.
+  */
+ void
+ mwifiex_dev_debugfs_init(struct mwifiex_private *priv)
+ {
+       if (!mwifiex_dfs_dir || !priv)
+               return;
+       priv->dfs_dev_dir = debugfs_create_dir(priv->netdev->name,
+                                              mwifiex_dfs_dir);
+       if (!priv->dfs_dev_dir)
+               return;
+       MWIFIEX_DFS_ADD_FILE(info);
+       MWIFIEX_DFS_ADD_FILE(debug);
+       MWIFIEX_DFS_ADD_FILE(getlog);
+       MWIFIEX_DFS_ADD_FILE(regrdwr);
+       MWIFIEX_DFS_ADD_FILE(rdeeprom);
+       MWIFIEX_DFS_ADD_FILE(device_dump);
+       MWIFIEX_DFS_ADD_FILE(memrw);
+       MWIFIEX_DFS_ADD_FILE(hscfg);
+       MWIFIEX_DFS_ADD_FILE(histogram);
+       MWIFIEX_DFS_ADD_FILE(debug_mask);
+       MWIFIEX_DFS_ADD_FILE(timeshare_coex);
+       MWIFIEX_DFS_ADD_FILE(reset);
+ }
+ /*
+  * This function removes the debug FS directory structure and the files.
+  */
+ void
+ mwifiex_dev_debugfs_remove(struct mwifiex_private *priv)
+ {
+       if (!priv)
+               return;
+       debugfs_remove_recursive(priv->dfs_dev_dir);
+ }
+ /*
+  * This function creates the top level proc directory.
+  */
+ void
+ mwifiex_debugfs_init(void)
+ {
+       if (!mwifiex_dfs_dir)
+               mwifiex_dfs_dir = debugfs_create_dir("mwifiex", NULL);
+ }
+ /*
+  * This function removes the top level proc directory.
+  */
+ void
+ mwifiex_debugfs_remove(void)
+ {
+       if (mwifiex_dfs_dir)
+               debugfs_remove(mwifiex_dfs_dir);
+ }
Simple merge
Simple merge
Simple merge