Skip to contentSkip to conversation

xen/PCI: address violations of MISRA C:2012 Rules 8.2 and 8.3

PATCH In review Federico Serafini 2 participants 4 messages Sep 11, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/PCI: address violations of MISRA C:2012 Rules 8.2 and 8.3

Add missing parameter names and make function declarations and definitions consistent. No functional change.

---
 xen/include/xen/pci.h | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
xen/include/xen/pci.h +12 -11
index 7d8a7cd213..3ed79d15cd 100644
@@ -166,14 +166,14 @@ int scan_pci_devices(void);
 enum pdev_type pdev_type(u16 seg, u8 bus, u8 devfn);
 int find_upstream_bridge(u16 seg, u8 *bus, u8 *devfn, u8 *secbus);
 
-void setup_hwdom_pci_devices(struct domain *,
-                            int (*)(u8 devfn, struct pci_dev *));
+void setup_hwdom_pci_devices(struct domain *d,
+                            int (*handler)(u8 devfn, struct pci_dev *pdev));
 int pci_release_devices(struct domain *d);
 void pci_segments_init(void);
 int pci_add_segment(u16 seg);
 const unsigned long *pci_get_ro_map(u16 seg);
 int pci_add_device(u16 seg, u8 bus, u8 devfn,
-                   const struct pci_dev_info *, nodeid_t node);
+                   const struct pci_dev_info *info, nodeid_t node);
 int pci_remove_device(u16 seg, u8 bus, u8 devfn);
 int pci_ro_device(int seg, int bus, int devfn);
 int pci_hide_device(unsigned int seg, unsigned int bus, unsigned int devfn);
@@ -198,10 +198,11 @@ int pci_find_next_cap(u16 seg, u8 bus, unsigned int devfn, u8 pos, int cap);
 int pci_find_ext_capability(int seg, int bus, int devfn, int cap);
 int pci_find_next_ext_capability(int seg, int bus, int devfn, int start,
                                  int cap);
-const char *parse_pci(const char *, unsigned int *seg, unsigned int *bus,
-                      unsigned int *dev, unsigned int *func);
-const char *parse_pci_seg(const char *, unsigned int *seg, unsigned int *bus,
-                          unsigned int *dev, unsigned int *func, bool *def_seg);
+const char *parse_pci(const char *s, unsigned int *seg_p, unsigned int *bus_p,
+                      unsigned int *dev_p, unsigned int *func_p);
+const char *parse_pci_seg(const char *s, unsigned int *seg_p,
+                          unsigned int *bus_p, unsigned int *dev_p,
+                          unsigned int *func_p, bool *def_seg);
 
 #define PCI_BAR_VF      (1u << 0)
 #define PCI_BAR_LAST    (1u << 1)
@@ -210,12 +211,12 @@ unsigned int pci_size_mem_bar(pci_sbdf_t sbdf, unsigned int pos,
                               uint64_t *paddr, uint64_t *psize,
                               unsigned int flags);
 
-void pci_intx(const struct pci_dev *, bool enable);
-bool pcie_aer_get_firmware_first(const struct pci_dev *);
+void pci_intx(const struct pci_dev *pdev, bool enable);
+bool pcie_aer_get_firmware_first(const struct pci_dev *pdev);
 
 struct pirq;
-int msixtbl_pt_register(struct domain *, struct pirq *, uint64_t gtable);
-void msixtbl_pt_unregister(struct domain *, struct pirq *);
+int msixtbl_pt_register(struct domain *d, struct pirq *pirq, uint64_t gtable);
+void msixtbl_pt_unregister(struct domain *d, struct pirq *pirq);
 void msixtbl_pt_cleanup(struct domain *d);
 
 #ifdef CONFIG_HVM
Signature · 1 line
2.34.1
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Federico Serafini

Add missing parameter names and make function declarations and definitions consistent. No functional change.

Since formally correct:

Nevertheless, it is probably about time to mention that ...

xen/include/xen/pci.h int pci_find_next_cap(u16 seg, u8 bus, unsigned int devfn, u8 pos, int cap); · line 205

Quoted 13 lines
xen/include/xen/pci.h +5 -4
@@ -198,10 +198,11 @@ int pci_find_next_cap(u16 seg, u8 bus, unsigned int devfn, u8 pos, int cap);
 int pci_find_ext_capability(int seg, int bus, int devfn, int cap);
 int pci_find_next_ext_capability(int seg, int bus, int devfn, int start,
                                  int cap);
-const char *parse_pci(const char *, unsigned int *seg, unsigned int *bus,
-                      unsigned int *dev, unsigned int *func);
-const char *parse_pci_seg(const char *, unsigned int *seg, unsigned int *bus,
-                          unsigned int *dev, unsigned int *func, bool *def_seg);
+const char *parse_pci(const char *s, unsigned int *seg_p, unsigned int *bus_p,
+                      unsigned int *dev_p, unsigned int *func_p);
+const char *parse_pci_seg(const char *s, unsigned int *seg_p,
+                          unsigned int *bus_p, unsigned int *dev_p,
+                          unsigned int *func_p, bool *def_seg);

... parameter renaming like this, while fulfilling the word of Misra, is actually hampering readability. To someone wanting to use the function and hence looking at the declaration it is entirely uninteresting whether the _p suffixes are there; there were similar changes earlier on. The longer names merely make reading harder and - as is the case here - also may require a single declaration to wrap across more lines. I view such as going against the spirit of Misra (aiming to improve code clarity).

Jan

#2 lore raw
Quoted 34 lines · Jan Beulich
Quoted 4 lines · Federico Serafini

Add missing parameter names and make function declarations and definitions consistent. No functional change.

Since formally correct:

Nevertheless, it is probably about time to mention that ...

xen/include/xen/pci.h int pci_find_next_cap(u16 seg, u8 bus, unsigned int devfn, u8 pos, int cap); · line 205

Quoted 13 lines
xen/include/xen/pci.h +5 -4
@@ -198,10 +198,11 @@ int pci_find_next_cap(u16 seg, u8 bus, unsigned int devfn, u8 pos, int cap);
  int pci_find_ext_capability(int seg, int bus, int devfn, int cap);
  int pci_find_next_ext_capability(int seg, int bus, int devfn, int start,
                                   int cap);
-const char *parse_pci(const char *, unsigned int *seg, unsigned int *bus,
-                      unsigned int *dev, unsigned int *func);
-const char *parse_pci_seg(const char *, unsigned int *seg, unsigned int *bus,
-                          unsigned int *dev, unsigned int *func, bool *def_seg);
+const char *parse_pci(const char *s, unsigned int *seg_p, unsigned int *bus_p,
+                      unsigned int *dev_p, unsigned int *func_p);
+const char *parse_pci_seg(const char *s, unsigned int *seg_p,
+                          unsigned int *bus_p, unsigned int *dev_p,
+                          unsigned int *func_p, bool *def_seg);

... parameter renaming like this, while fulfilling the word of Misra, is actually hampering readability. To someone wanting to use the function and hence looking at the declaration it is entirely uninteresting whether the _p suffixes are there; there were similar changes earlier on. The longer names merely make reading harder and - as is the case here - also may require a single declaration to wrap across more lines. I view such as going against the spirit of Misra (aiming to improve code clarity).

Quoted 2 lines

Jan

I agree with you, but, the removal of _p would lead to other (mechanical) changes to the function body.
In such cases, do you think that an improvement in readability justifies the code churn?

Signature · 3 lines
Federico Serafini, M.Sc.

Software Engineer, BUGSENG (http://bugseng.com)
#3 lore raw
Quoted 35 lines · Federico Serafini
Quoted 25 lines · Jan Beulich
Quoted 4 lines · Federico Serafini

Add missing parameter names and make function declarations and definitions consistent. No functional change.

Since formally correct:

Nevertheless, it is probably about time to mention that ...

xen/include/xen/pci.h int pci_find_next_cap(u16 seg, u8 bus, unsigned int devfn, u8 pos, int cap); · line 205

Quoted 13 lines
xen/include/xen/pci.h +5 -4
@@ -198,10 +198,11 @@ int pci_find_next_cap(u16 seg, u8 bus, unsigned int devfn, u8 pos, int cap);
  int pci_find_ext_capability(int seg, int bus, int devfn, int cap);
  int pci_find_next_ext_capability(int seg, int bus, int devfn, int start,
                                   int cap);
-const char *parse_pci(const char *, unsigned int *seg, unsigned int *bus,
-                      unsigned int *dev, unsigned int *func);
-const char *parse_pci_seg(const char *, unsigned int *seg, unsigned int *bus,
-                          unsigned int *dev, unsigned int *func, bool *def_seg);
+const char *parse_pci(const char *s, unsigned int *seg_p, unsigned int *bus_p,
+                      unsigned int *dev_p, unsigned int *func_p);
+const char *parse_pci_seg(const char *s, unsigned int *seg_p,
+                          unsigned int *bus_p, unsigned int *dev_p,
+                          unsigned int *func_p, bool *def_seg);
Quoted 8 lines

... parameter renaming like this, while fulfilling the word of Misra, is actually hampering readability. To someone wanting to use the function and hence looking at the declaration it is entirely uninteresting whether the _p suffixes are there; there were similar changes earlier on. The longer names merely make reading harder and - as is the case here - also may require a single declaration to wrap across more lines. I view such as going against the spirit of Misra (aiming to improve code clarity).

Quoted 4 lines

I agree with you, but, the removal of _p would lead to other (mechanical) changes to the function body.
In such cases, do you think that an improvement in readability justifies the code churn?

I didn't suggest changing the definition. I suggested keeping declaration and definition (slightly) out of sync.

Jan