driverdev-devel.linuxdriverproject.org archive mirror
 help / color / mirror / Atom feed
* [bug report] staging: wilc1000: added support to dynamically add/remove interfaces
@ 2019-08-08 10:48 Dan Carpenter
  2019-08-13  6:25 ` Ajay.Kathat
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2019-08-08 10:48 UTC (permalink / raw)


Hello Ajay Singh,

The patch 9bc061e88054: "staging: wilc1000: added support to
dynamically add/remove interfaces" from Jun 26, 2019, leads to the
following static checker warning:

	drivers/staging/wilc1000/wilc_wlan.c:497 wilc_wlan_handle_txq()
	warn: missing error code here? 'wilc_wlan_txq_get_first()' failed.

drivers/staging/wilc1000/wilc_wlan.c
   474  int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count)
   475  {
   476          int i, entries = 0;
   477          u32 sum;
   478          u32 reg;
   479          u32 offset = 0;
   480          int vmm_sz = 0;
   481          struct txq_entry_t *tqe;
   482          int ret = 0;
                    ^^^^^^^

   483          int counter;
   484          int timeout;
   485          u32 vmm_table[WILC_VMM_TBL_SIZE];
   486          const struct wilc_hif_func *func;
   487          u8 *txb = wilc->tx_buffer;
   488          struct net_device *dev;
   489          struct wilc_vif *vif;
   490  
   491          if (wilc->quit)
   492                  goto out;
   493  
   494          mutex_lock(&wilc->txq_add_to_head_cs);
   495          tqe = wilc_wlan_txq_get_first(wilc);
   496          if (!tqe)
   497                  goto out;
                        ^^^^^^^^
Should this really be a success path?

   498          dev = tqe->vif->ndev;
   499          wilc_wlan_txq_filter_dup_tcp_ack(dev);
   500          i = 0;
   501          sum = 0;
   502          do {
   503                  if (tqe && (i < (WILC_VMM_TBL_SIZE - 1))) {

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [bug report] staging: wilc1000: added support to dynamically add/remove interfaces
  2019-08-08 10:48 [bug report] staging: wilc1000: added support to dynamically add/remove interfaces Dan Carpenter
@ 2019-08-13  6:25 ` Ajay.Kathat
  0 siblings, 0 replies; 3+ messages in thread
From: Ajay.Kathat @ 2019-08-13  6:25 UTC (permalink / raw)


Hi Dan,

On 8/8/2019 4:18 PM, Dan Carpenter wrote:
> 
> Hello Ajay Singh,
> 
> The patch 9bc061e88054: "staging: wilc1000: added support to
> dynamically add/remove interfaces" from Jun 26, 2019, leads to the
> following static checker warning:
> 
> 	drivers/staging/wilc1000/wilc_wlan.c:497 wilc_wlan_handle_txq()
> 	warn: missing error code here? 'wilc_wlan_txq_get_first()' failed.
> 
> drivers/staging/wilc1000/wilc_wlan.c
>    474  int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count)
>    475  {
>    476          int i, entries = 0;
>    477          u32 sum;
>    478          u32 reg;
>    479          u32 offset = 0;
>    480          int vmm_sz = 0;
>    481          struct txq_entry_t *tqe;
>    482          int ret = 0;
>                     ^^^^^^^
> 
>    483          int counter;
>    484          int timeout;
>    485          u32 vmm_table[WILC_VMM_TBL_SIZE];
>    486          const struct wilc_hif_func *func;
>    487          u8 *txb = wilc->tx_buffer;
>    488          struct net_device *dev;
>    489          struct wilc_vif *vif;
>    490  
>    491          if (wilc->quit)
>    492                  goto out;
>    493  
>    494          mutex_lock(&wilc->txq_add_to_head_cs);
>    495          tqe = wilc_wlan_txq_get_first(wilc);
>    496          if (!tqe)
>    497                  goto out;
>                         ^^^^^^^^
> Should this really be a success path?

I think, returning value '0' is safe here. Only 'ENOBUFS' return value
is used for retry while other values are not considered. The 'if'
condition exit this function in case the list is empty. And later the
elements will be fetched again once'txq_event' completion signal is
received.

Regards,
Ajay

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [bug report] staging: wilc1000: added support to dynamically add/remove interfaces
@ 2019-11-13 18:33 Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2019-11-13 18:33 UTC (permalink / raw)
  To: ajay.kathat; +Cc: devel

[ When we renamed the files, then all the old warnings showed up as
  new warnings again.  - dan ]

Hello Ajay Singh,

The patch 9bc061e88054: "staging: wilc1000: added support to
dynamically add/remove interfaces" from Jun 26, 2019, leads to the
following static checker warning:

	drivers/staging/wilc1000/wlan.c:497 wilc_wlan_handle_txq()
	warn: missing error code here? 'wilc_wlan_txq_get_first()' failed.

drivers/staging/wilc1000/wlan.c
   474  int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count)
   475  {
   476          int i, entries = 0;
   477          u32 sum;
   478          u32 reg;
   479          u32 offset = 0;
   480          int vmm_sz = 0;
   481          struct txq_entry_t *tqe;
   482          int ret = 0;
   483          int counter;
   484          int timeout;
   485          u32 vmm_table[WILC_VMM_TBL_SIZE];
   486          const struct wilc_hif_func *func;
   487          u8 *txb = wilc->tx_buffer;
   488          struct net_device *dev;
   489          struct wilc_vif *vif;
   490  
   491          if (wilc->quit)
   492                  goto out;
                        ^^^^^^^^

One of my coding hints is that "goto out;" is always wrong.  In the
best case the name is too ambiguous so it doesn't tell what the goto
does.  But quite often the goto does too much.  For example, it could do
kfree(foo->bar); where foo is NULL so it's a NULL dereference.  Always
always distrust code which does a goto out.

In this case we are unlocking a lock but we aren't holding the lock.
Is this a success path?  That's complicated to say and becomes even
more complicated when we review the rest of this function.  It appears
that this function returns -ENOBUFS or random meaningless nonsense.

   493  
   494          mutex_lock(&wilc->txq_add_to_head_cs);
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Lock.

   495          tqe = wilc_wlan_txq_get_first(wilc);
   496          if (!tqe)
   497                  goto out;
                        ^^^^^^^^^
In this case, Smatch complains that maybe the error code is wrong.
Are we setting "*txq_count" to the correct value?  It's hard to say.

   498          dev = tqe->vif->ndev;
   499          wilc_wlan_txq_filter_dup_tcp_ack(dev);
   500          i = 0;
   501          sum = 0;
   502          do {
   503                  if (tqe && (i < (WILC_VMM_TBL_SIZE - 1))) {
   504                          if (tqe->type == WILC_CFG_PKT)
   505                                  vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
   506  
   507                          else if (tqe->type == WILC_NET_PKT)
   508                                  vmm_sz = ETH_ETHERNET_HDR_OFFSET;

[ snip ]

   666          ret = func->hif_clear_int_ext(wilc, ENABLE_TX_VMM);
   667          if (!ret)
   668                  goto out_release_bus;
                        ^^^^^^^^^^^^^^^^^^^^
These functions return 1 on success and 0 on failure.  We should set the
error code here.  There are several other similar places in this
function where we return zero on error.

   669  
   670          ret = func->hif_block_tx_ext(wilc, 0, txb, offset);
   671  
   672  out_release_bus:
   673          release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
   674  
   675  out:
   676          mutex_unlock(&wilc->txq_add_to_head_cs);
   677  
   678          *txq_count = wilc->txq_entries;
   679          return ret;
   680  }

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-13 18:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-08 10:48 [bug report] staging: wilc1000: added support to dynamically add/remove interfaces Dan Carpenter
2019-08-13  6:25 ` Ajay.Kathat
2019-11-13 18:33 Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).