Passing uninitialised local variable

2018-03-28 Thread Himanshu Jha
Hello everyone,


I recently found that a local variable in passed uninitialised to the
function at 

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:2950

u32 var; 
err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var);
if (err) {
brcmf_err("wl dtim_assoc failed (%d)\n", err);
goto update_bss_info_out;
}
dtim_period = (u8)var;


Now, the brcmf_fil_iovar_int_get() is defined as:

s32
brcmf_fil_iovar_int_get(struct brcmf_if *ifp, char *name, u32 *data)
{
__le32 data_le = cpu_to_le32(*data);
s32 err;

err = brcmf_fil_iovar_data_get(ifp, name, &data_le, sizeof(data_le));
if (err == 0)
*data = le32_to_cpu(data_le);
return err;
}

We can cleary see that 'var' in used uninitialised in the very first line
which is an undefined behavior.

So, what could be a possible fix for the above ?

I'm not sure initialising 'var' to 0 would be the correct solution.

-- 
Thanks
Himanshu Jha


Re: [PATCH] drivers: net: wireless: ath: ath9: dfs: remove VLA usage

2018-03-09 Thread Himanshu Jha
On Fri, Mar 09, 2018 at 02:30:12PM +0200, Andreas Christoforou wrote:
> The kernel would like to have all stack VLA usage removed.
> 
> Signed-off-by: Andreas Christoforou 
> ---
>  drivers/net/wireless/ath/ath9k/dfs.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/ath/ath9k/dfs.c 
> b/drivers/net/wireless/ath/ath9k/dfs.c
> index 6fee9a4..cfb0f84 100644
> --- a/drivers/net/wireless/ath/ath9k/dfs.c
> +++ b/drivers/net/wireless/ath/ath9k/dfs.c
> @@ -41,7 +41,6 @@ static const int BIN_DELTA_MAX  = 10;
>  
>  /* we need at least 3 deltas / 4 samples for a reliable chirp detection */
>  #define NUM_DIFFS 3
> -static const int FFT_NUM_SAMPLES = (NUM_DIFFS + 1);

Are you sure it is correct ?
Look for other users of "FFT_NUM_SAMPLES".

>  /* Threshold for difference of delta peaks */
>  static const int MAX_DIFF= 2;
> @@ -101,7 +100,7 @@ static bool ath9k_check_chirping(struct ath_softc *sc, u8 
> *data,
>int datalen, bool is_ctl, bool is_ext)
>  {
>   int i;
> - int max_bin[FFT_NUM_SAMPLES];
> + int max_bin[NUM_DIFFS + 1];
>   struct ath_hw *ah = sc->sc_ah;
>   struct ath_common *common = ath9k_hw_common(ah);
>   int prev_delta;

Always compile test the driver before sending a patch.
Also, patch title seems incorrect *ath9k*

himanshu@himanshu-Vostro-3559:~/linux-next$ git log --oneline 
drivers/net/wireless/ath/ath9k/dfs.c
626ab67 ath9k: dfs: use swap macro in ath9k_check_chirping
50c8cd4 ath9k: remove cast to void pointer
8fc2b61 ath9k: DFS - add pulse chirp detection for FCC


-- 
Thanks
Himanshu Jha


[PATCH v2] brcmfmac: Use zeroing memory allocator than allocator/memset

2018-01-08 Thread Himanshu Jha
Use dma_zalloc_coherent for allocating zeroed
memory and remove unnecessary memset function.

Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci

Suggested-by: Luis R. Rodriguez 
Signed-off-by: Himanshu Jha 
---
v2:
   -corrected the patch to be applied into the branch without corruption
 .../net/wireless/broadcom/brcm80211/brcmfmac/pcie.c  | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c 
b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
index 3c87157..8752707 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
@@ -1251,14 +1251,14 @@ static int brcmf_pcie_init_scratchbuffers(struct 
brcmf_pciedev_info *devinfo)
u64 address;
u32 addr;
 
-   devinfo->shared.scratch = dma_alloc_coherent(&devinfo->pdev->dev,
-   BRCMF_DMA_D2H_SCRATCH_BUF_LEN,
-   &devinfo->shared.scratch_dmahandle, GFP_KERNEL);
+   devinfo->shared.scratch =
+   dma_zalloc_coherent(&devinfo->pdev->dev,
+   BRCMF_DMA_D2H_SCRATCH_BUF_LEN,
+   &devinfo->shared.scratch_dmahandle,
+   GFP_KERNEL);
if (!devinfo->shared.scratch)
goto fail;
 
-   memset(devinfo->shared.scratch, 0, BRCMF_DMA_D2H_SCRATCH_BUF_LEN);
-
addr = devinfo->shared.tcm_base_address +
   BRCMF_SHARED_DMA_SCRATCH_ADDR_OFFSET;
address = (u64)devinfo->shared.scratch_dmahandle;
@@ -1268,14 +1268,14 @@ static int brcmf_pcie_init_scratchbuffers(struct 
brcmf_pciedev_info *devinfo)
   BRCMF_SHARED_DMA_SCRATCH_LEN_OFFSET;
brcmf_pcie_write_tcm32(devinfo, addr, BRCMF_DMA_D2H_SCRATCH_BUF_LEN);
 
-   devinfo->shared.ringupd = dma_alloc_coherent(&devinfo->pdev->dev,
-   BRCMF_DMA_D2H_RINGUPD_BUF_LEN,
-   &devinfo->shared.ringupd_dmahandle, GFP_KERNEL);
+   devinfo->shared.ringupd =
+   dma_zalloc_coherent(&devinfo->pdev->dev,
+   BRCMF_DMA_D2H_RINGUPD_BUF_LEN,
+   &devinfo->shared.ringupd_dmahandle,
+   GFP_KERNEL);
if (!devinfo->shared.ringupd)
goto fail;
 
-   memset(devinfo->shared.ringupd, 0, BRCMF_DMA_D2H_RINGUPD_BUF_LEN);
-
addr = devinfo->shared.tcm_base_address +
   BRCMF_SHARED_DMA_RINGUPD_ADDR_OFFSET;
address = (u64)devinfo->shared.ringupd_dmahandle;
-- 
2.7.4



Re: brcmfmac: Use zeroing memory allocator than allocator/memset

2018-01-08 Thread Himanshu Jha
On Mon, Jan 08, 2018 at 05:23:22PM +, Kalle Valo wrote:
> Himanshu Jha  wrote:
> 
> > Use dma_zalloc_coherent for allocating zeroed
> > memory and remove unnecessary memset function.
> > 
> > Done using Coccinelle.
> > Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
> > 0-day tested with no failures.
> > 
> > Suggested-by: Luis R. Rodriguez 
> > Signed-off-by: Himanshu Jha 
> > Reviewed-by: Andy Shevchenko 
> 
> Failed to apply:
> 
> fatal: corrupt patch at line 29
> error: could not build fake ancestor
> Applying: brcmfmac: Use zeroing memory allocator than allocator/memset
> Patch failed at 0001 brcmfmac: Use zeroing memory allocator than 
> allocator/memset
> The copy of the patch that failed is found in: .git/rebase-apply/patch
> 
> Patch set to Changes Requested.

Sorry! That failed because I manually adjusted the arguments to prevent
80 character limit in the patch generated.

I will rebase and send v2 with updates.

-- 
Thanks
Himanshu Jha


[PATCH] liquidio: Use zeroing memory allocator than allocator/memset

2017-12-31 Thread Himanshu Jha
Use vzalloc for allocating zeroed memory and remove unnecessary
memset function.

Done using Coccinelle.
Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
0-day tested with no failures.

Suggested-by: Luis R. Rodriguez 
Signed-off-by: Himanshu Jha 
---
 drivers/net/ethernet/cavium/liquidio/octeon_device.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_device.c 
b/drivers/net/ethernet/cavium/liquidio/octeon_device.c
index 2c615ab..f38abf6 100644
--- a/drivers/net/ethernet/cavium/liquidio/octeon_device.c
+++ b/drivers/net/ethernet/cavium/liquidio/octeon_device.c
@@ -702,12 +702,10 @@ static struct octeon_device 
*octeon_allocate_device_mem(u32 pci_id,
size = octdevsize + priv_size + configsize +
(sizeof(struct octeon_dispatch) * DISPATCH_LIST_SIZE);
 
-   buf = vmalloc(size);
+   buf = vzalloc(size);
if (!buf)
return NULL;
 
-   memset(buf, 0, size);
-
oct = (struct octeon_device *)buf;
oct->priv = (void *)(buf + octdevsize);
oct->chip = (void *)(buf + octdevsize + priv_size);
@@ -840,10 +838,9 @@ octeon_allocate_ioq_vector(struct octeon_device  *oct)
 
size = sizeof(struct octeon_ioq_vector) * num_ioqs;
 
-   oct->ioq_vector = vmalloc(size);
+   oct->ioq_vector = vzalloc(size);
if (!oct->ioq_vector)
return 1;
-   memset(oct->ioq_vector, 0, size);
for (i = 0; i < num_ioqs; i++) {
ioq_vector  = &oct->ioq_vector[i];
ioq_vector->oct_dev = oct;
-- 
2.7.4



[PATCH] brcmfmac: Use zeroing memory allocator than allocator/memset

2017-12-30 Thread Himanshu Jha
Use dma_zalloc_coherent for allocating zeroed
memory and remove unnecessary memset function.

Done using Coccinelle.
Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
0-day tested with no failures.

Suggested-by: Luis R. Rodriguez 
Signed-off-by: Himanshu Jha 
---
 .../net/wireless/broadcom/brcm80211/brcmfmac/pcie.c| 18 --
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c 
b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
index 3c87157..bdef2ac 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
@@ -1251,14 +1251,13 @@ static int brcmf_pcie_init_scratchbuffers(struct 
brcmf_pciedev_info *devinfo)
u64 address;
u32 addr;
 
-   devinfo->shared.scratch = dma_alloc_coherent(&devinfo->pdev->dev,
-   BRCMF_DMA_D2H_SCRATCH_BUF_LEN,
-   &devinfo->shared.scratch_dmahandle, GFP_KERNEL);
+   devinfo->shared.scratch =
+   dma_zalloc_coherent(&devinfo->pdev->dev,
+   BRCMF_DMA_D2H_SCRATCH_BUF_LEN,
+   &devinfo->shared.scratch_dmahandle,
+   GFP_KERNEL);
if (!devinfo->shared.scratch)
goto fail;
 
-   memset(devinfo->shared.scratch, 0, BRCMF_DMA_D2H_SCRATCH_BUF_LEN);
-
addr = devinfo->shared.tcm_base_address +
   BRCMF_SHARED_DMA_SCRATCH_ADDR_OFFSET;
address = (u64)devinfo->shared.scratch_dmahandle;
@@ -1268,14 +1267,13 @@ static int brcmf_pcie_init_scratchbuffers(struct 
brcmf_pciedev_info *devinfo)
   BRCMF_SHARED_DMA_SCRATCH_LEN_OFFSET;
brcmf_pcie_write_tcm32(devinfo, addr, BRCMF_DMA_D2H_SCRATCH_BUF_LEN);
 
-   devinfo->shared.ringupd = dma_alloc_coherent(&devinfo->pdev->dev,
-   BRCMF_DMA_D2H_RINGUPD_BUF_LEN,
-   &devinfo->shared.ringupd_dmahandle, GFP_KERNEL);
+   devinfo->shared.ringupd =
+   dma_zalloc_coherent(&devinfo->pdev->dev,
+   BRCMF_DMA_D2H_RINGUPD_BUF_LEN,
+   &devinfo->shared.ringupd_dmahandle,
+   GFP_KERNEL);
if (!devinfo->shared.ringupd)
goto fail;
 
-   memset(devinfo->shared.ringupd, 0, BRCMF_DMA_D2H_RINGUPD_BUF_LEN);
-
addr = devinfo->shared.tcm_base_address +
   BRCMF_SHARED_DMA_RINGUPD_ADDR_OFFSET;
address = (u64)devinfo->shared.ringupd_dmahandle;
-- 
2.7.4



[PATCH] ethernet/broadcom: Use zeroing memory allocator than allocator/memset

2017-12-30 Thread Himanshu Jha
Use dma_zalloc_coherent for allocating zeroed
memory and remove unnecessary memset function.

Done using Coccinelle.
Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
0-day tested with no failures.

Suggested-by: Luis R. Rodriguez 
Signed-off-by: Himanshu Jha 
---
 drivers/net/ethernet/broadcom/bcm63xx_enet.c  | 6 ++
 drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c | 5 ++---
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.c 
b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
index 1fbbbab..14a59e5 100644
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
@@ -2128,27 +2128,25 @@ static int bcm_enetsw_open(struct net_device *dev)
 
/* allocate rx dma ring */
size = priv->rx_ring_size * sizeof(struct bcm_enet_desc);
-   p = dma_alloc_coherent(kdev, size, &priv->rx_desc_dma, GFP_KERNEL);
+   p = dma_zalloc_coherent(kdev, size, &priv->rx_desc_dma, GFP_KERNEL);
if (!p) {
dev_err(kdev, "cannot allocate rx ring %u\n", size);
ret = -ENOMEM;
goto out_freeirq_tx;
}
 
-   memset(p, 0, size);
priv->rx_desc_alloc_size = size;
priv->rx_desc_cpu = p;
 
/* allocate tx dma ring */
size = priv->tx_ring_size * sizeof(struct bcm_enet_desc);
-   p = dma_alloc_coherent(kdev, size, &priv->tx_desc_dma, GFP_KERNEL);
+   p = dma_zalloc_coherent(kdev, size, &priv->tx_desc_dma, GFP_KERNEL);
if (!p) {
dev_err(kdev, "cannot allocate tx ring\n");
ret = -ENOMEM;
goto out_free_rx_ring;
}
 
-   memset(p, 0, size);
priv->tx_desc_alloc_size = size;
priv->tx_desc_cpu = p;
 
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c 
b/drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c
index fed37cd..3c746f2 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c
@@ -278,12 +278,11 @@ static int bnxt_hwrm_set_dcbx_app(struct bnxt *bp, struct 
dcb_app *app,
 
n = IEEE_8021QAZ_MAX_TCS;
data_len = sizeof(*data) + sizeof(*fw_app) * n;
-   data = dma_alloc_coherent(&bp->pdev->dev, data_len, &mapping,
- GFP_KERNEL);
+   data = dma_zalloc_coherent(&bp->pdev->dev, data_len, &mapping,
+  GFP_KERNEL);
if (!data)
return -ENOMEM;
 
-   memset(data, 0, data_len);
bnxt_hwrm_cmd_hdr_init(bp, &get, HWRM_FW_GET_STRUCTURED_DATA, -1, -1);
get.dest_data_addr = cpu_to_le64(mapping);
get.structure_id = cpu_to_le16(STRUCT_HDR_STRUCT_ID_DCBX_APP);
-- 
2.7.4



[PATCH] qed: Use zeroing memory allocator than allocator/memset

2017-12-30 Thread Himanshu Jha
Use dma_zalloc_coherent and vzalloc for allocating zeroed
memory and remove unnecessary memset function.

Done using Coccinelle.
Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
0-day tested with no failures.

Suggested-by: Luis R. Rodriguez 
Signed-off-by: Himanshu Jha 
---
 drivers/net/ethernet/qlogic/qed/qed_cxt.c | 12 +---
 drivers/net/ethernet/qlogic/qed/qed_l2.c  |  3 +--
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qed/qed_cxt.c 
b/drivers/net/ethernet/qlogic/qed/qed_cxt.c
index afd07ad..f0a55d2 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_cxt.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_cxt.c
@@ -1055,11 +1055,10 @@ static int qed_ilt_blk_alloc(struct qed_hwfn *p_hwfn,
u32 size;
 
size = min_t(u32, sz_left, p_blk->real_size_in_page);
-   p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
-   size, &p_phys, GFP_KERNEL);
+   p_virt = dma_zalloc_coherent(&p_hwfn->cdev->pdev->dev, size,
+&p_phys, GFP_KERNEL);
if (!p_virt)
return -ENOMEM;
-   memset(p_virt, 0, size);
 
ilt_shadow[line].p_phys = p_phys;
ilt_shadow[line].p_virt = p_virt;
@@ -2303,14 +2302,13 @@ qed_cxt_dynamic_ilt_alloc(struct qed_hwfn *p_hwfn,
goto out0;
}
 
-   p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
-   p_blk->real_size_in_page,
-   &p_phys, GFP_KERNEL);
+   p_virt = dma_zalloc_coherent(&p_hwfn->cdev->pdev->dev,
+p_blk->real_size_in_page, &p_phys,
+GFP_KERNEL);
if (!p_virt) {
rc = -ENOMEM;
goto out1;
}
-   memset(p_virt, 0, p_blk->real_size_in_page);
 
/* configuration of refTagMask to 0xF is required for RoCE DIF MR only,
 * to compensate for a HW bug, but it is configured even if DIF is not
diff --git a/drivers/net/ethernet/qlogic/qed/qed_l2.c 
b/drivers/net/ethernet/qlogic/qed/qed_l2.c
index 0853389..fd76b81 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_l2.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_l2.c
@@ -223,10 +223,9 @@ _qed_eth_queue_to_cid(struct qed_hwfn *p_hwfn,
struct qed_queue_cid *p_cid;
int rc;
 
-   p_cid = vmalloc(sizeof(*p_cid));
+   p_cid = vzalloc(sizeof(*p_cid));
if (!p_cid)
return NULL;
-   memset(p_cid, 0, sizeof(*p_cid));
 
p_cid->opaque_fid = opaque_fid;
p_cid->cid = cid;
-- 
2.7.4



[PATCH v2] mwifiex: Use put_unaligned_le32

2017-10-06 Thread Himanshu Jha
Use put_unaligned_le32 rather than using byte ordering function and
memcpy which makes code clear.
Also, add the header file where it is declared.

Done using Coccinelle and semantic patch used is :

@ rule1 @
identifier tmp; expression ptr,x; type T;
@@

- tmp = cpu_to_le32(x);

  <+... when != tmp
- memcpy(ptr, (T)&tmp, ...);
+ put_unaligned_le32(x,ptr);
  ...+>

@ depends on rule1 @
type j; identifier tmp;
@@

- j tmp;
  ...when != tmp

Signed-off-by: Himanshu Jha 
---
v2:
* added correct header file.

 drivers/net/wireless/marvell/mwifiex/cmdevt.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/marvell/mwifiex/cmdevt.c 
b/drivers/net/wireless/marvell/mwifiex/cmdevt.c
index 0edc5d6..e28e119 100644
--- a/drivers/net/wireless/marvell/mwifiex/cmdevt.c
+++ b/drivers/net/wireless/marvell/mwifiex/cmdevt.c
@@ -17,6 +17,7 @@
  * this warranty disclaimer.
  */
 
+#include 
 #include "decl.h"
 #include "ioctl.h"
 #include "util.h"
@@ -183,7 +184,6 @@ static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private 
*priv,
uint16_t cmd_code;
uint16_t cmd_size;
unsigned long flags;
-   __le32 tmp;
 
if (!adapter || !cmd_node)
return -1;
@@ -249,9 +249,9 @@ static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private 
*priv,
mwifiex_dbg_dump(adapter, CMD_D, "cmd buffer:", host_cmd, cmd_size);
 
if (adapter->iface_type == MWIFIEX_USB) {
-   tmp = cpu_to_le32(MWIFIEX_USB_TYPE_CMD);
skb_push(cmd_node->cmd_skb, MWIFIEX_TYPE_LEN);
-   memcpy(cmd_node->cmd_skb->data, &tmp, MWIFIEX_TYPE_LEN);
+   put_unaligned_le32(MWIFIEX_USB_TYPE_CMD,
+  cmd_node->cmd_skb->data);
adapter->cmd_sent = true;
ret = adapter->if_ops.host_to_card(adapter,
   MWIFIEX_USB_EP_CMD_EVENT,
@@ -317,7 +317,6 @@ static int mwifiex_dnld_sleep_confirm_cmd(struct 
mwifiex_adapter *adapter)
(struct mwifiex_opt_sleep_confirm *)
adapter->sleep_cfm->data;
struct sk_buff *sleep_cfm_tmp;
-   __le32 tmp;
 
priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
 
@@ -342,8 +341,7 @@ static int mwifiex_dnld_sleep_confirm_cmd(struct 
mwifiex_adapter *adapter)
  + MWIFIEX_TYPE_LEN);
skb_put(sleep_cfm_tmp, sizeof(struct mwifiex_opt_sleep_confirm)
+ MWIFIEX_TYPE_LEN);
-   tmp = cpu_to_le32(MWIFIEX_USB_TYPE_CMD);
-   memcpy(sleep_cfm_tmp->data, &tmp, MWIFIEX_TYPE_LEN);
+   put_unaligned_le32(MWIFIEX_USB_TYPE_CMD, sleep_cfm_tmp->data);
memcpy(sleep_cfm_tmp->data + MWIFIEX_TYPE_LEN,
   adapter->sleep_cfm->data,
   sizeof(struct mwifiex_opt_sleep_confirm));
-- 
2.7.4



Re: [PATCH] mwifiex: Use put_unaligned_le32

2017-10-05 Thread Himanshu Jha
On Thu, Oct 05, 2017 at 11:02:50AM -0700, Brian Norris wrote:
> On Thu, Oct 05, 2017 at 08:52:33PM +0530, Himanshu Jha wrote:
> > There are various instances where a function used in file say for eg
> > int func_align (void* a)
> > is used and it is defined in align.h
> > But many files don't *directly* include align.h and rather include
> > any other header which includes align.h
> 
> I believe the general rule is that you should included headers for all
> symbols you use, and not rely on implicit includes.
> 
> The modification to the general rule is that not all headers are
> intended to be included directly, and in such cases there's likely a
> parent header that is the more appropriate target.
> 
> In this case, the key is CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS. It
> seems that asm-generic/unaligned.h is set up to include different
> headers, based on the expected architecture behavior.
>
Yes, asm-generic/unaligned.h looks more appopriate and is most generic
implementation of unaligned accesses and  arc specific.

Let's see what Kalle Valo recommends! And then I will send v2 of the
patch.

Thanks for the information!

Himanshu Jha

> I wonder if include/linux/unaligned/access_ok.h should have a safety
> check (e.g., raise an #error if
> !CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS?).
> 
> > Is compiling the file the only way to check if apppropriate header is
> > included or is there some other way to check for it.
> 
> I believe it's mostly manual. Implicit includes have been a problem for
> anyone who refactors header files.
> 
> Brian


Re: [PATCH] mwifiex: Use put_unaligned_le32

2017-10-05 Thread Himanshu Jha
On Thu, Oct 05, 2017 at 11:41:38AM +0300, Kalle Valo wrote:
> Himanshu Jha  writes:
> 
> >> > --- a/drivers/net/wireless/marvell/mwifiex/cmdevt.c
> >> > +++ b/drivers/net/wireless/marvell/mwifiex/cmdevt.c
> >> > @@ -17,6 +17,7 @@
> >> >   * this warranty disclaimer.
> >> >   */
> >> >  
> >> > +#include 
> >> 
> >> I don't think this is correct. Should it be asm/unaligned.h?
> >
> > Would mind explainig me as to why it is incorrect! Also, it defined in
> > both the header files but, why is asm/unaligned.h preferred ?
> 
> asm/unaligned.h seems to be the toplevel header file which includes
> header files based on arch configuration. Also grepping the sources
> support that, nobody from drivers/ include access_ok.h directly.
>
Yes, you are correct!

I will send v2 patch with asm/unaligned.h

> But I can't say that I fully understand how the header files work so
> please do correct me if I have mistaken.
>
It is confusing to me as well.
There are various instances where a function used in file say for eg
int func_align (void* a)
is used and it is defined in align.h
But many files don't *directly* include align.h and rather include
any other header which includes align.h

Is compiling the file the only way to check if apppropriate header is
included or is there some other way to check for it.

Thanks



Re: [PATCH] mwifiex: Use put_unaligned_le32

2017-10-05 Thread Himanshu Jha
On Thu, Oct 05, 2017 at 10:23:37AM +0300, Kalle Valo wrote:
> Himanshu Jha  writes:
> 
> > Use put_unaligned_le32 rather than using byte ordering function and
> > memcpy which makes code clear.
> > Also, add the header file where it is declared.
> >
> > Done using Coccinelle and semantic patch used is :
> >
> > @ rule1 @
> > identifier tmp; expression ptr,x; type T;
> > @@
> >
> > - tmp = cpu_to_le32(x);
> >
> >   <+... when != tmp
> > - memcpy(ptr, (T)&tmp, ...);
> > + put_unaligned_le32(x,ptr);
> >   ...+>
> >
> > @ depends on rule1 @
> > type j; identifier tmp;
> > @@
> >
> > - j tmp;
> >   ...when != tmp
> >
> > Signed-off-by: Himanshu Jha 
> > ---
> >  drivers/net/wireless/marvell/mwifiex/cmdevt.c | 10 --
> >  1 file changed, 4 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/net/wireless/marvell/mwifiex/cmdevt.c 
> > b/drivers/net/wireless/marvell/mwifiex/cmdevt.c
> > index 0edc5d6..e28e119 100644
> > --- a/drivers/net/wireless/marvell/mwifiex/cmdevt.c
> > +++ b/drivers/net/wireless/marvell/mwifiex/cmdevt.c
> > @@ -17,6 +17,7 @@
> >   * this warranty disclaimer.
> >   */
> >  
> > +#include 
> 
> I don't think this is correct. Should it be asm/unaligned.h?

Would mind explainig me as to why it is incorrect! Also, it defined in
both the header files but, why is asm/unaligned.h preferred ?

Thanks

> -- 
> Kalle Valo


[PATCH] mwifiex: Use put_unaligned_le32

2017-10-04 Thread Himanshu Jha
Use put_unaligned_le32 rather than using byte ordering function and
memcpy which makes code clear.
Also, add the header file where it is declared.

Done using Coccinelle and semantic patch used is :

@ rule1 @
identifier tmp; expression ptr,x; type T;
@@

- tmp = cpu_to_le32(x);

  <+... when != tmp
- memcpy(ptr, (T)&tmp, ...);
+ put_unaligned_le32(x,ptr);
  ...+>

@ depends on rule1 @
type j; identifier tmp;
@@

- j tmp;
  ...when != tmp

Signed-off-by: Himanshu Jha 
---
 drivers/net/wireless/marvell/mwifiex/cmdevt.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/marvell/mwifiex/cmdevt.c 
b/drivers/net/wireless/marvell/mwifiex/cmdevt.c
index 0edc5d6..e28e119 100644
--- a/drivers/net/wireless/marvell/mwifiex/cmdevt.c
+++ b/drivers/net/wireless/marvell/mwifiex/cmdevt.c
@@ -17,6 +17,7 @@
  * this warranty disclaimer.
  */
 
+#include 
 #include "decl.h"
 #include "ioctl.h"
 #include "util.h"
@@ -183,7 +184,6 @@ static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private 
*priv,
uint16_t cmd_code;
uint16_t cmd_size;
unsigned long flags;
-   __le32 tmp;
 
if (!adapter || !cmd_node)
return -1;
@@ -249,9 +249,9 @@ static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private 
*priv,
mwifiex_dbg_dump(adapter, CMD_D, "cmd buffer:", host_cmd, cmd_size);
 
if (adapter->iface_type == MWIFIEX_USB) {
-   tmp = cpu_to_le32(MWIFIEX_USB_TYPE_CMD);
skb_push(cmd_node->cmd_skb, MWIFIEX_TYPE_LEN);
-   memcpy(cmd_node->cmd_skb->data, &tmp, MWIFIEX_TYPE_LEN);
+   put_unaligned_le32(MWIFIEX_USB_TYPE_CMD,
+  cmd_node->cmd_skb->data);
adapter->cmd_sent = true;
ret = adapter->if_ops.host_to_card(adapter,
   MWIFIEX_USB_EP_CMD_EVENT,
@@ -317,7 +317,6 @@ static int mwifiex_dnld_sleep_confirm_cmd(struct 
mwifiex_adapter *adapter)
(struct mwifiex_opt_sleep_confirm *)
adapter->sleep_cfm->data;
struct sk_buff *sleep_cfm_tmp;
-   __le32 tmp;
 
priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
 
@@ -342,8 +341,7 @@ static int mwifiex_dnld_sleep_confirm_cmd(struct 
mwifiex_adapter *adapter)
  + MWIFIEX_TYPE_LEN);
skb_put(sleep_cfm_tmp, sizeof(struct mwifiex_opt_sleep_confirm)
+ MWIFIEX_TYPE_LEN);
-   tmp = cpu_to_le32(MWIFIEX_USB_TYPE_CMD);
-   memcpy(sleep_cfm_tmp->data, &tmp, MWIFIEX_TYPE_LEN);
+   put_unaligned_le32(MWIFIEX_USB_TYPE_CMD, sleep_cfm_tmp->data);
memcpy(sleep_cfm_tmp->data + MWIFIEX_TYPE_LEN,
   adapter->sleep_cfm->data,
   sizeof(struct mwifiex_opt_sleep_confirm));
-- 
2.7.4



[PATCH] net: bcm63xx_enet: Use setup_timer and mod_timer

2017-09-24 Thread Himanshu Jha
Use setup_timer and mod_timer API instead of structure assignments.

This is done using Coccinelle and semantic patch used
for this as follows:

@@
expression x,y,z,a,b;
@@

-init_timer (&x);
+setup_timer (&x, y, z);
+mod_timer (&a, b);
-x.function = y;
-x.data = z;
-x.expires = b;
-add_timer(&a);

Signed-off-by: Himanshu Jha 
---
 drivers/net/ethernet/broadcom/bcm63xx_enet.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.c 
b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
index f8f..c6221f0 100644
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
@@ -2331,11 +2331,8 @@ static int bcm_enetsw_open(struct net_device *dev)
}
 
/* start phy polling timer */
-   init_timer(&priv->swphy_poll);
-   priv->swphy_poll.function = swphy_poll_timer;
-   priv->swphy_poll.data = (unsigned long)priv;
-   priv->swphy_poll.expires = jiffies;
-   add_timer(&priv->swphy_poll);
+   setup_timer(&priv->swphy_poll, swphy_poll_timer, (unsigned long)priv);
+   mod_timer(&priv->swphy_poll, jiffies);
return 0;
 
 out:
-- 
2.7.4



[PATCH] qed: remove unnecessary call to memset

2017-09-12 Thread Himanshu Jha
call to memset to assign 0 value immediately after allocating
memory with kzalloc is unnecesaary as kzalloc allocates the memory
filled with 0 value.

Semantic patch used to resolve this issue:

@@
expression e,e2; constant c;
statement S;
@@

  e = kzalloc(e2, c);
  if(e == NULL) S
- memset(e, 0, e2);

Signed-off-by: Himanshu Jha 
---
 drivers/net/ethernet/qlogic/qed/qed_dcbx.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c 
b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
index eaca457..8f6ccc0 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
@@ -1244,7 +1244,6 @@ int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
if (!dcbx_info)
return -ENOMEM;
 
-   memset(dcbx_info, 0, sizeof(*dcbx_info));
rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
if (rc) {
kfree(dcbx_info);
-- 
2.7.4



[PATCH] mwifiex: remove unnecessary call to memset

2017-09-11 Thread Himanshu Jha
call to memset to assign 0 value immediately after allocating
memory with kzalloc is unnecesaary as kzalloc allocates the memory
filled with 0 value.

Semantic patch used to resolve this issue:

@@
expression e,e2; constant c;
statement S;
@@

  e = kzalloc(e2, c);
  if(e == NULL) S
- memset(e, 0, e2);

Signed-off-by: Himanshu Jha 
---
 drivers/net/wireless/marvell/mwifiex/scan.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/wireless/marvell/mwifiex/scan.c 
b/drivers/net/wireless/marvell/mwifiex/scan.c
index c9d41ed..8838b88 100644
--- a/drivers/net/wireless/marvell/mwifiex/scan.c
+++ b/drivers/net/wireless/marvell/mwifiex/scan.c
@@ -1936,8 +1936,6 @@ mwifiex_active_scan_req_for_passive_chan(struct 
mwifiex_private *priv)
if (!user_scan_cfg)
return -ENOMEM;
 
-   memset(user_scan_cfg, 0, sizeof(*user_scan_cfg));
-
for (id = 0; id < MWIFIEX_USER_SCAN_CHAN_MAX; id++) {
if (!priv->hidden_chan[id].chan_number)
break;
-- 
2.7.4



[PATCH] ath9k: remove cast to void pointer

2017-08-31 Thread Himanshu Jha
casting to void pointer from any pointer type and vice-versa is done
implicitly and therefore casting is not needed in such a case.

Signed-off-by: Himanshu Jha 
---
 drivers/net/wireless/ath/ath9k/ar9003_mac.c |  4 ++--
 drivers/net/wireless/ath/ath9k/dfs.c|  2 +-
 drivers/net/wireless/ath/ath9k/hif_usb.c|  8 
 drivers/net/wireless/ath/ath9k/htc_drv_beacon.c |  2 +-
 drivers/net/wireless/ath/ath9k/htc_drv_init.c   | 24 
 drivers/net/wireless/ath/ath9k/htc_drv_main.c   |  2 +-
 drivers/net/wireless/ath/ath9k/htc_drv_txrx.c   |  6 +++---
 drivers/net/wireless/ath/ath9k/init.c   |  8 
 drivers/net/wireless/ath/ath9k/main.c   |  2 +-
 drivers/net/wireless/ath/ath9k/mci.c|  2 +-
 drivers/net/wireless/ath/ath9k/wmi.c|  4 ++--
 11 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c 
b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
index b3f20b3..e1fe7a7 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
@@ -480,7 +480,7 @@ EXPORT_SYMBOL(ath9k_hw_addrxbuf_edma);
 int ath9k_hw_process_rxdesc_edma(struct ath_hw *ah, struct ath_rx_status *rxs,
 void *buf_addr)
 {
-   struct ar9003_rxs *rxsp = (struct ar9003_rxs *) buf_addr;
+   struct ar9003_rxs *rxsp = buf_addr;
unsigned int phyerr;
 
if ((rxsp->status11 & AR_RxDone) == 0)
@@ -610,7 +610,7 @@ void ath9k_hw_setup_statusring(struct ath_hw *ah, void 
*ts_start,
ah->ts_paddr_start = ts_paddr_start;
ah->ts_paddr_end = ts_paddr_start + (size * sizeof(struct ar9003_txs));
ah->ts_size = size;
-   ah->ts_ring = (struct ar9003_txs *) ts_start;
+   ah->ts_ring = ts_start;
 
ath9k_hw_reset_txstatus_ring(ah);
 }
diff --git a/drivers/net/wireless/ath/ath9k/dfs.c 
b/drivers/net/wireless/ath/ath9k/dfs.c
index 1ece42c..40a397f 100644
--- a/drivers/net/wireless/ath/ath9k/dfs.c
+++ b/drivers/net/wireless/ath/ath9k/dfs.c
@@ -326,7 +326,7 @@ void ath9k_dfs_process_phyerr(struct ath_softc *sc, void 
*data,
if (ard.ext_rssi & 0x80)
ard.ext_rssi = 0;
 
-   vdata_end = (char *)data + datalen;
+   vdata_end = data + datalen;
ard.pulse_bw_info = vdata_end[-1];
ard.pulse_length_ext = vdata_end[-2];
ard.pulse_length_pri = vdata_end[-3];
diff --git a/drivers/net/wireless/ath/ath9k/hif_usb.c 
b/drivers/net/wireless/ath/ath9k/hif_usb.c
index 0d9687a..71d1725 100644
--- a/drivers/net/wireless/ath/ath9k/hif_usb.c
+++ b/drivers/net/wireless/ath/ath9k/hif_usb.c
@@ -424,7 +424,7 @@ static int hif_usb_send_tx(struct hif_device_usb *hif_dev, 
struct sk_buff *skb)
 
 static void hif_usb_start(void *hif_handle)
 {
-   struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
+   struct hif_device_usb *hif_dev = hif_handle;
unsigned long flags;
 
hif_dev->flags |= HIF_USB_START;
@@ -436,7 +436,7 @@ static void hif_usb_start(void *hif_handle)
 
 static void hif_usb_stop(void *hif_handle)
 {
-   struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
+   struct hif_device_usb *hif_dev = hif_handle;
struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL;
unsigned long flags;
 
@@ -457,7 +457,7 @@ static void hif_usb_stop(void *hif_handle)
 
 static int hif_usb_send(void *hif_handle, u8 pipe_id, struct sk_buff *skb)
 {
-   struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
+   struct hif_device_usb *hif_dev = hif_handle;
int ret = 0;
 
switch (pipe_id) {
@@ -492,7 +492,7 @@ static inline bool check_index(struct sk_buff *skb, u8 idx)
 
 static void hif_usb_sta_drain(void *hif_handle, u8 idx)
 {
-   struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
+   struct hif_device_usb *hif_dev = hif_handle;
struct sk_buff *skb, *tmp;
unsigned long flags;
 
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c 
b/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c
index 2c0e4d2..f20c839 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c
@@ -384,7 +384,7 @@ void ath9k_htc_set_tsfadjust(struct ath9k_htc_priv *priv,
 
 static void ath9k_htc_beacon_iter(void *data, u8 *mac, struct ieee80211_vif 
*vif)
 {
-   bool *beacon_configured = (bool *)data;
+   bool *beacon_configured = data;
struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
 
if (vif->type == NL80211_IFTYPE_STATION &&
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_init.c 
b/drivers/net/wireless/ath/ath9k/htc_drv_init.c
index defacc6..9e0c237 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_init.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_init.c
@@ -233,7 +233,7 @@ static void ath9k_reg_notifier(

[PATCH] rsi: remove memset before memcpy

2017-08-29 Thread Himanshu Jha
calling memcpy immediately after memset with the same region of memory
makes memset redundant.

Signed-off-by: Himanshu Jha 
---
 drivers/net/wireless/rsi/rsi_91x_sdio.c | 1 -
 drivers/net/wireless/rsi/rsi_91x_usb.c  | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/net/wireless/rsi/rsi_91x_sdio.c 
b/drivers/net/wireless/rsi/rsi_91x_sdio.c
index 742f6cd..8d3a483 100644
--- a/drivers/net/wireless/rsi/rsi_91x_sdio.c
+++ b/drivers/net/wireless/rsi/rsi_91x_sdio.c
@@ -584,7 +584,6 @@ static int rsi_sdio_load_data_master_write(struct rsi_hw 
*adapter,
}
 
for (offset = 0, i = 0; i < num_blocks; i++, offset += block_size) {
-   memset(temp_buf, 0, block_size);
memcpy(temp_buf, ta_firmware + offset, block_size);
lsb_address = (u16)base_address;
status = rsi_sdio_write_register_multiple
diff --git a/drivers/net/wireless/rsi/rsi_91x_usb.c 
b/drivers/net/wireless/rsi/rsi_91x_usb.c
index 9097f7e..81df09d 100644
--- a/drivers/net/wireless/rsi/rsi_91x_usb.c
+++ b/drivers/net/wireless/rsi/rsi_91x_usb.c
@@ -439,7 +439,6 @@ static int rsi_usb_load_data_master_write(struct rsi_hw 
*adapter,
rsi_dbg(INFO_ZONE, "num_blocks: %d\n", num_blocks);
 
for (cur_indx = 0, i = 0; i < num_blocks; i++, cur_indx += block_size) {
-   memset(temp_buf, 0, block_size);
memcpy(temp_buf, ta_firmware + cur_indx, block_size);
status = rsi_usb_write_register_multiple(adapter, base_address,
 (u8 *)(temp_buf),
-- 
2.7.4



[PATCH] net: ethernet: broadcom: Remove null check before kfree

2017-08-26 Thread Himanshu Jha
Kfree on NULL pointer is a no-op and therefore checking is redundant.

Signed-off-by: Himanshu Jha 
---
 drivers/net/ethernet/broadcom/sb1250-mac.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/sb1250-mac.c 
b/drivers/net/ethernet/broadcom/sb1250-mac.c
index 16a0f19..ecdef42 100644
--- a/drivers/net/ethernet/broadcom/sb1250-mac.c
+++ b/drivers/net/ethernet/broadcom/sb1250-mac.c
@@ -1367,15 +1367,11 @@ static int sbmac_initctx(struct sbmac_softc *s)
 
 static void sbdma_uninitctx(struct sbmacdma *d)
 {
-   if (d->sbdma_dscrtable_unaligned) {
-   kfree(d->sbdma_dscrtable_unaligned);
-   d->sbdma_dscrtable_unaligned = d->sbdma_dscrtable = NULL;
-   }
+   kfree(d->sbdma_dscrtable_unaligned);
+   d->sbdma_dscrtable_unaligned = d->sbdma_dscrtable = NULL;
 
-   if (d->sbdma_ctxtable) {
-   kfree(d->sbdma_ctxtable);
-   d->sbdma_ctxtable = NULL;
-   }
+   kfree(d->sbdma_ctxtable);
+   d->sbdma_ctxtable = NULL;
 }
 
 
-- 
2.7.4



[PATCH] cfg80211: Use tabs for identation

2017-08-24 Thread Himanshu Jha
Removed whitespaces and added necessary tabs conforming to coding style.
Issue found using checkpatch.pl

Signed-off-by: Himanshu Jha 
---
 net/wireless/chan.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/wireless/chan.c b/net/wireless/chan.c
index b8aa5a7..13c95e5 100644
--- a/net/wireless/chan.c
+++ b/net/wireless/chan.c
@@ -984,9 +984,9 @@ int cfg80211_set_monitor_channel(struct 
cfg80211_registered_device *rdev,
 
 void
 cfg80211_get_chan_state(struct wireless_dev *wdev,
-   struct ieee80211_channel **chan,
-   enum cfg80211_chan_mode *chanmode,
-   u8 *radar_detect)
+   struct ieee80211_channel **chan,
+   enum cfg80211_chan_mode *chanmode,
+   u8 *radar_detect)
 {
int ret;
 
-- 
2.7.4



[PATCH v2] at76c50x-usb: check memory allocation failure

2017-08-23 Thread Himanshu Jha
Check memory allocation failure and return -ENOMEM rather than just
retuning void.

Signed-off-by: Himanshu Jha 
---
 drivers/net/wireless/atmel/at76c50x-usb.c | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/net/wireless/atmel/at76c50x-usb.c 
b/drivers/net/wireless/atmel/at76c50x-usb.c
index 09defbc..ceb453b 100644
--- a/drivers/net/wireless/atmel/at76c50x-usb.c
+++ b/drivers/net/wireless/atmel/at76c50x-usb.c
@@ -932,7 +932,7 @@ static int at76_set_autorate_fallback(struct at76_priv 
*priv, int onoff)
return ret;
 }
 
-static void at76_dump_mib_mac_addr(struct at76_priv *priv)
+static int at76_dump_mib_mac_addr(struct at76_priv *priv)
 {
int i;
int ret;
@@ -940,7 +940,7 @@ static void at76_dump_mib_mac_addr(struct at76_priv *priv)
 GFP_KERNEL);
 
if (!m)
-   return;
+   return -ENOMEM;
 
ret = at76_get_mib(priv->udev, MIB_MAC_ADDR, m,
   sizeof(struct mib_mac_addr));
@@ -961,7 +961,7 @@ static void at76_dump_mib_mac_addr(struct at76_priv *priv)
kfree(m);
 }
 
-static void at76_dump_mib_mac_wep(struct at76_priv *priv)
+static int at76_dump_mib_mac_wep(struct at76_priv *priv)
 {
int i;
int ret;
@@ -969,7 +969,7 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv)
struct mib_mac_wep *m = kmalloc(sizeof(struct mib_mac_wep), GFP_KERNEL);
 
if (!m)
-   return;
+   return -ENOMEM;
 
ret = at76_get_mib(priv->udev, MIB_MAC_WEP, m,
   sizeof(struct mib_mac_wep));
@@ -999,14 +999,14 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv)
kfree(m);
 }
 
-static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
+static int at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 {
int ret;
struct mib_mac_mgmt *m = kmalloc(sizeof(struct mib_mac_mgmt),
 GFP_KERNEL);
 
if (!m)
-   return;
+   return -ENOMEM;
 
ret = at76_get_mib(priv->udev, MIB_MAC_MGMT, m,
   sizeof(struct mib_mac_mgmt));
@@ -1037,13 +1037,13 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv 
*priv)
kfree(m);
 }
 
-static void at76_dump_mib_mac(struct at76_priv *priv)
+static int at76_dump_mib_mac(struct at76_priv *priv)
 {
int ret;
struct mib_mac *m = kmalloc(sizeof(struct mib_mac), GFP_KERNEL);
 
if (!m)
-   return;
+   return -ENOMEM;
 
ret = at76_get_mib(priv->udev, MIB_MAC, m, sizeof(struct mib_mac));
if (ret < 0) {
@@ -1074,13 +1074,13 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
kfree(m);
 }
 
-static void at76_dump_mib_phy(struct at76_priv *priv)
+static int at76_dump_mib_phy(struct at76_priv *priv)
 {
int ret;
struct mib_phy *m = kmalloc(sizeof(struct mib_phy), GFP_KERNEL);
 
if (!m)
-   return;
+   return -ENOMEM;
 
ret = at76_get_mib(priv->udev, MIB_PHY, m, sizeof(struct mib_phy));
if (ret < 0) {
@@ -1107,13 +1107,13 @@ static void at76_dump_mib_phy(struct at76_priv *priv)
kfree(m);
 }
 
-static void at76_dump_mib_local(struct at76_priv *priv)
+static int at76_dump_mib_local(struct at76_priv *priv)
 {
int ret;
struct mib_local *m = kmalloc(sizeof(*m), GFP_KERNEL);
 
if (!m)
-   return;
+   return -ENOMEM;
 
ret = at76_get_mib(priv->udev, MIB_LOCAL, m, sizeof(*m));
if (ret < 0) {
@@ -1132,13 +1132,13 @@ static void at76_dump_mib_local(struct at76_priv *priv)
kfree(m);
 }
 
-static void at76_dump_mib_mdomain(struct at76_priv *priv)
+static int at76_dump_mib_mdomain(struct at76_priv *priv)
 {
int ret;
struct mib_mdomain *m = kmalloc(sizeof(struct mib_mdomain), GFP_KERNEL);
 
if (!m)
-   return;
+   return -ENOMEM;
 
ret = at76_get_mib(priv->udev, MIB_MDOMAIN, m,
   sizeof(struct mib_mdomain));
-- 
2.7.4



[PATCH] drivers: net: wireless: atmel: check memory allocation failure

2017-08-22 Thread Himanshu Jha
Check memory allocation failure and return -ENOMEM if failure
occurs.

Signed-off-by: Himanshu Jha 
---
 drivers/net/wireless/atmel/at76c50x-usb.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/atmel/at76c50x-usb.c 
b/drivers/net/wireless/atmel/at76c50x-usb.c
index 09defbc..73f0924 100644
--- a/drivers/net/wireless/atmel/at76c50x-usb.c
+++ b/drivers/net/wireless/atmel/at76c50x-usb.c
@@ -940,7 +940,7 @@ static void at76_dump_mib_mac_addr(struct at76_priv *priv)
 GFP_KERNEL);
 
if (!m)
-   return;
+   return -ENOMEM;
 
ret = at76_get_mib(priv->udev, MIB_MAC_ADDR, m,
   sizeof(struct mib_mac_addr));
@@ -969,7 +969,7 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv)
struct mib_mac_wep *m = kmalloc(sizeof(struct mib_mac_wep), GFP_KERNEL);
 
if (!m)
-   return;
+   return -ENOMEM;
 
ret = at76_get_mib(priv->udev, MIB_MAC_WEP, m,
   sizeof(struct mib_mac_wep));
@@ -1006,7 +1006,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 GFP_KERNEL);
 
if (!m)
-   return;
+   return -ENOMEM;
 
ret = at76_get_mib(priv->udev, MIB_MAC_MGMT, m,
   sizeof(struct mib_mac_mgmt));
@@ -1043,7 +1043,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
struct mib_mac *m = kmalloc(sizeof(struct mib_mac), GFP_KERNEL);
 
if (!m)
-   return;
+   return -ENOMEM;
 
ret = at76_get_mib(priv->udev, MIB_MAC, m, sizeof(struct mib_mac));
if (ret < 0) {
@@ -1080,7 +1080,7 @@ static void at76_dump_mib_phy(struct at76_priv *priv)
struct mib_phy *m = kmalloc(sizeof(struct mib_phy), GFP_KERNEL);
 
if (!m)
-   return;
+   return -ENOMEM;
 
ret = at76_get_mib(priv->udev, MIB_PHY, m, sizeof(struct mib_phy));
if (ret < 0) {
@@ -1113,7 +1113,7 @@ static void at76_dump_mib_local(struct at76_priv *priv)
struct mib_local *m = kmalloc(sizeof(*m), GFP_KERNEL);
 
if (!m)
-   return;
+   return -ENOMEM;
 
ret = at76_get_mib(priv->udev, MIB_LOCAL, m, sizeof(*m));
if (ret < 0) {
@@ -1138,7 +1138,7 @@ static void at76_dump_mib_mdomain(struct at76_priv *priv)
struct mib_mdomain *m = kmalloc(sizeof(struct mib_mdomain), GFP_KERNEL);
 
if (!m)
-   return;
+   return -ENOMEM;
 
ret = at76_get_mib(priv->udev, MIB_MDOMAIN, m,
   sizeof(struct mib_mdomain));
-- 
2.7.4