Re: [PATCH] staging: rtl8723bs: core: rtw_recv: fix warning Comparison to NULL

2019-05-16 Thread Joe Perches
On Thu, 2019-05-16 at 23:55 +0530, Hariprasad Kelam wrote:
> On Thu, May 16, 2019 at 11:00:56AM +0300, Dan Carpenter wrote:
> > On Wed, May 15, 2019 at 11:15:36PM +0530, Hariprasad Kelam wrote:
> > > @@ -1042,7 +1042,7 @@ sint sta2ap_data_frame(
> > >   }
> > >  
> > >   *psta = rtw_get_stainfo(pstapriv, pattrib->src);
> > > - if (*psta == NULL) {
> > > + if (!*psta == NULL) {
> > ^^
> > It's surprising that this didn't cause some kind of warning somewhere...
> 
> Thanks for pointing out this error. Here my intention is to write
> if(!*psta) 
> but somehow i missed it .
> 
> Will resend this patch after correcting the same.Like below
> 
> > -   if (*psta == NULL) {
> > > +   if (!*psta) {

You could run the coccinelle spatch file for bool
comparisons on the files instead.  It's much less
error prone.

$ spatch --sp-file scripts/coccinelle/misc/boolconv.cocci --in-place 
drivers/staging/rtl8723bs/

Or you could use a patch to checkpatch like below and then use

$ git ls-files drivers/staging/rtl8723bs | \
  xargs ./scripts/checkpatch.pl -f --fix-inplace --types=bool_comparison

but that definitely would not be as good as the coccinelle
tool use as coccinelle is much better at parsing expressions.

---
 scripts/checkpatch.pl | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 1c421ac42b07..fe83aa0b1f97 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6407,11 +6407,13 @@ sub process {
$op = "";
}
 
-   CHK("BOOL_COMPARISON",
-   "Using comparison to $otype is error 
prone\n" . $herecurr);
-
+   if (CHK("BOOL_COMPARISON",
+   "Using comparison to $otype is error 
prone\n" . $herecurr) &&
+   $fix) {
+   $fixed[$fixlinenr] =~ 
s/\b(?:true|false|$Lval)\s*(?:==|\!=)\s*(?:true|false|$Lval)\b/${op}${arg}/;
+   }
 ## maybe suggesting a correct construct would better
-## "Using comparison to $otype is error prone. 
 Perhaps use '${lead}${op}${arg}${trail}'\n" . $herecurr);
+## "Using comparison to $otype is error 
prone.  Perhaps use '${lead}${op}${arg}${trail}'\n" . $herecurr);
 
}
}


___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: rtl8723bs: core: rtw_recv: fix warning Comparison to NULL

2019-05-16 Thread Hariprasad Kelam
On Thu, May 16, 2019 at 11:00:56AM +0300, Dan Carpenter wrote:
> On Wed, May 15, 2019 at 11:15:36PM +0530, Hariprasad Kelam wrote:
> > @@ -1042,7 +1042,7 @@ sint sta2ap_data_frame(
> > }
> >  
> > *psta = rtw_get_stainfo(pstapriv, pattrib->src);
> > -   if (*psta == NULL) {
> > +   if (!*psta == NULL) {
> ^^
> It's surprising that this didn't cause some kind of warning somewhere...

Thanks for pointing out this error. Here my intention is to write
if(!*psta) 
but somehow i missed it .

Will resend this patch after correcting the same.Like below

> -   if (*psta == NULL) {
> > +   if (!*psta) {


Do let me know if the above propose change is fine or not.
> 
> > RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't 
> > get psta under AP_MODE; drop pkt\n"));
> > DBG_871X("issue_deauth to sta =" MAC_FMT " for the 
> > reason(7)\n", MAC_ARG(pattrib->src));
> >  
> 
> regards,
> dan carpenter
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: rtl8723bs: core: rtw_recv: fix warning Comparison to NULL

2019-05-16 Thread Dan Carpenter
On Wed, May 15, 2019 at 11:15:36PM +0530, Hariprasad Kelam wrote:
> @@ -1042,7 +1042,7 @@ sint sta2ap_data_frame(
>   }
>  
>   *psta = rtw_get_stainfo(pstapriv, pattrib->src);
> - if (*psta == NULL) {
> + if (!*psta == NULL) {
^^
It's surprising that this didn't cause some kind of warning somewhere...

>   RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't 
> get psta under AP_MODE; drop pkt\n"));
>   DBG_871X("issue_deauth to sta =" MAC_FMT " for the 
> reason(7)\n", MAC_ARG(pattrib->src));
>  

regards,
dan carpenter
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: rtl8723bs: core: rtw_recv: fix warning Comparison to NULL

2019-05-15 Thread Hariprasad Kelam
fix below warning reported by checkpatch

CHECK: Comparison to NULL could be written
"!precvpriv->pallocated_frame_buf"
CHECK: Comparison to NULL could be written "padapter"

Signed-off-by: Hariprasad Kelam 
---
 drivers/staging/rtl8723bs/core/rtw_recv.c | 48 +++
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_recv.c 
b/drivers/staging/rtl8723bs/core/rtw_recv.c
index b543e97..b01dae5 100644
--- a/drivers/staging/rtl8723bs/core/rtw_recv.c
+++ b/drivers/staging/rtl8723bs/core/rtw_recv.c
@@ -50,7 +50,7 @@ sint _rtw_init_recv_priv(struct recv_priv *precvpriv, struct 
adapter *padapter)
 
precvpriv->pallocated_frame_buf = vzalloc(NR_RECVFRAME * sizeof(union 
recv_frame) + RXFRAME_ALIGN_SZ);
 
-   if (precvpriv->pallocated_frame_buf == NULL) {
+   if (!precvpriv->pallocated_frame_buf) {
res = _FAIL;
goto exit;
}
@@ -122,7 +122,7 @@ union recv_frame *_rtw_alloc_recvframe(struct __queue 
*pfree_recv_queue)
 
list_del_init(>u.hdr.list);
padapter = precvframe->u.hdr.adapter;
-   if (padapter != NULL) {
+   if (padapter) {
precvpriv = >recvpriv;
if (pfree_recv_queue == >free_recv_queue)
precvpriv->free_recvframe_cnt--;
@@ -160,7 +160,7 @@ int rtw_free_recvframe(union recv_frame *precvframe, struct 
__queue *pfree_recv_
 
list_add_tail(&(precvframe->u.hdr.list), 
get_list_head(pfree_recv_queue));
 
-   if (padapter != NULL) {
+   if (padapter) {
if (pfree_recv_queue == >free_recv_queue)
precvpriv->free_recvframe_cnt++;
}
@@ -183,7 +183,7 @@ sint _rtw_enqueue_recvframe(union recv_frame *precvframe, 
struct __queue *queue)
 
list_add_tail(&(precvframe->u.hdr.list), get_list_head(queue));
 
-   if (padapter != NULL)
+   if (padapter)
if (queue == >free_recv_queue)
precvpriv->free_recvframe_cnt++;
 
@@ -334,7 +334,7 @@ sint recvframe_chkmic(struct adapter *adapter,  union 
recv_frame *precvframe)
prxattrib->ra[0], prxattrib->ra[1], prxattrib->ra[2], 
prxattrib->ra[3], prxattrib->ra[4], prxattrib->ra[5]));
 
/* calculate mic code */
-   if (stainfo != NULL) {
+   if (stainfo) {
if (IS_MCAST(prxattrib->ra)) {
/* mickey 
=>dot118021XGrprxmickey.skey[0]; */
/* iv = 
precvframe->u.hdr.rx_data+prxattrib->hdrlen; */
@@ -570,7 +570,7 @@ union recv_frame *portctrl(struct adapter *adapter, union 
recv_frame *precv_fram
RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, 
("portctrl:adapter->securitypriv.dot11AuthAlgrthm =%d\n", 
adapter->securitypriv.dot11AuthAlgrthm));
 
if (auth_alg == 2) {
-   if ((psta != NULL) && (psta->ieee8021x_blocked)) {
+   if ((psta) && (psta->ieee8021x_blocked)) {
__be16 be_tmp;
 
/* blocked */
@@ -859,7 +859,7 @@ sint sta2sta_data_frame(
else
*psta = rtw_get_stainfo(pstapriv, sta_addr); /*  get ap_info */
 
-   if (*psta == NULL) {
+   if (!*psta) {
RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta 
under sta2sta_data_frame ; drop pkt\n"));
ret = _FAIL;
goto exit;
@@ -942,7 +942,7 @@ sint ap2sta_data_frame(
else
*psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /*  
get ap_info */
 
-   if (*psta == NULL) {
+   if (!*psta) {
RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("ap2sta: 
can't get psta under STATION_MODE ; drop pkt\n"));
#ifdef DBG_RX_DROP_FRAME
DBG_871X("DBG_RX_DROP_FRAME %s can't get psta under 
STATION_MODE ; drop pkt\n", __func__);
@@ -974,7 +974,7 @@ sint ap2sta_data_frame(
 
 
*psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /*  get 
sta_info */
-   if (*psta == NULL) {
+   if (!*psta) {
RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't 
get psta under MP_MODE ; drop pkt\n"));
#ifdef DBG_RX_DROP_FRAME
DBG_871X("DBG_RX_DROP_FRAME %s can't get psta under 
WIFI_MP_STATE ; drop pkt\n", __func__);
@@ -991,7 +991,7 @@ sint ap2sta_data_frame(
} else {
if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && (!bmcast)) {
*psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /*  
get sta_info */
-   if (*psta == NULL) {
+   if (!*psta) {
 
/* for AP multicast issue , modify by yiwei */