Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up -Wextra warnings #80

Open
tyreld opened this issue Mar 14, 2022 · 3 comments
Open

clean up -Wextra warnings #80

tyreld opened this issue Mar 14, 2022 · 3 comments
Assignees

Comments

@tyreld
Copy link
Member

tyreld commented Mar 14, 2022

Enabling -Wextra in the build generates a fair number of warning worth cleaning up.

src/nvram.c:671:20: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
  671 |     for (i = 0; (i < sizeof(descs) / sizeof(descs[0])); i++) {
      |                    ^
src/nvram.c: In function ‘print_of_config_part’:
src/nvram.c:1189:19: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
 1189 |     for (i = 0; i <= (strlen(pname) + 14); i++)
      |                   ^~
src/lparstat.c: In function ‘sig_int_handler’:
src/lparstat.c:229:33: warning: unused parameter ‘signal’ [-Wunused-parameter]
  229 | static void sig_int_handler(int signal)
      |                             ~~~~^~~~~~
src/lparstat.c: In function ‘get_sys_uptime’:
src/lparstat.c:309:38: warning: unused parameter ‘unused_se’ [-Wunused-parameter]
  309 | void get_sys_uptime(struct sysentry *unused_se, char *uptime)
      |                     ~~~~~~~~~~~~~~~~~^~~~~~~~~
src/lparstat.c: In function ‘get_cpu_physc’:
src/lparstat.c:389:37: warning: unused parameter ‘unused_se’ [-Wunused-parameter]
  389 | void get_cpu_physc(struct sysentry *unused_se, char *buf)
      |                    ~~~~~~~~~~~~~~~~~^~~~~~~~~
src/lparstat.c: In function ‘get_per_entc’:
src/lparstat.c:417:36: warning: unused parameter ‘unused_se’ [-Wunused-parameter]
  417 | void get_per_entc(struct sysentry *unused_se, char *buf)
      |                   ~~~~~~~~~~~~~~~~~^~~~~~~~~
src/lparstat.c: In function ‘get_cpu_app’:
src/lparstat.c:429:35: warning: unused parameter ‘unused_se’ [-Wunused-parameter]
  429 | void get_cpu_app(struct sysentry *unused_se, char *buf)
      |                  ~~~~~~~~~~~~~~~~~^~~~~~~~~
src/lparstat.c: In function ‘get_cpu_util_purr’:
src/lparstat.c:484:41: warning: unused parameter ‘unused_se’ [-Wunused-parameter]
  484 | void get_cpu_util_purr(struct sysentry *unused_se, char *buf)
      |                        ~~~~~~~~~~~~~~~~~^~~~~~~~~
src/lparstat.c: In function ‘get_cpu_idle_purr’:
src/lparstat.c:499:41: warning: unused parameter ‘unused_se’ [-Wunused-parameter]
  499 | void get_cpu_idle_purr(struct sysentry *unused_se, char *buf)
      |                        ~~~~~~~~~~~~~~~~~^~~~~~~~~
src/lparstat.c: In function ‘get_cpu_util_spurr’:
src/lparstat.c:515:42: warning: unused parameter ‘unused_se’ [-Wunused-parameter]
  515 | void get_cpu_util_spurr(struct sysentry *unused_se, char *buf)
      |                         ~~~~~~~~~~~~~~~~~^~~~~~~~~
src/lparstat.c: In function ‘get_cpu_idle_spurr’:
src/lparstat.c:533:42: warning: unused parameter ‘unused_se’ [-Wunused-parameter]
  533 | void get_cpu_idle_spurr(struct sysentry *unused_se, char *buf)
      |                         ~~~~~~~~~~~~~~~~~^~~~~~~~~
src/lparstat.c: In function ‘get_phys_cpu_percentage’:
src/lparstat.c:727:47: warning: unused parameter ‘se’ [-Wunused-parameter]
  727 | void get_phys_cpu_percentage(struct sysentry *se, char *buf)
      |                              ~~~~~~~~~~~~~~~~~^~
src/lparstat.c: In function ‘get_active_cpus_in_pool’:
src/lparstat.c:741:47: warning: unused parameter ‘se’ [-Wunused-parameter]
  741 | void get_active_cpus_in_pool(struct sysentry *se, char *buf)
      |                              ~~~~~~~~~~~~~~~~~^~
src/lparstat.c: In function ‘get_memory_mode’:
src/lparstat.c:754:39: warning: unused parameter ‘se’ [-Wunused-parameter]
  754 | void get_memory_mode(struct sysentry *se, char *buf)
      |                      ~~~~~~~~~~~~~~~~~^~
src/lparstat.c: In function ‘get_node_name’:
src/lparstat.c:783:37: warning: unused parameter ‘se’ [-Wunused-parameter]
  783 | void get_node_name(struct sysentry *se, char *buf)
      |                    ~~~~~~~~~~~~~~~~~^~
src/lparstat.c: In function ‘get_mem_total’:
src/lparstat.c:805:37: warning: unused parameter ‘se’ [-Wunused-parameter]
  805 | void get_mem_total(struct sysentry *se, char *buf)
      |                    ~~~~~~~~~~~~~~~~~^~
src/lparstat.c: In function ‘get_smt_mode’:
src/lparstat.c:847:36: warning: unused parameter ‘se’ [-Wunused-parameter]
  847 | void get_smt_mode(struct sysentry *se, char *buf)
      |                   ~~~~~~~~~~~~~~~~~^~
src/ppc64_cpu.c: In function ‘setrlimit_open_files’:
src/ppc64_cpu.c:781:31: warning: comparison of integer expressions of different signedness: ‘rlim_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
  781 |         if (old_rlim.rlim_cur > new)
      |                               ^
src/vcpustat.c: In function ‘sighandler’:
src/vcpustat.c:344:28: warning: unused parameter ‘signum’ [-Wunused-parameter]
  344 | static void sighandler(int signum)
      |                        ~~~~^~~~~~
src/uesensor.c: In function ‘main’:
src/uesensor.c:441:47: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
  441 |                                 for (i = 0; i <= max_index; i++) {
      |                                               ^~
src/errinjct/open_close.c: In function ‘ei_open_arg’:
src/errinjct/open_close.c:53:22: warning: unused parameter ‘arg’ [-Wunused-parameter]
   53 | int ei_open_arg(char arg, char *optarg)
      |                 ~~~~~^~~
src/errinjct/open_close.c:53:33: warning: unused parameter ‘optarg’ [-Wunused-parameter]
   53 | int ei_open_arg(char arg, char *optarg)
      |                           ~~~~~~^~~~~~
src/errinjct/open_close.c: In function ‘ei_close_arg’:
src/errinjct/open_close.c:118:23: warning: unused parameter ‘arg’ [-Wunused-parameter]
  118 | int ei_close_arg(char arg, char *optarg)
      |                  ~~~~~^~~
src/errinjct/open_close.c:118:34: warning: unused parameter ‘optarg’ [-Wunused-parameter]
  118 | int ei_close_arg(char arg, char *optarg)
      |                            ~~~~~~^~~~~~
src/errinjct/tlb.c: In function ‘corrupted_tlb_arg’:
src/errinjct/tlb.c:59:28: warning: unused parameter ‘arg’ [-Wunused-parameter]
   59 | int corrupted_tlb_arg(char arg, char *optarg)
      |                       ~~~~~^~~
src/errinjct/tlb.c:59:39: warning: unused parameter ‘optarg’ [-Wunused-parameter]
   59 | int corrupted_tlb_arg(char arg, char *optarg)
      |                                 ~~~~~~^~~~~~
src/rtas_dbg.c: In function ‘get_rtas_token_by_value’:
src/rtas_dbg.c:191:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
  191 |                 if (value == tok->token)
      |                           ^~
src/drmgr/common.c: In function ‘say’:
src/drmgr/common.c:91:17: warning: comparison of integer expressions of different signedness: ‘enum say_level’ and ‘int’ [-Wsign-compare]
   91 |         if (lvl <= output_level)
      |                 ^~
src/drmgr/common.c: In function ‘get_att_prop’:
src/drmgr/common.c:729:34: warning: comparison of integer expressions of different signedness: ‘__off_t’ {aka ‘long int’} and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
  729 |                 if (sbuf.st_size > buf_sz) {
      |                                  ^
src/drmgr/common.c: In function ‘update_sysparm’:
src/drmgr/common.c:1230:35: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
 1230 |                 if (usr_drc_count > curval) {
      |                                   ^
src/drmgr/common_ofdt.c: In function ‘get_min_common_depth’:
src/drmgr/common_ofdt.c:785:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
  785 |         if (size < sizeof(uint32_t)) {
      |                  ^
src/drmgr/common_ofdt.c: In function ‘get_assoc_arrays’:
src/drmgr/common_ofdt.c:819:30: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
  819 |         if (min_common_depth > aa->array_sz) {
      |                              ^
src/drmgr/common_ofdt.c:825:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
  825 |         if (size != (aa->n_arrays * aa->array_sz + 2)) {
      |                  ^~
src/drmgr/common_ofdt.c: In function ‘of_associativity_to_node’:
src/drmgr/common_ofdt.c:863:30: warning: comparison of integer expressions of different signedness: ‘__uint32_t’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
  863 |         if (be32toh(prop[0]) < min_common_depth) {
      |                              ^
src/drmgr/common_pci.c: In function ‘get_bus_id’:
src/drmgr/common_pci.c:1094:39: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
 1094 |                 if ((strlen(location) == inlen &&
      |                                       ^~
In file included from src/drmgr/common_numa.c:28:
src/drmgr/common_numa.h: In function ‘ppcnuma_next_node’:
src/drmgr/common_numa.h:54:25: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
   54 |         for (nid++; nid <= numa->node_max; nid++)
      |                         ^~
src/drmgr/common_numa.c: In function ‘ppcnuma_fetch_node’:
src/drmgr/common_numa.c:51:38: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
   51 |         if (!numa->node_count || nid < numa->node_min)
      |                                      ^
src/drmgr/common_numa.c:53:17: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
   53 |         if (nid > numa->node_max)
      |                 ^
src/drmgr/common_numa.c: In function ‘read_numa_topology’:
src/drmgr/common_numa.c:103:31: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
  103 |                 for (i = 0; i < cpus->size; i++)
      |                               ^
In file included from src/drmgr/common_numa.c:28:
src/drmgr/common_numa.h:64:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
   64 |              nid <= (numa)->node_max;                                   \
      |                  ^~
src/drmgr/common_numa.c:113:17: note: in expansion of macro ‘ppcnuma_foreach_node’
  113 |                 ppcnuma_foreach_node(numa, nid, node)
      |                 ^~~~~~~~~~~~~~~~~~~~
src/drmgr/drslot_chrp_cpu.c: In function ‘add_cpus’:
src/drmgr/drslot_chrp_cpu.c:241:22: warning: comparison of integer expressions of different signedness: ‘uint’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
  241 |         while (count < usr_drc_count) {
      |                      ^
src/drmgr/drslot_chrp_cpu.c: In function ‘remove_cpus’:
src/drmgr/drslot_chrp_cpu.c:295:22: warning: comparison of integer expressions of different signedness: ‘uint’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
  295 |         while (count < usr_drc_count) {
      |                      ^
In file included from src/drmgr/drslot_chrp_mem.c:34:
src/drmgr/common_numa.h: In function ‘ppcnuma_next_node’:
src/drmgr/common_numa.h:54:25: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
   54 |         for (nid++; nid <= numa->node_max; nid++)
      |                         ^~
src/drmgr/drslot_chrp_mem.c: In function ‘get_dynamic_reconfig_lmbs_v2’:
src/drmgr/drslot_chrp_mem.c:469:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
  469 |         for (i = 0; i < lmb_sets; i++) {
      |                       ^
src/drmgr/drslot_chrp_mem.c:478:31: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
  478 |                 for (j = 0; j < seq_lmbs; j++) {
      |                               ^
src/drmgr/drslot_chrp_mem.c: In function ‘update_drconf_affinity’:
src/drmgr/drslot_chrp_mem.c:768:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
  768 |         for (i = 0; i < assoc_entries; i++) {
      |                       ^
src/drmgr/drslot_chrp_mem.c: In function ‘mem_remove’:
src/drmgr/drslot_chrp_mem.c:1349:31: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]
 1349 |                 if (removable < usr_drc_count) {
      |                               ^
src/drmgr/drslot_chrp_mem.c: In function ‘remove_lmb_from_node’:
src/drmgr/drslot_chrp_mem.c:1478:44: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
 1478 |         for (lmb = node->lmbs; lmb && done < count; lmb = lmb->lmb_numa_next) {
      |                                            ^
In file included from src/drmgr/drslot_chrp_mem.c:34:
src/drmgr/drslot_chrp_mem.c: In function ‘update_cpuless_node_ratio’:
src/drmgr/common_numa.h:64:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
   64 |              nid <= (numa)->node_max;                                   \
      |                  ^~
src/drmgr/drslot_chrp_mem.c:1532:9: note: in expansion of macro ‘ppcnuma_foreach_node’
 1532 |         ppcnuma_foreach_node(&numa, nid, node) {
      |         ^~~~~~~~~~~~~~~~~~~~
src/drmgr/drslot_chrp_mem.c: In function ‘remove_cpuless_lmbs’:
src/drmgr/common_numa.h:64:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
   64 |              nid <= (numa)->node_max;                                   \
      |                  ^~
src/drmgr/drslot_chrp_mem.c:1563:17: note: in expansion of macro ‘ppcnuma_foreach_node’
 1563 |                 ppcnuma_foreach_node(&numa, nid, node) {
      |                 ^~~~~~~~~~~~~~~~~~~~
src/drmgr/drslot_chrp_mem.c: In function ‘update_node_ratio’:
src/drmgr/common_numa.h:64:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
   64 |              nid <= (numa)->node_max;                                   \
      |                  ^~
src/drmgr/drslot_chrp_mem.c:1608:9: note: in expansion of macro ‘ppcnuma_foreach_node’
 1608 |         ppcnuma_foreach_node(&numa, nid, node) {
      |         ^~~~~~~~~~~~~~~~~~~~
src/drmgr/common_numa.h:64:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
   64 |              nid <= (numa)->node_max;                                   \
      |                  ^~
src/drmgr/drslot_chrp_mem.c:1619:9: note: in expansion of macro ‘ppcnuma_foreach_node’
 1619 |         ppcnuma_foreach_node(&numa, nid, node) {
      |         ^~~~~~~~~~~~~~~~~~~~
src/drmgr/drslot_chrp_mem.c: In function ‘clear_numa_lmb_links’:
src/drmgr/common_numa.h:64:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
   64 |              nid <= (numa)->node_max;                                   \
      |                  ^~
src/drmgr/drslot_chrp_mem.c:1701:9: note: in expansion of macro ‘ppcnuma_foreach_node’
 1701 |         ppcnuma_foreach_node(&numa, nid, node)
      |         ^~~~~~~~~~~~~~~~~~~~
src/drmgr/drslot_chrp_mem.c: In function ‘numa_based_remove’:
src/drmgr/common_numa.h:64:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
   64 |              nid <= (numa)->node_max;                                   \
      |                  ^~
src/drmgr/drslot_chrp_mem.c:1729:9: note: in expansion of macro ‘ppcnuma_foreach_node’
 1729 |         ppcnuma_foreach_node(&numa, nid, node) {
      |         ^~~~~~~~~~~~~~~~~~~~
@tyreld tyreld self-assigned this Mar 14, 2022
@tyreld tyreld added this to the Release 1.3.10 milestone Mar 14, 2022
@tyreld
Copy link
Member Author

tyreld commented Mar 14, 2022

A good number of these are -Wunused-parameter warnings in lparstat. In particular it looks like most of the get data accessors don't use the struct sysentry that is passed (which are further given the parameter name *unsed_se in some cases).

As an example:

void get_per_entc(struct sysentry *unused_se, char *buf)                         
{                                                                                
        char *descr;                                                             
        char physc[32];                                                          
        char entc[32];                                                           
                                                                                 
        get_sysdata("DesEntCap", &descr, entc);                                  
        get_sysdata("physc", &descr, physc);                                     
                                                                                 
        sprintf(buf, "%.2f", atof(physc) / atof(entc) * 100.0);                  
}

A couple options if we care enough to get rid of these warnings is __attribute__((unused)) or dropping the struct sysentry * parameter from the (*get) function pointer in struct sysentry since we have get_sysentry() which searches system_data[] for a matching char *name.

@tyreld
Copy link
Member Author

tyreld commented Mar 15, 2022

The errinjct source has a similar scenario with an array of elements that contain function pointers. In particular for each possible errinjct function there is a function pointer to validate additional command line arguments. Three of these always return error as they don't expect additional arguments and thusly don't parse the input parameters which are being correctly reported as unused.

This scenario is easily fixed by just setting these function pointers to NULL, and allowing the argument parsing loop in main to treat extra options as an error when there is not a valid .arg function pointer.

@tyreld
Copy link
Member Author

tyreld commented Mar 15, 2022

The remaining warnings are all -Wsign-compare.

@tyreld tyreld removed this from the Release 1.3.10 milestone Mar 15, 2022
@tyreld tyreld added this to the Release 1.3.12 milestone Jan 23, 2023
@tyreld tyreld added the CI label Jan 23, 2023
@tyreld tyreld removed this from the Release 1.3.12 milestone Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant