[PATCH v2] net/mlx4: Use true,false for bool variable

2020-12-14 Thread Vasyl Gomonovych
It is fix for semantic patch warning available in
scripts/coccinelle/misc/boolinit.cocci
Fix en_rx.c:687:1-17: WARNING: Assignment of 0/1 to bool variable
Fix main.c:4465:5-13: WARNING: Comparison of 0/1 to bool variable

Signed-off-by: Vasyl Gomonovych 
---
 - Add coccicheck script name
 - Simplify if condition
---
 drivers/net/ethernet/mellanox/mlx4/en_rx.c | 2 +-
 drivers/net/ethernet/mellanox/mlx4/main.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c 
b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index 502d1b97855c..b0f79a5151cf 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -684,7 +684,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct 
mlx4_en_cq *cq, int bud
xdp_prog = rcu_dereference(ring->xdp_prog);
xdp.rxq = &ring->xdp_rxq;
xdp.frame_sz = priv->frag_info[0].frag_stride;
-   doorbell_pending = 0;
+   doorbell_pending = false;
 
/* We assume a 1:1 mapping between CQEs and Rx descriptors, so Rx
 * descriptor offset can be deduced from the CQE index instead of
diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c 
b/drivers/net/ethernet/mellanox/mlx4/main.c
index c326b434734e..3492a4f3691e 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -4462,7 +4462,7 @@ static int __init mlx4_verify_params(void)
pr_warn("mlx4_core: log_num_vlan - obsolete module param, using 
%d\n",
MLX4_LOG_NUM_VLANS);
 
-   if (use_prio != 0)
+   if (use_prio)
pr_warn("mlx4_core: use_prio - obsolete module param, 
ignored\n");
 
if ((log_mtts_per_seg < 0) || (log_mtts_per_seg > 7)) {
-- 
2.17.1



[PATCH] net/mlx4: Use true,false for bool variable

2020-12-11 Thread Vasyl Gomonovych
Fix en_rx.c:687:1-17: WARNING: Assignment of 0/1 to bool variable
Fix main.c:4465:5-13: WARNING: Comparison of 0/1 to bool variable

Signed-off-by: Vasyl Gomonovych 
---
 drivers/net/ethernet/mellanox/mlx4/en_rx.c | 2 +-
 drivers/net/ethernet/mellanox/mlx4/main.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c 
b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index 502d1b97855c..b0f79a5151cf 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -684,7 +684,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct 
mlx4_en_cq *cq, int bud
xdp_prog = rcu_dereference(ring->xdp_prog);
xdp.rxq = &ring->xdp_rxq;
xdp.frame_sz = priv->frag_info[0].frag_stride;
-   doorbell_pending = 0;
+   doorbell_pending = false;
 
/* We assume a 1:1 mapping between CQEs and Rx descriptors, so Rx
 * descriptor offset can be deduced from the CQE index instead of
diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c 
b/drivers/net/ethernet/mellanox/mlx4/main.c
index c326b434734e..c5bce3eeed91 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -4462,7 +4462,7 @@ static int __init mlx4_verify_params(void)
pr_warn("mlx4_core: log_num_vlan - obsolete module param, using 
%d\n",
MLX4_LOG_NUM_VLANS);
 
-   if (use_prio != 0)
+   if (use_prio != false)
pr_warn("mlx4_core: use_prio - obsolete module param, 
ignored\n");
 
if ((log_mtts_per_seg < 0) || (log_mtts_per_seg > 7)) {
-- 
2.17.1



[PATCH] net: intel: e100: Fix warning of passing zero to 'PTR_ERR'

2017-12-07 Thread Vasyl Gomonovych
fw could be NULL and put into PTR_ERR
also zero in PTR_ERR will be translated into success return statement

Signed-off-by: Vasyl Gomonovych 
---
 drivers/net/ethernet/intel/e100.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/e100.c 
b/drivers/net/ethernet/intel/e100.c
index 4d10270..55e399d 100644
--- a/drivers/net/ethernet/intel/e100.c
+++ b/drivers/net/ethernet/intel/e100.c
@@ -1370,7 +1370,9 @@ static inline int e100_load_ucode_wait(struct nic *nic)
 
fw = e100_request_firmware(nic);
/* If it's NULL, then no ucode is required */
-   if (!fw || IS_ERR(fw))
+   if (!fw)
+   return -EINVAL;
+   else if (IS_ERR(fw))
return PTR_ERR(fw);
 
if ((err = e100_exec_cb(nic, (void *)fw, e100_setup_ucode)))
-- 
1.9.1



[PATCH] net: ethernet: ixp4xx_eth: Use dma_pool_zalloc

2017-11-30 Thread Vasyl Gomonovych
Replacing dma_pool_alloc and memset with a single call to dma_pool_zalloc

Signed-off-by: Vasyl Gomonovych 
---
 drivers/net/ethernet/xscale/ixp4xx_eth.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c 
b/drivers/net/ethernet/xscale/ixp4xx_eth.c
index aee55c03def0..02f7f3e3da8d 100644
--- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
+++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
@@ -1108,10 +1108,10 @@ static int init_queues(struct port *port)
return -ENOMEM;
}
 
-   if (!(port->desc_tab = dma_pool_alloc(dma_pool, GFP_KERNEL,
- &port->desc_tab_phys)))
+   port->desc_tab = dma_pool_zalloc(dma_pool, GFP_KERNEL,
+&port->desc_tab_phys);
+   if (!port->desc_tab)
return -ENOMEM;
-   memset(port->desc_tab, 0, POOL_ALLOC_SIZE);
memset(port->rx_buff_tab, 0, sizeof(port->rx_buff_tab)); /* tables */
memset(port->tx_buff_tab, 0, sizeof(port->tx_buff_tab));
 
-- 
1.9.1



[PATCH] NFC: use timer_setup() helper

2017-11-25 Thread Vasyl Gomonovych
Use timer_setup function instead of initializing timer with the
function and data fields.

net/nfc/core.c:1097:2-12: Use setup_timer function for function on line 1098
net/nfc/hci/core.c:1007:1-11: Use setup_timer function for function on line 1008
net/nfc/hci/llc_shdlc.c:766:1-11: Use setup_timer function for function on line 
767
net/nfc/hci/llc_shdlc.c:766:1-11: Use setup_timer function for function on line 
767
net/nfc/llcp_core.c:1576:1-11: Use setup_timer function for function on line 
1577

Generated by: scripts/coccinelle/api/setup_timer.cocci

Signed-off-by: Vasyl Gomonovych 
---
 net/nfc/core.c  |  8 +++-
 net/nfc/hci/core.c  |  8 +++-
 net/nfc/hci/llc_shdlc.c | 26 +-
 net/nfc/llcp_core.c | 16 ++--
 4 files changed, 21 insertions(+), 37 deletions(-)

diff --git a/net/nfc/core.c b/net/nfc/core.c
index 5cf33df888c3..b220b0406b57 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -1015,9 +1015,9 @@ static void nfc_check_pres_work(struct work_struct *work)
device_unlock(&dev->dev);
 }
 
-static void nfc_check_pres_timeout(unsigned long data)
+static void nfc_check_pres_timeout(struct timer_list *t)
 {
-   struct nfc_dev *dev = (struct nfc_dev *)data;
+   struct nfc_dev *dev = from_timer(dev, t, check_pres_timer);
 
schedule_work(&dev->check_pres_work);
 }
@@ -1094,9 +1094,7 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
dev->targets_generation = 1;
 
if (ops->check_presence) {
-   init_timer(&dev->check_pres_timer);
-   dev->check_pres_timer.data = (unsigned long)dev;
-   dev->check_pres_timer.function = nfc_check_pres_timeout;
+   timer_setup(&dev->check_pres_timer, nfc_check_pres_timeout, 0);
 
INIT_WORK(&dev->check_pres_work, nfc_check_pres_work);
}
diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c
index b740fef0acc5..ac8030c4bcf8 100644
--- a/net/nfc/hci/core.c
+++ b/net/nfc/hci/core.c
@@ -428,9 +428,9 @@ void nfc_hci_event_received(struct nfc_hci_dev *hdev, u8 
pipe, u8 event,
nfc_hci_driver_failure(hdev, r);
 }
 
-static void nfc_hci_cmd_timeout(unsigned long data)
+static void nfc_hci_cmd_timeout(struct timer_list *t)
 {
-   struct nfc_hci_dev *hdev = (struct nfc_hci_dev *)data;
+   struct nfc_hci_dev *hdev = from_timer(hdev, t, cmd_timer);
 
schedule_work(&hdev->msg_tx_work);
 }
@@ -1004,9 +1004,7 @@ int nfc_hci_register_device(struct nfc_hci_dev *hdev)
 
INIT_WORK(&hdev->msg_tx_work, nfc_hci_msg_tx_work);
 
-   init_timer(&hdev->cmd_timer);
-   hdev->cmd_timer.data = (unsigned long)hdev;
-   hdev->cmd_timer.function = nfc_hci_cmd_timeout;
+   timer_setup(&hdev->cmd_timer, nfc_hci_cmd_timeout, 0);
 
skb_queue_head_init(&hdev->rx_hcp_frags);
 
diff --git a/net/nfc/hci/llc_shdlc.c b/net/nfc/hci/llc_shdlc.c
index 17e59a009ce6..fe988936ad92 100644
--- a/net/nfc/hci/llc_shdlc.c
+++ b/net/nfc/hci/llc_shdlc.c
@@ -580,27 +580,27 @@ static void llc_shdlc_handle_send_queue(struct llc_shdlc 
*shdlc)
}
 }
 
-static void llc_shdlc_connect_timeout(unsigned long data)
+static void llc_shdlc_connect_timeout(struct timer_list *t)
 {
-   struct llc_shdlc *shdlc = (struct llc_shdlc *)data;
+   struct llc_shdlc *shdlc = from_timer(shdlc, t, connect_timer);
 
pr_debug("\n");
 
schedule_work(&shdlc->sm_work);
 }
 
-static void llc_shdlc_t1_timeout(unsigned long data)
+static void llc_shdlc_t1_timeout(struct timer_list *t)
 {
-   struct llc_shdlc *shdlc = (struct llc_shdlc *)data;
+   struct llc_shdlc *shdlc = from_timer(shdlc, t, t1_timer);
 
pr_debug("SoftIRQ: need to send ack\n");
 
schedule_work(&shdlc->sm_work);
 }
 
-static void llc_shdlc_t2_timeout(unsigned long data)
+static void llc_shdlc_t2_timeout(struct timer_list *t)
 {
-   struct llc_shdlc *shdlc = (struct llc_shdlc *)data;
+   struct llc_shdlc *shdlc = from_timer(shdlc, t, t2_timer);
 
pr_debug("SoftIRQ: need to retransmit\n");
 
@@ -763,17 +763,9 @@ static void *llc_shdlc_init(struct nfc_hci_dev *hdev, 
xmit_to_drv_t xmit_to_drv,
mutex_init(&shdlc->state_mutex);
shdlc->state = SHDLC_DISCONNECTED;
 
-   init_timer(&shdlc->connect_timer);
-   shdlc->connect_timer.data = (unsigned long)shdlc;
-   shdlc->connect_timer.function = llc_shdlc_connect_timeout;
-
-   init_timer(&shdlc->t1_timer);
-   shdlc->t1_timer.data = (unsigned long)shdlc;
-   shdlc->t1_timer.function = llc_shdlc_t1_timeout;
-
-   init_timer(&shdlc->t2_timer);
-   shdlc->t2_timer.data = (unsigned long)shdlc;
-   shdlc->t2_timer.function = llc_shdlc_t2_timeout;
+   timer_setup(&shdlc->connect_timer, llc_shdlc_connect_timeo

[PATCH] [WAN]: lmc: Use memdup_user() as a cleanup

2017-11-22 Thread Vasyl Gomonovych
Fix coccicheck warning which recommends to use memdup_user():
drivers/net/wan/lmc/lmc_main.c:497:27-34: WARNING opportunity for memdup_user
Generated by: scripts/coccinelle/memdup_user/memdup_user.cocci

Signed-off-by: Vasyl Gomonovych 
---
 drivers/net/wan/lmc/lmc_main.c | 13 +++--
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wan/lmc/lmc_main.c b/drivers/net/wan/lmc/lmc_main.c
index 4698450c77d1..ded78a466fe3 100644
--- a/drivers/net/wan/lmc/lmc_main.c
+++ b/drivers/net/wan/lmc/lmc_main.c
@@ -494,18 +494,11 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, 
int cmd) /*fold00*/
 break;
 }
 
-data = kmalloc(xc.len, GFP_KERNEL);
-if (!data) {
-ret = -ENOMEM;
+data = memdup_user(xc.data, xc.len);
+if (IS_ERR(data)) {
+ret = PTR_ERR(data);
 break;
 }
-
-if(copy_from_user(data, xc.data, xc.len))
-{
-   kfree(data);
-   ret = -ENOMEM;
-   break;
-}
 
 printk("%s: Starting load of data Len: %d at 0x%p == 
0x%p\n", dev->name, xc.len, xc.data, data);
 
-- 
1.9.1



[PATCH] net: ethernet: ti: cpts: Use ERR_CAST instead of ERR_PTR(PTR_ERR())

2017-11-21 Thread Vasyl Gomonovych
Use ERR_CAST inlined function instead of ERR_PTR(PTR_ERR(...)).
drivers/net/ethernet/ti/cpts.c:567:9-16: WARNING: ERR_CAST can be used with 
cpts -> refclk
Generated by: scripts/coccinelle/api/err_cast.cocci

Signed-off-by: Vasyl Gomonovych 
---
 drivers/net/ethernet/ti/cpts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
index e7b76f6b4f67..7842f094f2ef 100644
--- a/drivers/net/ethernet/ti/cpts.c
+++ b/drivers/net/ethernet/ti/cpts.c
@@ -564,7 +564,7 @@ struct cpts *cpts_create(struct device *dev, void __iomem 
*regs,
cpts->refclk = devm_clk_get(dev, "cpts");
if (IS_ERR(cpts->refclk)) {
dev_err(dev, "Failed to get cpts refclk\n");
-   return ERR_PTR(PTR_ERR(cpts->refclk));
+   return ERR_CAST(cpts->refclk);
}
 
clk_prepare(cpts->refclk);
-- 
1.9.1



Re: [PATCH] qed: fix unnecessary call to memset cocci warnings

2017-11-20 Thread Vasyl Gomonovych
It  doesn't apply becouse of identical one qed: use kzalloc instead of kmalloc 
and memset.


[PATCH] qed: fix unnecessary call to memset cocci warnings

2017-11-16 Thread Vasyl Gomonovych
Use kzalloc rather than kmalloc followed by memset with 0

drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1280:13-20: WARNING:
kzalloc should be used for dcbx_info, instead of kmalloc/memset
Generated by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci

Signed-off-by: Vasyl Gomonovych 
---
 drivers/net/ethernet/qlogic/qed/qed_dcbx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c 
b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
index 8f6ccc0c39e5..cc9e0dfcee48 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
@@ -1277,11 +1277,10 @@ static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct 
qed_hwfn *hwfn,
 {
struct qed_dcbx_get *dcbx_info;
 
-   dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_ATOMIC);
+   dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_ATOMIC);
if (!dcbx_info)
return NULL;
 
-   memset(dcbx_info, 0, sizeof(*dcbx_info));
if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
kfree(dcbx_info);
return NULL;
-- 
1.9.1



Re: [PATCH] qed: fix unnecessary call to memset cocci warnings

2017-11-16 Thread Vasyl Gomonovych
Sorry.


[PATCH] qed: fix unnecessary call to memset cocci warnings

2017-11-15 Thread Vasyl Gomonovych
Use kzalloc rather than kmalloc followed by memset with 0
drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1280:13-20: WARNING:
kzalloc should be used for dcbx_info, instead of kmalloc/memset
Generated by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci

Originally was fixed in:
'commit 561ed23331df ("qed: fix kzalloc-simple.cocci warnings")'
But later warning was introduced in:
'commit 62289ba27558 ("qed: Fix possible system hang in the
dcbnl-getdcbx() path.")'

Signed-off-by: Vasyl Gomonovych 
---
 drivers/net/ethernet/qlogic/qed/qed_dcbx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c 
b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
index 8f6ccc0c39e5..9a1bd996a640 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
@@ -1277,11 +1277,10 @@ static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct 
qed_hwfn *hwfn,
 {
struct qed_dcbx_get *dcbx_info;
 
-   dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_ATOMIC);
+   dcbx_info = kzmalloc(sizeof(*dcbx_info), GFP_ATOMIC);
if (!dcbx_info)
return NULL;
 
-   memset(dcbx_info, 0, sizeof(*dcbx_info));
if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
kfree(dcbx_info);
return NULL;
-- 
1.9.1