From c78e2b4c646d6a87d40e18b527aba8cdb5f89ae4 Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Thu, 1 Aug 2024 16:18:48 -0400 Subject: [PATCH] LWP: Avoid casting functions to void pointer Commit 09aba81c50cb (Cast LWP event functions to void pointer) fixed a compiler warning when building binaries with LWP threaded, but did so in a way that appeased the compiler but did not address the underlying undefined behavior. The ISO C standard states "a pointer to any object type may be converted to a pointer to void and back again; the result shall compare equal to the original pointer", but since a function is not defined as an object, the conversion of function pointer to a void pointer is undefined. Fix this by creating dummy integer globals to be used as the event ids for the few places function pointers are used for event ids. The values of the dummy variables are set but are never read. Change-Id: I00084b882fe62cb0a82963ef45c390e5082c6fab Reviewed-on: https://gerrit.openafs.org/15794 Tested-by: BuildBot Reviewed-by: Mark Vitale Reviewed-by: Cheyenne Wills Reviewed-by: Michael Meffie --- src/vol/volume.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/vol/volume.c b/src/vol/volume.c index e4e5122963..d772e27713 100644 --- a/src/vol/volume.c +++ b/src/vol/volume.c @@ -118,6 +118,9 @@ pthread_cond_t vol_sleep_cond; pthread_cond_t vol_init_attach_cond; pthread_cond_t vol_vinit_cond; int vol_attach_threads = 1; +#else +int VInitAttachVolumes_event = 1; +int VPutVolume_event = 2; #endif /* AFS_PTHREAD_ENV */ #ifdef AFS_DEMAND_ATTACH_FS @@ -659,7 +662,7 @@ VInitAttachVolumes(ProgramType pt) } VOL_LOCK; VSetVInit_r(2); /* Initialized, and all volumes have been attached */ - LWP_NoYieldSignal((void *)VInitAttachVolumes); + LWP_NoYieldSignal(&VInitAttachVolumes_event); VOL_UNLOCK; return 0; } @@ -1326,7 +1329,7 @@ VShutdown_r(void) #ifdef AFS_PTHREAD_ENV VOL_CV_WAIT(&vol_init_attach_cond); #else - LWP_WaitProcess((void *)VInitAttachVolumes); + LWP_WaitProcess(&VInitAttachVolumes_event); #endif /* AFS_PTHREAD_ENV */ } } @@ -4237,7 +4240,7 @@ GetVolume(Error * ec, Error * client_ec, VolumeId volumeId, Volume * hint, /* LWP has no timed wait, so the caller better not be * expecting one */ opr_Assert(!timeout); - LWP_WaitProcess((void *)VPutVolume); + LWP_WaitProcess(&VPutVolume_event); #endif /* AFS_PTHREAD_ENV */ continue; } @@ -4384,7 +4387,7 @@ VForceOffline_r(Volume * vp, int flags) #ifdef AFS_PTHREAD_ENV opr_cv_broadcast(&vol_put_volume_cond); #else /* AFS_PTHREAD_ENV */ - LWP_NoYieldSignal((void *)VPutVolume); + LWP_NoYieldSignal(&VPutVolume_event); #endif /* AFS_PTHREAD_ENV */ VReleaseVolumeHandles_r(vp); @@ -5070,7 +5073,7 @@ VCheckDetach(Volume * vp) #if defined(AFS_PTHREAD_ENV) opr_cv_broadcast(&vol_put_volume_cond); #else /* AFS_PTHREAD_ENV */ - LWP_NoYieldSignal((void *)VPutVolume); + LWP_NoYieldSignal(&VPutVolume_event); #endif /* AFS_PTHREAD_ENV */ } } @@ -5170,7 +5173,7 @@ VCheckOffline(Volume * vp) #ifdef AFS_PTHREAD_ENV opr_cv_broadcast(&vol_put_volume_cond); #else /* AFS_PTHREAD_ENV */ - LWP_NoYieldSignal((void *)VPutVolume); + LWP_NoYieldSignal(&VPutVolume_event); #endif /* AFS_PTHREAD_ENV */ } return ret;