hv: fix MISRA-C violations in vpci code: 93S, 331S and 612S

- 331S: Literal value requires a U suffix.
- 612S: inline function should be declared static.
- 93S: Value is not of appropriate type. MISRA-C imposes strict type
  checking: no comparison between signed and unsigned, etc.

Tracked-On: #861
Signed-off-by: Zide Chen <zide.chen@intel.com>
Reviewed-by: Huihuang Shi <huihuang.shi@intel.com>
This commit is contained in:
Zide Chen 2018-11-06 22:09:15 -08:00 committed by wenlingz
parent f84f1a216b
commit d3f0edfe4f
6 changed files with 11 additions and 14 deletions

View File

@ -30,7 +30,7 @@
#include <hypervisor.h> #include <hypervisor.h>
#include "pci_priv.h" #include "pci_priv.h"
inline uint32_t pci_vdev_read_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes) uint32_t pci_vdev_read_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes)
{ {
uint32_t val; uint32_t val;
@ -49,7 +49,7 @@ inline uint32_t pci_vdev_read_cfg(struct pci_vdev *vdev, uint32_t offset, uint32
return val; return val;
} }
inline void pci_vdev_write_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val) void pci_vdev_write_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val)
{ {
switch (bytes) { switch (bytes) {
case 1U: case 1U:

View File

@ -216,7 +216,7 @@ void populate_msi_struct(struct pci_vdev *vdev)
static int vmsi_deinit(struct pci_vdev *vdev) static int vmsi_deinit(struct pci_vdev *vdev)
{ {
if (vdev->msi.capoff != 0U) { if (vdev->msi.capoff != 0U) {
ptdev_remove_msix_remapping(vdev->vpci->vm, vdev->vbdf.value, 1); ptdev_remove_msix_remapping(vdev->vpci->vm, vdev->vbdf.value, 1U);
} }
return 0; return 0;

View File

@ -242,14 +242,14 @@ static int vmsix_table_mmio_access_handler(struct io_request *io_req, void *hand
{ {
struct mmio_request *mmio = &io_req->reqs.mmio; struct mmio_request *mmio = &io_req->reqs.mmio;
struct pci_vdev *vdev; struct pci_vdev *vdev;
uint32_t offset; uint64_t offset;
uint64_t hva; uint64_t hva;
vdev = (struct pci_vdev *)handler_private_data; vdev = (struct pci_vdev *)handler_private_data;
offset = (uint32_t)(mmio->address - vdev->msix.mmio_gpa); offset = mmio->address - vdev->msix.mmio_gpa;
if (msixtable_access(vdev, offset)) { if (msixtable_access(vdev, (uint32_t)offset)) {
vmsix_table_rw(vdev, mmio, offset); vmsix_table_rw(vdev, mmio, (uint32_t)offset);
} else { } else {
hva = vdev->msix.mmio_hva + offset; hva = vdev->msix.mmio_hva + offset;

View File

@ -63,7 +63,7 @@ static int partition_mode_vpci_init(struct acrn_vm *vm)
vdev->vpci = vpci; vdev->vpci = vpci;
if ((vdev->ops != NULL) && (vdev->ops->init != NULL)) { if ((vdev->ops != NULL) && (vdev->ops->init != NULL)) {
if (vdev->ops->init(vdev) != 0U) { if (vdev->ops->init(vdev) != 0) {
pr_err("%s() failed at PCI device (bdf %x)!", __func__, pr_err("%s() failed at PCI device (bdf %x)!", __func__,
vdev->vbdf); vdev->vbdf);
} }
@ -84,7 +84,7 @@ static void partition_mode_vpci_deinit(struct acrn_vm *vm)
for (i = 0; i < vdev_array->num_pci_vdev; i++) { for (i = 0; i < vdev_array->num_pci_vdev; i++) {
vdev = &vdev_array->vpci_vdev_list[i]; vdev = &vdev_array->vpci_vdev_list[i];
if ((vdev->ops != NULL) && (vdev->ops->deinit != NULL)) { if ((vdev->ops != NULL) && (vdev->ops->deinit != NULL)) {
if (vdev->ops->deinit(vdev) != 0U) { if (vdev->ops->deinit(vdev) != 0) {
pr_err("vdev->ops->deinit failed!"); pr_err("vdev->ops->deinit failed!");
} }
} }

View File

@ -41,7 +41,7 @@ static int vdev_pt_init_validate(struct pci_vdev *vdev)
{ {
uint32_t idx; uint32_t idx;
for (idx = 0; idx < (uint32_t)PCI_BAR_COUNT; idx++) { for (idx = 0U; idx < PCI_BAR_COUNT; idx++) {
if ((vdev->bar[idx].base != 0x0UL) if ((vdev->bar[idx].base != 0x0UL)
|| ((vdev->bar[idx].size & 0xFFFUL) != 0x0UL) || ((vdev->bar[idx].size & 0xFFFUL) != 0x0UL)
|| ((vdev->bar[idx].type != PCIBAR_MEM32) || ((vdev->bar[idx].type != PCIBAR_MEM32)

View File

@ -91,10 +91,7 @@ static void pci_cfg_io_write(struct acrn_vm *vm, uint16_t addr, size_t bytes,
if (is_cfg_addr(addr)) { if (is_cfg_addr(addr)) {
/* TODO: handling the non 4 bytes access */ /* TODO: handling the non 4 bytes access */
if (bytes == 4U) { if (bytes == 4U) {
pi->cached_bdf.bits.b = (uint8_t)(val >> 16U) & PCI_BUSMAX; pi->cached_bdf.value = (uint16_t)(val >> 8U);
pi->cached_bdf.bits.d = (uint8_t)(val >> 11U) & PCI_SLOTMAX;
pi->cached_bdf.bits.f = (uint8_t)(val >> 8U) & PCI_FUNCMAX;
pi->cached_reg = val & PCI_REGMAX; pi->cached_reg = val & PCI_REGMAX;
pi->cached_enable = ((val & PCI_CFG_ENABLE) == PCI_CFG_ENABLE); pi->cached_enable = ((val & PCI_CFG_ENABLE) == PCI_CFG_ENABLE);
} }