提交 21ab7995 编写于 作者: A Alex Williamson

vfio/pci: Resolve sparse endian warnings in IGD support

Sparse warns:

sparse warnings: (new ones prefixed by >>)
>> drivers/vfio/pci/vfio_pci_igd.c:146:21: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned short [addressable] [usertype] val @@     got restricted __le16 [usertype] @@
   drivers/vfio/pci/vfio_pci_igd.c:146:21: sparse:     expected unsigned short [addressable] [usertype] val
   drivers/vfio/pci/vfio_pci_igd.c:146:21: sparse:     got restricted __le16 [usertype]
>> drivers/vfio/pci/vfio_pci_igd.c:161:21: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned int [addressable] [usertype] val @@     got restricted __le32 [usertype] @@
   drivers/vfio/pci/vfio_pci_igd.c:161:21: sparse:     expected unsigned int [addressable] [usertype] val
   drivers/vfio/pci/vfio_pci_igd.c:161:21: sparse:     got restricted __le32 [usertype]
   drivers/vfio/pci/vfio_pci_igd.c:176:21: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned short [addressable] [usertype] val @@     got restricted __le16 [usertype] @@
   drivers/vfio/pci/vfio_pci_igd.c:176:21: sparse:     expected unsigned short [addressable] [usertype] val
   drivers/vfio/pci/vfio_pci_igd.c:176:21: sparse:     got restricted __le16 [usertype]

These are due to trying to use an unsigned to store the result of
a cpu_to_leXX() conversion.  These are small variables, so pointer
tricks are wasteful and casting just generates different sparse
warnings.  Store to and copy results from a separate little endian
variable.
Reported-by: Nkernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/r/202111290026.O3vehj03-lkp@intel.com/
Link: https://lore.kernel.org/r/163840226123.138003.7668320168896210328.stgit@omenSigned-off-by: NAlex Williamson <alex.williamson@redhat.com>
上级 a7904a53
...@@ -309,13 +309,14 @@ static ssize_t vfio_pci_igd_cfg_rw(struct vfio_pci_core_device *vdev, ...@@ -309,13 +309,14 @@ static ssize_t vfio_pci_igd_cfg_rw(struct vfio_pci_core_device *vdev,
if ((pos & 3) && size > 2) { if ((pos & 3) && size > 2) {
u16 val; u16 val;
__le16 lval;
ret = pci_user_read_config_word(pdev, pos, &val); ret = pci_user_read_config_word(pdev, pos, &val);
if (ret) if (ret)
return ret; return ret;
val = cpu_to_le16(val); lval = cpu_to_le16(val);
if (copy_to_user(buf + count - size, &val, 2)) if (copy_to_user(buf + count - size, &lval, 2))
return -EFAULT; return -EFAULT;
pos += 2; pos += 2;
...@@ -324,13 +325,14 @@ static ssize_t vfio_pci_igd_cfg_rw(struct vfio_pci_core_device *vdev, ...@@ -324,13 +325,14 @@ static ssize_t vfio_pci_igd_cfg_rw(struct vfio_pci_core_device *vdev,
while (size > 3) { while (size > 3) {
u32 val; u32 val;
__le32 lval;
ret = pci_user_read_config_dword(pdev, pos, &val); ret = pci_user_read_config_dword(pdev, pos, &val);
if (ret) if (ret)
return ret; return ret;
val = cpu_to_le32(val); lval = cpu_to_le32(val);
if (copy_to_user(buf + count - size, &val, 4)) if (copy_to_user(buf + count - size, &lval, 4))
return -EFAULT; return -EFAULT;
pos += 4; pos += 4;
...@@ -339,13 +341,14 @@ static ssize_t vfio_pci_igd_cfg_rw(struct vfio_pci_core_device *vdev, ...@@ -339,13 +341,14 @@ static ssize_t vfio_pci_igd_cfg_rw(struct vfio_pci_core_device *vdev,
while (size >= 2) { while (size >= 2) {
u16 val; u16 val;
__le16 lval;
ret = pci_user_read_config_word(pdev, pos, &val); ret = pci_user_read_config_word(pdev, pos, &val);
if (ret) if (ret)
return ret; return ret;
val = cpu_to_le16(val); lval = cpu_to_le16(val);
if (copy_to_user(buf + count - size, &val, 2)) if (copy_to_user(buf + count - size, &lval, 2))
return -EFAULT; return -EFAULT;
pos += 2; pos += 2;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册