[bug report] vdpa: set the virtqueue num during register

Started by Dan Carpenter on Feb 25, 2021

open the first message on its own page

Message details and related content
Hello Jason Wang,

The patch ddd50f4495d3: "vdpa: set the virtqueue num during register"
from Feb 23, 2021, leads to the following static checker warning:

	drivers/vdpa/ifcvf/ifcvf_main.c:433 ifcvf_probe()
	warn: risky error pointer math: '__vdpa_alloc_device(dev, &ifc_vdpa_ops, 2592 + (0), (0)))'

include/linux/vdpa.h
   255  #define vdpa_alloc_device(dev_struct, member, parent, config, name)   \
   256                            container_of(__vdpa_alloc_device( \
   257                                         parent, config, \
   258                                         sizeof(dev_struct) + \
   259                                         BUILD_BUG_ON_ZERO(offsetof( \
   260                                         dev_struct, member)), name), \
   261                                         dev_struct, member)
   262  

The __vdpa_alloc_device() returns an error pointer and if we call
container_of() on then that's a bug...  (Unless the container_of() is
known to be a no-op, in which case it's sort of ugly but fine, I guess.
There is one caller where this is the case.).

drivers/vdpa/ifcvf/ifcvf_main.c
   432  
   433          adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa,
   434                                      dev, &ifc_vdpa_ops, NULL);
   435          if (adapter == NULL) {

All the other caller check for NULL.  :P

   436                  IFCVF_ERR(pdev, "Failed to allocate vDPA structure");
   437                  return -ENOMEM;
   438          }
   439  
   440          pci_set_master(pdev);
   441          pci_set_drvdata(pdev, adapter);
   442  

regards,
dan carpenter
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help