Whamcloud - gitweb
b=19115
authoranserper <anserper>
Thu, 11 Jun 2009 10:03:24 +0000 (10:03 +0000)
committeranserper <anserper>
Thu, 11 Jun 2009 10:03:24 +0000 (10:03 +0000)
i=Andreas Dilger
i=Nathan Rutman

make lov_setstripe exit on bad magic

lustre/lov/lov_pack.c

index 9b8dcf8..ba552e8 100644 (file)
@@ -424,24 +424,27 @@ int lov_setstripe(struct obd_export *exp, struct lov_stripe_md **lsmp,
         rc = copy_from_user(&lumv3, lump, sizeof(struct lov_user_md_v1));
         if (rc)
                 RETURN(-EFAULT);
-        if ((lumv1->lmm_magic == LOV_USER_MAGIC_V3) ||
-            (lumv1->lmm_magic == LOV_USER_MAGIC_V3_SWABBED)) {
+
+        switch (lumv1->lmm_magic) {
+        case LOV_USER_MAGIC_V3_SWABBED:
                 rc = copy_from_user(&lumv3, lump, sizeof(lumv3));
                 if (rc)
-                        RETURN(-EFAULT);
-        }
-
-        if ((lumv1->lmm_magic == LOV_USER_MAGIC_V1_SWABBED) ||
-            (lumv1->lmm_magic == LOV_USER_MAGIC_V3_SWABBED)) {
+                        break;
+                /* fall through to swab */
+        case LOV_USER_MAGIC_V1_SWABBED:
                 rc = lustre_swab_lov_user_md(lumv1);
-                if (rc)
-                        RETURN(rc);
-        } else if ((lumv1->lmm_magic != LOV_USER_MAGIC_V1) &&
-                   (lumv1->lmm_magic != LOV_USER_MAGIC_V3)) {
-                CDEBUG(D_IOCTL, "bad userland LOV MAGIC: %#08x\n",
-                       lumv1->lmm_magic);
+                break;
+        case LOV_USER_MAGIC_V3:
+                rc = copy_from_user(&lumv3, lump, sizeof(lumv3));
+                /* fall through */
+        case LOV_USER_MAGIC_V1:
+                break;
+        default:
+                CERROR("bad lsm magic %08x\n", lumv1->lmm_magic);
                 RETURN(-EINVAL);
         }
+        if (rc)
+                RETURN(rc);
 
         /* in the rest of the tests, as *lumv1 and lumv3 have the same
          * fields, we use lumv1 to avoid code duplication */