afs: Avoid always-false NULL test on AFSTOV(avc) 56/14956/7
authorCheyenne Wills <cwills@sinenomine.net>
Tue, 21 Jun 2022 15:57:40 +0000 (09:57 -0600)
committerBenjamin Kaduk <kaduk@mit.edu>
Thu, 23 Jun 2022 22:01:57 +0000 (18:01 -0400)
GCC-12 is flagging a comparison with the following diagnostic:

 src/afs/afs_vcache.c:3161:25: error: the comparison will always
    evaluate as ‘false’ for the address of ‘v’ will never be NULL
    [-Werror=address]
 3161 |             AFSTOV(avc) == NULL || vType(avc) == VDIR ||
      |                         ^~

When the vcache structure does not have the vnode embedded the expansion
of the AFSTOV macro results in:
   ((avc)->v)
which tests contents of a 'v'.

When the vcache structure does have the vnode embedded, the expansion of
the macro results in:
   (&(avc)->v)
which tests the address of 'v', which will never be NULL in this case.

Update afs.h to add a new define 'AFS_VCACHE_EMBEDDED_VNODE' when the
vcache structure contains an embedded vnode structure.  Restructure the
preprocessor statements for the AFSTOV definition

Avoid testing AFSTOV(x) against NULL when AFS_VCACHE_EMBEDDED_VNODE is
defined.

The diagnostic is changed from a warning to an error when configured
with --enable-checking.

Change-Id: Ib72647fa23e5a7ecd96772b04c6ef76540f44535
Reviewed-on: https://gerrit.openafs.org/14956
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/afs/afs.h
src/afs/afs_vcache.c

index 370b708..4bde047 100644 (file)
@@ -791,6 +791,7 @@ struct nbvdata {
 #define VTOAFS(v) ((struct vcache *)(v)->v_data)
 #define AFSTOV(vc) ((vc)->v)
 #else
+#define AFS_VCACHE_EMBEDDED_VNODE
 #define VTOAFS(V) ((struct vcache *)(V))
 #define AFSTOV(V) (&(V)->v)
 #endif
@@ -861,10 +862,10 @@ struct multiPage_range {
  * !(avc->nextfree) && !avc->vlruq.next => (FreeVCList == avc->nextfree)
  */
 struct vcache {
-#if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_SUN511_ENV) || (defined(AFS_LINUX_ENV) && !defined(STRUCT_SUPER_OPERATIONS_HAS_ALLOC_INODE))
-    struct vnode *v;
-#else
+#if defined(AFS_VCACHE_EMBEDDED_VNODE)
     struct vnode v;            /* Has reference count in v.v_count */
+#else
+    struct vnode *v;
 #endif
     struct afs_q vlruq;                /* lru q next and prev */
 #if !defined(AFS_LINUX_ENV)
index d48a297..2930149 100644 (file)
@@ -3158,7 +3158,10 @@ afs_StaleVCacheFlags(struct vcache *avc, afs_stalevc_flags_t flags,
 
     if (do_dnlc) {
        if ((avc->f.fid.Fid.Vnode & 1) ||
-           AFSTOV(avc) == NULL || vType(avc) == VDIR ||
+#if !defined(AFS_VCACHE_EMBEDDED_VNODE)
+           AFSTOV(avc) == NULL ||
+#endif
+           vType(avc) == VDIR ||
            (avc->f.states & CForeign)) {
            /* This vcache is (or could be) a directory. */
            osi_dnlc_purgedp(avc);