Whamcloud - gitweb
LU-3576 mdc: prevent fall through in mdc_iocontrol() 62/6962/2
authorJohn L. Hammond <john.hammond@intel.com>
Fri, 12 Jul 2013 15:21:48 +0000 (10:21 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 23 Jul 2013 05:45:38 +0000 (05:45 +0000)
In mdc_iocontrol() add a goto to the end of the LL_IOC_HSM_STATE_SET
case, preventing fall through into the next case. In the same
function, replace the return statement in OBD_IOC_QUOTACTL with a
goto, so that a reference to the module is not leaked.

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: Ib3c04835f8cd761849869c8fb11672d66aa14025
Reviewed-on: http://review.whamcloud.com/6962
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Aurelien Degremont <aurelien.degremont@cea.fr>
Reviewed-by: jacques-Charles Lafoucriere <jacques-charles.lafoucriere@cea.fr>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/mdc/mdc_request.c

index 50f9600..f318474 100644 (file)
@@ -1836,6 +1836,7 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                GOTO(out, rc);
        case LL_IOC_HSM_STATE_SET:
                rc = mdc_ioc_hsm_state_set(exp, karg);
+               GOTO(out, rc);
        case LL_IOC_HSM_ACTION:
                rc = mdc_ioc_hsm_current_action(exp, karg);
                GOTO(out, rc);
@@ -1904,44 +1905,42 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
 
                 GOTO(out, rc = 0);
         }
-        case OBD_IOC_QUOTACTL: {
-                struct if_quotactl *qctl = karg;
-                struct obd_quotactl *oqctl;
+       case OBD_IOC_QUOTACTL: {
+               struct if_quotactl *qctl = karg;
+               struct obd_quotactl *oqctl;
 
-                OBD_ALLOC_PTR(oqctl);
-                if (!oqctl)
-                        RETURN(-ENOMEM);
+               OBD_ALLOC_PTR(oqctl);
+               if (oqctl == NULL)
+                       GOTO(out, rc = -ENOMEM);
 
-                QCTL_COPY(oqctl, qctl);
-                rc = obd_quotactl(exp, oqctl);
-                if (rc == 0) {
-                        QCTL_COPY(qctl, oqctl);
-                        qctl->qc_valid = QC_MDTIDX;
-                        qctl->obd_uuid = obd->u.cli.cl_target_uuid;
-                }
-                OBD_FREE_PTR(oqctl);
-                break;
-        }
-       case LL_IOC_GET_CONNECT_FLAGS: {
-               if (copy_to_user(uarg,
-                                    exp_connect_flags_ptr(exp),
-                                    sizeof(__u64)))
-                       GOTO(out, rc = -EFAULT);
-               else
-                       GOTO(out, rc = 0);
+               QCTL_COPY(oqctl, qctl);
+               rc = obd_quotactl(exp, oqctl);
+               if (rc == 0) {
+                       QCTL_COPY(qctl, oqctl);
+                       qctl->qc_valid = QC_MDTIDX;
+                       qctl->obd_uuid = obd->u.cli.cl_target_uuid;
+               }
+
+               OBD_FREE_PTR(oqctl);
+               GOTO(out, rc);
        }
-       case LL_IOC_LOV_SWAP_LAYOUTS: {
+       case LL_IOC_GET_CONNECT_FLAGS:
+               if (copy_to_user(uarg, exp_connect_flags_ptr(exp),
+                                sizeof(*exp_connect_flags_ptr(exp))))
+                       GOTO(out, rc = -EFAULT);
+
+               GOTO(out, rc = 0);
+       case LL_IOC_LOV_SWAP_LAYOUTS:
                rc = mdc_ioc_swap_layouts(exp, karg);
-               break;
+               GOTO(out, rc);
+       default:
+               CERROR("unrecognised ioctl: cmd = %#x\n", cmd);
+               GOTO(out, rc = -ENOTTY);
        }
-        default:
-                CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
-                GOTO(out, rc = -ENOTTY);
-        }
 out:
-        cfs_module_put(THIS_MODULE);
+       cfs_module_put(THIS_MODULE);
 
-        return rc;
+       return rc;
 }
 
 int mdc_get_info_rpc(struct obd_export *exp,