Skip to content

Commit 927c517

Browse files
ZideChen0wenlingz
authored andcommitted
hv: vpci: fix MISRA-C violations related to variable declarations
78D: Global variable should be declared const. Global variables should be declared constant wherever possible to avoid unintentional modification. 27D: Variable should be declared static pci_ops_vdev_msi is not accessed by other files. Remove the declaration from the header and define it with the static qualifier; Because it's referenced by populate_msi_struct(), so move the define statements forward. 33D: No real declaration for external variable certain variables are available in sharing mode or partition mode only, so that the declarations in header files must be enclosed with CONFIG_PARTITION_MODE Tracked-On: #861 Signed-off-by: Zide Chen <zide.chen@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
1 parent 4c28e98 commit 927c517

File tree

8 files changed

+34
-29
lines changed

8 files changed

+34
-29
lines changed

hypervisor/dm/vpci/hostbridge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static int32_t vdev_hostbridge_cfgwrite(struct pci_vdev *vdev, uint32_t offset,
118118
return 0;
119119
}
120120

121-
struct pci_vdev_ops pci_ops_vdev_hostbridge = {
121+
const struct pci_vdev_ops pci_ops_vdev_hostbridge = {
122122
.init = vdev_hostbridge_init,
123123
.deinit = vdev_hostbridge_deinit,
124124
.cfgwrite = vdev_hostbridge_cfgwrite,

hypervisor/dm/vpci/msi.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ static int32_t vmsi_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t by
151151
return ret;
152152
}
153153

154+
static int32_t vmsi_deinit(struct pci_vdev *vdev)
155+
{
156+
if (vdev->msi.capoff != 0U) {
157+
ptirq_remove_msix_remapping(vdev->vpci->vm, vdev->vbdf.value, 1U);
158+
}
159+
160+
return 0;
161+
}
162+
163+
static const struct pci_vdev_ops pci_ops_vdev_msi = {
164+
.deinit = vmsi_deinit,
165+
.cfgwrite = vmsi_cfgwrite,
166+
.cfgread = vmsi_cfgread,
167+
};
168+
154169
void populate_msi_struct(struct pci_vdev *vdev)
155170
{
156171
uint8_t ptr, cap;
@@ -216,17 +231,3 @@ void populate_msi_struct(struct pci_vdev *vdev)
216231
}
217232
}
218233

219-
static int32_t vmsi_deinit(struct pci_vdev *vdev)
220-
{
221-
if (vdev->msi.capoff != 0U) {
222-
ptirq_remove_msix_remapping(vdev->vpci->vm, vdev->vbdf.value, 1U);
223-
}
224-
225-
return 0;
226-
}
227-
228-
struct pci_vdev_ops pci_ops_vdev_msi = {
229-
.deinit = vmsi_deinit,
230-
.cfgwrite = vmsi_cfgwrite,
231-
.cfgread = vmsi_cfgread,
232-
};

hypervisor/dm/vpci/msix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ static int32_t vmsix_deinit(struct pci_vdev *vdev)
425425
return 0;
426426
}
427427

428-
struct pci_vdev_ops pci_ops_vdev_msix = {
428+
const struct pci_vdev_ops pci_ops_vdev_msix = {
429429
.init = vmsix_init,
430430
.deinit = vmsix_deinit,
431431
.cfgwrite = vmsix_cfgwrite,

hypervisor/dm/vpci/partition_mode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static void partition_mode_cfgwrite(struct acrn_vpci *vpci, union pci_bdf vbdf,
111111
}
112112
}
113113

114-
struct vpci_ops partition_mode_vpci_ops = {
114+
const struct vpci_ops partition_mode_vpci_ops = {
115115
.init = partition_mode_vpci_init,
116116
.deinit = partition_mode_vpci_deinit,
117117
.cfgread = partition_mode_cfgread,

hypervisor/dm/vpci/pci_priv.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,19 @@ static inline void pci_vdev_write_cfg_u32(struct pci_vdev *vdev, uint32_t offset
6767
vdev->cfgdata.data_32[offset >> 2U] = val;
6868
}
6969

70-
extern struct vpci_ops partition_mode_vpci_ops;
71-
extern struct vpci_ops sharing_mode_vpci_ops;
72-
extern struct pci_vdev_ops pci_ops_vdev_msi;
73-
extern struct pci_vdev_ops pci_ops_vdev_msix;
70+
#ifdef CONFIG_PARTITION_MODE
71+
extern const struct vpci_ops partition_mode_vpci_ops;
72+
#else
73+
extern const struct vpci_ops sharing_mode_vpci_ops;
74+
extern const struct pci_vdev_ops pci_ops_vdev_msix;
75+
#endif
7476

7577
uint32_t pci_vdev_read_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes);
7678
void pci_vdev_write_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
7779

7880
void populate_msi_struct(struct pci_vdev *vdev);
7981

8082
struct pci_vdev *sharing_mode_find_vdev(union pci_bdf pbdf);
81-
void add_vdev_handler(struct pci_vdev *vdev, struct pci_vdev_ops *ops);
83+
void add_vdev_handler(struct pci_vdev *vdev, const struct pci_vdev_ops *ops);
8284

8385
#endif /* PCI_PRIV_H_ */

hypervisor/dm/vpci/pci_pt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static int32_t vdev_pt_cfgwrite(struct pci_vdev *vdev, uint32_t offset,
195195
return 0;
196196
}
197197

198-
struct pci_vdev_ops pci_ops_vdev_pt = {
198+
const struct pci_vdev_ops pci_ops_vdev_pt = {
199199
.init = vdev_pt_init,
200200
.deinit = vdev_pt_deinit,
201201
.cfgwrite = vdev_pt_cfgwrite,

hypervisor/dm/vpci/sharing_mode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static void sharing_mode_vpci_deinit(__unused struct acrn_vm *vm)
183183
}
184184
}
185185

186-
void add_vdev_handler(struct pci_vdev *vdev, struct pci_vdev_ops *ops)
186+
void add_vdev_handler(struct pci_vdev *vdev, const struct pci_vdev_ops *ops)
187187
{
188188
if (vdev->nr_ops >= (MAX_VPCI_DEV_OPS - 1U)) {
189189
pr_err("%s, adding too many handlers", __func__);
@@ -193,7 +193,7 @@ void add_vdev_handler(struct pci_vdev *vdev, struct pci_vdev_ops *ops)
193193
}
194194
}
195195

196-
struct vpci_ops sharing_mode_vpci_ops = {
196+
const struct vpci_ops sharing_mode_vpci_ops = {
197197
.init = sharing_mode_vpci_init,
198198
.deinit = sharing_mode_vpci_deinit,
199199
.cfgread = sharing_mode_cfgread,

hypervisor/include/dm/vpci.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct pci_vdev {
9898
struct pci_vdev_ops ops[MAX_VPCI_DEV_OPS];
9999
uint32_t nr_ops;
100100
#else
101-
struct pci_vdev_ops *ops;
101+
const struct pci_vdev_ops *ops;
102102
#endif
103103

104104
struct acrn_vpci *vpci;
@@ -137,11 +137,13 @@ struct vpci_ops {
137137
struct acrn_vpci {
138138
struct acrn_vm *vm;
139139
struct pci_addr_info addr_info;
140-
struct vpci_ops *ops;
140+
const struct vpci_ops *ops;
141141
};
142142

143-
extern struct pci_vdev_ops pci_ops_vdev_hostbridge;
144-
extern struct pci_vdev_ops pci_ops_vdev_pt;
143+
#ifdef CONFIG_PARTITION_MODE
144+
extern const struct pci_vdev_ops pci_ops_vdev_hostbridge;
145+
extern const struct pci_vdev_ops pci_ops_vdev_pt;
146+
#endif
145147

146148
void vpci_init(struct acrn_vm *vm);
147149
void vpci_cleanup(struct acrn_vm *vm);

0 commit comments

Comments
 (0)