linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [usb:usb-testing 7/12] drivers/usb/dwc3/core.c:1482:69: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 4
@ 2024-04-24  5:03 kernel test robot
  2024-04-24  6:41 ` Johan Hovold
  0 siblings, 1 reply; 4+ messages in thread
From: kernel test robot @ 2024-04-24  5:03 UTC (permalink / raw)
  To: Krishna Kurapati
  Cc: oe-kbuild-all, linux-usb, Greg Kroah-Hartman, Bjorn Andersson,
	Johan Hovold

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
head:   a160e1202ca318a85c70cf5831f172cc79a24c57
commit: 846b4bacf2d48212f271fc1ef7488bcdf2c75bcb [7/12] usb: dwc3: core: Refactor PHY logic to support Multiport Controller
config: s390-allyesconfig (https://download.01.org/0day-ci/archive/20240424/202404241215.Mib19Cu7-lkp@intel.com/config)
compiler: s390-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240424/202404241215.Mib19Cu7-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202404241215.Mib19Cu7-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/usb/dwc3/core.c: In function 'dwc3_core_get_phy':
>> drivers/usb/dwc3/core.c:1482:69: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 4 [-Wformat-truncation=]
    1482 |                         snprintf(phy_name, sizeof(phy_name),  "usb2-%d", i);
         |                                                                     ^~
   drivers/usb/dwc3/core.c:1482:63: note: directive argument in the range [-2147483641, 254]
    1482 |                         snprintf(phy_name, sizeof(phy_name),  "usb2-%d", i);
         |                                                               ^~~~~~~~~
   drivers/usb/dwc3/core.c:1482:25: note: 'snprintf' output between 7 and 17 bytes into a destination of size 9
    1482 |                         snprintf(phy_name, sizeof(phy_name),  "usb2-%d", i);
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/usb/dwc3/core.c:1499:68: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 4 [-Wformat-truncation=]
    1499 |                         snprintf(phy_name, sizeof(phy_name), "usb3-%d", i);
         |                                                                    ^~
   drivers/usb/dwc3/core.c:1499:62: note: directive argument in the range [-2147483641, 254]
    1499 |                         snprintf(phy_name, sizeof(phy_name), "usb3-%d", i);
         |                                                              ^~~~~~~~~
   drivers/usb/dwc3/core.c:1499:25: note: 'snprintf' output between 7 and 17 bytes into a destination of size 9
    1499 |                         snprintf(phy_name, sizeof(phy_name), "usb3-%d", i);
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +1482 drivers/usb/dwc3/core.c

  1445	
  1446	static int dwc3_core_get_phy(struct dwc3 *dwc)
  1447	{
  1448		struct device		*dev = dwc->dev;
  1449		struct device_node	*node = dev->of_node;
  1450		char phy_name[9];
  1451		int ret;
  1452		int i;
  1453	
  1454		if (node) {
  1455			dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
  1456			dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
  1457		} else {
  1458			dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
  1459			dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
  1460		}
  1461	
  1462		if (IS_ERR(dwc->usb2_phy)) {
  1463			ret = PTR_ERR(dwc->usb2_phy);
  1464			if (ret == -ENXIO || ret == -ENODEV)
  1465				dwc->usb2_phy = NULL;
  1466			else
  1467				return dev_err_probe(dev, ret, "no usb2 phy configured\n");
  1468		}
  1469	
  1470		if (IS_ERR(dwc->usb3_phy)) {
  1471			ret = PTR_ERR(dwc->usb3_phy);
  1472			if (ret == -ENXIO || ret == -ENODEV)
  1473				dwc->usb3_phy = NULL;
  1474			else
  1475				return dev_err_probe(dev, ret, "no usb3 phy configured\n");
  1476		}
  1477	
  1478		for (i = 0; i < dwc->num_usb2_ports; i++) {
  1479			if (dwc->num_usb2_ports == 1)
  1480				snprintf(phy_name, sizeof(phy_name), "usb2-phy");
  1481			else
> 1482				snprintf(phy_name, sizeof(phy_name),  "usb2-%d", i);
  1483	
  1484			dwc->usb2_generic_phy[i] = devm_phy_get(dev, phy_name);
  1485			if (IS_ERR(dwc->usb2_generic_phy[i])) {
  1486				ret = PTR_ERR(dwc->usb2_generic_phy[i]);
  1487				if (ret == -ENOSYS || ret == -ENODEV)
  1488					dwc->usb2_generic_phy[i] = NULL;
  1489				else
  1490					return dev_err_probe(dev, ret, "failed to lookup phy %s\n",
  1491								phy_name);
  1492			}
  1493		}
  1494	
  1495		for (i = 0; i < dwc->num_usb3_ports; i++) {
  1496			if (dwc->num_usb3_ports == 1)
  1497				snprintf(phy_name, sizeof(phy_name), "usb3-phy");
  1498			else
  1499				snprintf(phy_name, sizeof(phy_name), "usb3-%d", i);
  1500	
  1501			dwc->usb3_generic_phy[i] = devm_phy_get(dev, phy_name);
  1502			if (IS_ERR(dwc->usb3_generic_phy[i])) {
  1503				ret = PTR_ERR(dwc->usb3_generic_phy[i]);
  1504				if (ret == -ENOSYS || ret == -ENODEV)
  1505					dwc->usb3_generic_phy[i] = NULL;
  1506				else
  1507					return dev_err_probe(dev, ret, "failed to lookup phy %s\n",
  1508								phy_name);
  1509			}
  1510		}
  1511	
  1512		return 0;
  1513	}
  1514	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [usb:usb-testing 7/12] drivers/usb/dwc3/core.c:1482:69: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 4
  2024-04-24  5:03 [usb:usb-testing 7/12] drivers/usb/dwc3/core.c:1482:69: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 4 kernel test robot
@ 2024-04-24  6:41 ` Johan Hovold
  2024-04-25  5:08   ` Krishna Kurapati PSSNV
  0 siblings, 1 reply; 4+ messages in thread
From: Johan Hovold @ 2024-04-24  6:41 UTC (permalink / raw)
  To: kernel test robot, Krishna Kurapati, Greg Kroah-Hartman
  Cc: oe-kbuild-all, linux-usb, Bjorn Andersson, Johan Hovold, Thinh Nguyen

On Wed, Apr 24, 2024 at 01:03:07PM +0800, kernel test robot wrote:
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
> head:   a160e1202ca318a85c70cf5831f172cc79a24c57
> commit: 846b4bacf2d48212f271fc1ef7488bcdf2c75bcb [7/12] usb: dwc3: core: Refactor PHY logic to support Multiport Controller
> config: s390-allyesconfig (https://download.01.org/0day-ci/archive/20240424/202404241215.Mib19Cu7-lkp@intel.com/config)
> compiler: s390-linux-gcc (GCC) 13.2.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240424/202404241215.Mib19Cu7-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202404241215.Mib19Cu7-lkp@intel.com/
> 
> All warnings (new ones prefixed by >>):
> 
>    drivers/usb/dwc3/core.c: In function 'dwc3_core_get_phy':
> >> drivers/usb/dwc3/core.c:1482:69: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 4 [-Wformat-truncation=]
>     1482 |                         snprintf(phy_name, sizeof(phy_name),  "usb2-%d", i);
>          |                                                                     ^~
>    drivers/usb/dwc3/core.c:1482:63: note: directive argument in the range [-2147483641, 254]
>     1482 |                         snprintf(phy_name, sizeof(phy_name),  "usb2-%d", i);

This version or s390-build of gcc appears to be confused as the
variable i is clearly in the range [0,254] in these for loops.

I also don't see this W=1 warning with my gcc-10 (aarch64).

It may be possible to work around this by using u8 type for the iterator
(and %u in the format), but I'm not sure we should be working around
compiler bugs like that.

>          |                                                               ^~~~~~~~~
>    drivers/usb/dwc3/core.c:1482:25: note: 'snprintf' output between 7 and 17 bytes into a destination of size 9
>     1482 |                         snprintf(phy_name, sizeof(phy_name),  "usb2-%d", i);
>          |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

>   1446	static int dwc3_core_get_phy(struct dwc3 *dwc)
>   1447	{

>   1450		char phy_name[9];
>   1451		int ret;
>   1452		int i;

>   1478		for (i = 0; i < dwc->num_usb2_ports; i++) {
>   1479			if (dwc->num_usb2_ports == 1)
>   1480				snprintf(phy_name, sizeof(phy_name), "usb2-phy");
>   1481			else
> > 1482				snprintf(phy_name, sizeof(phy_name),  "usb2-%d", i);

>   1493		}

Johan

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

* Re: [usb:usb-testing 7/12] drivers/usb/dwc3/core.c:1482:69: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 4
  2024-04-24  6:41 ` Johan Hovold
@ 2024-04-25  5:08   ` Krishna Kurapati PSSNV
  2024-04-25 15:18     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Krishna Kurapati PSSNV @ 2024-04-25  5:08 UTC (permalink / raw)
  To: Johan Hovold, kernel test robot, Greg Kroah-Hartman
  Cc: oe-kbuild-all, linux-usb, Bjorn Andersson, Johan Hovold, Thinh Nguyen



On 4/24/2024 12:11 PM, Johan Hovold wrote:
> On Wed, Apr 24, 2024 at 01:03:07PM +0800, kernel test robot wrote:
>> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
>> head:   a160e1202ca318a85c70cf5831f172cc79a24c57
>> commit: 846b4bacf2d48212f271fc1ef7488bcdf2c75bcb [7/12] usb: dwc3: core: Refactor PHY logic to support Multiport Controller
>> config: s390-allyesconfig (https://download.01.org/0day-ci/archive/20240424/202404241215.Mib19Cu7-lkp@intel.com/config)
>> compiler: s390-linux-gcc (GCC) 13.2.0
>> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240424/202404241215.Mib19Cu7-lkp@intel.com/reproduce)
>>
>> If you fix the issue in a separate patch/commit (i.e. not just a new version of
>> the same patch/commit), kindly add following tags
>> | Reported-by: kernel test robot <lkp@intel.com>
>> | Closes: https://lore.kernel.org/oe-kbuild-all/202404241215.Mib19Cu7-lkp@intel.com/
>>
>> All warnings (new ones prefixed by >>):
>>
>>     drivers/usb/dwc3/core.c: In function 'dwc3_core_get_phy':
>>>> drivers/usb/dwc3/core.c:1482:69: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 4 [-Wformat-truncation=]
>>      1482 |                         snprintf(phy_name, sizeof(phy_name),  "usb2-%d", i);
>>           |                                                                     ^~
>>     drivers/usb/dwc3/core.c:1482:63: note: directive argument in the range [-2147483641, 254]
>>      1482 |                         snprintf(phy_name, sizeof(phy_name),  "usb2-%d", i);
> 
> This version or s390-build of gcc appears to be confused as the
> variable i is clearly in the range [0,254] in these for loops.
> 
> I also don't see this W=1 warning with my gcc-10 (aarch64).
> 
> It may be possible to work around this by using u8 type for the iterator
> (and %u in the format), but I'm not sure we should be working around
> compiler bugs like that.

Thanks Johan. i agree it looks like a bogus compiler warning, but I 
think your suggestion of changing to u8 should work, if only to placate 
the compiler.

Greg, do you think I should go ahead and update it in v22 or can we 
ignore this warning ?

> 
>>           |                                                               ^~~~~~~~~
>>     drivers/usb/dwc3/core.c:1482:25: note: 'snprintf' output between 7 and 17 bytes into a destination of size 9
>>      1482 |                         snprintf(phy_name, sizeof(phy_name),  "usb2-%d", i);
>>           |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
>>    1446	static int dwc3_core_get_phy(struct dwc3 *dwc)
>>    1447	{
> 
>>    1450		char phy_name[9];
>>    1451		int ret;
>>    1452		int i;
> 
>>    1478		for (i = 0; i < dwc->num_usb2_ports; i++) {
>>    1479			if (dwc->num_usb2_ports == 1)
>>    1480				snprintf(phy_name, sizeof(phy_name), "usb2-phy");
>>    1481			else
>>> 1482				snprintf(phy_name, sizeof(phy_name),  "usb2-%d", i);
> 
>>    1493		}
> 
> Johan

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

* Re: [usb:usb-testing 7/12] drivers/usb/dwc3/core.c:1482:69: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 4
  2024-04-25  5:08   ` Krishna Kurapati PSSNV
@ 2024-04-25 15:18     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2024-04-25 15:18 UTC (permalink / raw)
  To: Krishna Kurapati PSSNV
  Cc: Johan Hovold, kernel test robot, oe-kbuild-all, linux-usb,
	Bjorn Andersson, Johan Hovold, Thinh Nguyen

On Thu, Apr 25, 2024 at 10:38:47AM +0530, Krishna Kurapati PSSNV wrote:
> 
> 
> On 4/24/2024 12:11 PM, Johan Hovold wrote:
> > On Wed, Apr 24, 2024 at 01:03:07PM +0800, kernel test robot wrote:
> > > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
> > > head:   a160e1202ca318a85c70cf5831f172cc79a24c57
> > > commit: 846b4bacf2d48212f271fc1ef7488bcdf2c75bcb [7/12] usb: dwc3: core: Refactor PHY logic to support Multiport Controller
> > > config: s390-allyesconfig (https://download.01.org/0day-ci/archive/20240424/202404241215.Mib19Cu7-lkp@intel.com/config)
> > > compiler: s390-linux-gcc (GCC) 13.2.0
> > > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240424/202404241215.Mib19Cu7-lkp@intel.com/reproduce)
> > > 
> > > If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > > the same patch/commit), kindly add following tags
> > > | Reported-by: kernel test robot <lkp@intel.com>
> > > | Closes: https://lore.kernel.org/oe-kbuild-all/202404241215.Mib19Cu7-lkp@intel.com/
> > > 
> > > All warnings (new ones prefixed by >>):
> > > 
> > >     drivers/usb/dwc3/core.c: In function 'dwc3_core_get_phy':
> > > > > drivers/usb/dwc3/core.c:1482:69: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 4 [-Wformat-truncation=]
> > >      1482 |                         snprintf(phy_name, sizeof(phy_name),  "usb2-%d", i);
> > >           |                                                                     ^~
> > >     drivers/usb/dwc3/core.c:1482:63: note: directive argument in the range [-2147483641, 254]
> > >      1482 |                         snprintf(phy_name, sizeof(phy_name),  "usb2-%d", i);
> > 
> > This version or s390-build of gcc appears to be confused as the
> > variable i is clearly in the range [0,254] in these for loops.
> > 
> > I also don't see this W=1 warning with my gcc-10 (aarch64).
> > 
> > It may be possible to work around this by using u8 type for the iterator
> > (and %u in the format), but I'm not sure we should be working around
> > compiler bugs like that.
> 
> Thanks Johan. i agree it looks like a bogus compiler warning, but I think
> your suggestion of changing to u8 should work, if only to placate the
> compiler.
> 
> Greg, do you think I should go ahead and update it in v22 or can we ignore
> this warning ?

Please send a follow-on patch to fix this, I'll leave it as-is in my
tree for now.

thanks,

greg k-h

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

end of thread, other threads:[~2024-04-25 15:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-24  5:03 [usb:usb-testing 7/12] drivers/usb/dwc3/core.c:1482:69: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 4 kernel test robot
2024-04-24  6:41 ` Johan Hovold
2024-04-25  5:08   ` Krishna Kurapati PSSNV
2024-04-25 15:18     ` Greg Kroah-Hartman

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).