Smatch: False positive in __dwc3_gadget_kick_transfer()

Zeeshan Ahmad <[email protected]> Wed, 4 Mar 2026 14:04:08 +0500
Newsgroups org.kernel.vger.smatch,org.kernel.vger.linux-usb
Message-ID <[email protected]>
Hi Dan,

I am performing a logic audit of the DWC3 driver and encountered a 
consistent Smatch warning in drivers/usb/dwc3/gadget.c that appears 
to be a false positive.

The warning:
drivers/usb/dwc3/gadget.c:1691 __dwc3_gadget_kick_transfer() warn: missing error code? 'ret'

The code:
1680:         ret = dwc3_prepare_trbs(dep);
1681:         if (ret < 0)
1682:                 return ret;
...
1690:         if (!ret && !starting)
1691:                 return ret;

In this context, ret = 0 is a valid success state. As noted in the 
comment at line 1676, it is normal to have no new TRBs prepared. 
The return at line 1691 signifies that no update to the transfer 
is required, which is a successful "no-op" rather than a failure.

It seems Smatch is flagging this because it expects a non-zero 
error code when the primary logic of a function is bypassed by 
a conditional check.

Best regards,
Zeeshan Ahmad