[04/10] sim/ppc: don't pass uninitialized value to semctl for GETVAL calls

Message ID 5155a6bb36800aa1a8bdb214f59f85f9d92b6989.1666192979.git.aburgess@redhat.com
State Committed
Headers
Series Building the sim/ tree with clang |

Commit Message

Andrew Burgess Oct. 19, 2022, 3:24 p.m. UTC
  When calling semctl with an GETVAL action, the 'union semun' argument
is unused.

Rather than passing an uninitialized variable (as we currently do),
just pass the integer 0.  This silences some compiler warnings, and is
just as correct (given the argument is ignored).

To be honest, it might be the case that the argument is not needed at
all, however, I'm a little nervous to make this change as the amount
of testing I can do of this code is limited.  Every example I found
online for a semctl/GETVAL call did pass the final argument, so that's
what I've continued to do.
---
 sim/ppc/hw_sem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Mike Frysinger Oct. 23, 2022, 2:01 p.m. UTC | #1
On 19 Oct 2022 16:24, Andrew Burgess via Gdb-patches wrote:
> When calling semctl with an GETVAL action, the 'union semun' argument
> is unused.
> 
> Rather than passing an uninitialized variable (as we currently do),
> just pass the integer 0.  This silences some compiler warnings, and is
> just as correct (given the argument is ignored).
> 
> To be honest, it might be the case that the argument is not needed at
> all, however, I'm a little nervous to make this change as the amount
> of testing I can do of this code is limited.  Every example I found
> online for a semctl/GETVAL call did pass the final argument, so that's
> what I've continued to do.

the semctl prototype is:
	int semctl(int semid, int semnum, int cmd, ...);

i would just delete the 4th arg, but if you really want to keep the 0, OK.
-mike
  

Patch

diff --git a/sim/ppc/hw_sem.c b/sim/ppc/hw_sem.c
index 937e2ad6f81..78e3dda9ae6 100644
--- a/sim/ppc/hw_sem.c
+++ b/sim/ppc/hw_sem.c
@@ -148,7 +148,7 @@  hw_sem_init_data(device *me)
       error("hw_sem_init_data() semget failed\n");
   }
 
-  sem->count = semctl( sem->id, 0, GETVAL, help );
+  sem->count = semctl( sem->id, 0, GETVAL, 0 );
   if (sem->count == -1)
     error("hw_sem_init_data() semctl -- get value failed\n");
   DTRACE(sem, ("semaphore OS value (%d)\n", sem->count) );
@@ -241,7 +241,7 @@  hw_sem_io_read_buffer(device *me,
   }
 
   /* assume target is big endian */
-  u32 = H2T_4(semctl( sem->id, 0, GETVAL, help ));
+  u32 = H2T_4(semctl( sem->id, 0, GETVAL, 0 ));
 
   DTRACE(sem, ("semaphore OS value (%d)\n", u32) );
   if (u32 == 0xffffffff) {