Skip to content

Commit 21ab799

Browse files
committed
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: kernel test robot <[email protected]> Link: https://lore.kernel.org/r/[email protected]/ Link: https://lore.kernel.org/r/163840226123.138003.7668320168896210328.stgit@omen Signed-off-by: Alex Williamson <[email protected]>
1 parent a7904a5 commit 21ab799

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

drivers/vfio/pci/vfio_pci_igd.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,14 @@ static ssize_t vfio_pci_igd_cfg_rw(struct vfio_pci_core_device *vdev,
309309

310310
if ((pos & 3) && size > 2) {
311311
u16 val;
312+
__le16 lval;
312313

313314
ret = pci_user_read_config_word(pdev, pos, &val);
314315
if (ret)
315316
return ret;
316317

317-
val = cpu_to_le16(val);
318-
if (copy_to_user(buf + count - size, &val, 2))
318+
lval = cpu_to_le16(val);
319+
if (copy_to_user(buf + count - size, &lval, 2))
319320
return -EFAULT;
320321

321322
pos += 2;
@@ -324,13 +325,14 @@ static ssize_t vfio_pci_igd_cfg_rw(struct vfio_pci_core_device *vdev,
324325

325326
while (size > 3) {
326327
u32 val;
328+
__le32 lval;
327329

328330
ret = pci_user_read_config_dword(pdev, pos, &val);
329331
if (ret)
330332
return ret;
331333

332-
val = cpu_to_le32(val);
333-
if (copy_to_user(buf + count - size, &val, 4))
334+
lval = cpu_to_le32(val);
335+
if (copy_to_user(buf + count - size, &lval, 4))
334336
return -EFAULT;
335337

336338
pos += 4;
@@ -339,13 +341,14 @@ static ssize_t vfio_pci_igd_cfg_rw(struct vfio_pci_core_device *vdev,
339341

340342
while (size >= 2) {
341343
u16 val;
344+
__le16 lval;
342345

343346
ret = pci_user_read_config_word(pdev, pos, &val);
344347
if (ret)
345348
return ret;
346349

347-
val = cpu_to_le16(val);
348-
if (copy_to_user(buf + count - size, &val, 2))
350+
lval = cpu_to_le16(val);
351+
if (copy_to_user(buf + count - size, &lval, 2))
349352
return -EFAULT;
350353

351354
pos += 2;

0 commit comments

Comments
 (0)