mmc: move ready/frame field into mmc_core_rpmb_req
authorChuanxiao Dong <chuanxiao.dong@intel.com>
Mon, 6 Feb 2012 09:45:08 +0000 (17:45 +0800)
committerbuildbot <buildbot@intel.com>
Tue, 14 Feb 2012 10:22:23 +0000 (02:22 -0800)
BZ: 22879

mmc_rpmb_req is used for external use. Keeping ready/frame field
in this structure is not safe.
Create a new struct named mmc_core_rpmb_req which is for mmc core
only. No external user can touch it. So move ready/frame field into
this structure

Change-Id: I767e47c31a0ce6396f099c46056c100aa40e6f6f
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com>
Reviewed-on: http://android.intel.com:8080/34475
Reviewed-by: Jiang, Brendan <brendan.jiang@intel.com>
Reviewed-by: Tang, Richard <richard.tang@intel.com>
Tested-by: Sun, Jianhua <jianhua.sun@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
drivers/mmc/card/block.c
drivers/mmc/core/mmc_ops.c
include/linux/mmc/core.h

index c33b084..86ad102 100644 (file)
@@ -755,6 +755,7 @@ int mmc_rpmb_req_handle(struct device *emmc, struct mmc_rpmb_req *req)
        struct mmc_card *card   = NULL;
        struct mmc_blk_data *md = NULL;
        unsigned int            part_curr;
+       struct mmc_core_rpmb_req rpmb_req;
 
        if (!emmc)
                return -ENODEV;
@@ -796,8 +797,10 @@ int mmc_rpmb_req_handle(struct device *emmc, struct mmc_rpmb_req *req)
                goto err;
        }
 
+       memset(&rpmb_req, 0, sizeof(struct mmc_core_rpmb_req));
+       rpmb_req.req = req;
        /* check request */
-       ret = mmc_rpmb_pre_frame(req, card);
+       ret = mmc_rpmb_pre_frame(&rpmb_req, card);
        if (ret) {
                pr_err("%s: prepare frame failed\n", mmc_hostname(card->host));
                goto err;
@@ -805,7 +808,8 @@ int mmc_rpmb_req_handle(struct device *emmc, struct mmc_rpmb_req *req)
 
        mmc_claim_host(card->host);
 
-       /* * before start, let's change to RPMB partition first
+       /*
+        * before start, let's change to RPMB partition first
         */
        part_curr = md->part_type;
        md->part_type = EXT_CSD_PART_CONFIG_RPMB;
@@ -820,7 +824,7 @@ int mmc_rpmb_req_handle(struct device *emmc, struct mmc_rpmb_req *req)
                goto out;
        }
 
-       ret = mmc_rpmb_partition_ops(req, card);
+       ret = mmc_rpmb_partition_ops(&rpmb_req, card);
        if (ret)
                pr_err("%s: failed (%d) to handle RPMB request type (%d)!\n",
                                mmc_hostname(card->host), ret, req->type);
@@ -845,7 +849,7 @@ out:
                }
        }
        mmc_release_host(card->host);
-       mmc_rpmb_post_frame(req);
+       mmc_rpmb_post_frame(&rpmb_req);
 err:
        mmc_blk_put(md);
 
index b96ea8c..a57fcbd 100644 (file)
@@ -642,12 +642,13 @@ static int mmc_rpmb_send_command(struct mmc_card *card, u8 *buf, __u16 blks,
        return 0;
 }
 
-void mmc_rpmb_post_frame(struct mmc_rpmb_req *p_req)
+void mmc_rpmb_post_frame(struct mmc_core_rpmb_req *rpmb_req)
 {
        int i;
-       __u8 *ptr, *buf_frame = p_req->frame;
+       struct mmc_rpmb_req *p_req = rpmb_req->req;
+       __u8 *ptr, *buf_frame = rpmb_req->frame;
 
-       if (!p_req->ready || !buf_frame)
+       if (!rpmb_req->ready || !buf_frame)
                return;
        /*
         * Regarding to the check rules, here is the post
@@ -713,7 +714,7 @@ void mmc_rpmb_post_frame(struct mmc_rpmb_req *p_req)
        }
 out:
        kfree(buf_frame);
-       p_req->frame = NULL;
+       rpmb_req->frame = NULL;
        return;
 }
 EXPORT_SYMBOL_GPL(mmc_rpmb_post_frame);
@@ -822,20 +823,26 @@ static int mmc_rpmb_request_check(struct mmc_card *card,
  * convert needed bytes
  * return how many frames will be prepared
  */
-int mmc_rpmb_pre_frame(struct mmc_rpmb_req *p_req,
+int mmc_rpmb_pre_frame(struct mmc_core_rpmb_req *rpmb_req,
                struct mmc_card *card)
 {
        int i, j, ret;
+       struct mmc_rpmb_req *p_req = rpmb_req->req;
        __u8 *ptr = NULL, *buf_frame;
-       __u8 *data = p_req->data;
        __u16 blk_cnt, addr, type;
        __u32 w_counter;
 
+       if (!p_req) {
+               pr_err("%s: mmc_rpmb_req is NULL. Wrong parameter\n",
+                               mmc_hostname(card->host));
+               return -EINVAL;
+       }
+
        /*
         * make sure these two items are clear
         */
-       p_req->ready = 0;
-       p_req->frame = NULL;
+       rpmb_req->ready = 0;
+       rpmb_req->frame = NULL;
 
        ret = mmc_rpmb_request_check(card, p_req);
        if (ret)
@@ -866,6 +873,7 @@ int mmc_rpmb_pre_frame(struct mmc_rpmb_req *p_req,
                for (i = 0; i < 16; i++, ptr--)
                        *ptr = p_req->nonce[i];
        } else if (p_req->type == RPMB_WRITE_DATA) {
+               __u8 *data = p_req->data;
                /*
                 * multiple package prepared
                 * This request nees blk_cnt, addr, write_counter,
@@ -906,20 +914,21 @@ int mmc_rpmb_pre_frame(struct mmc_rpmb_req *p_req,
                kfree(buf_frame);
                return -EINVAL;
        }
-       p_req->ready = 1;
-       p_req->frame = buf_frame;
+       rpmb_req->ready = 1;
+       rpmb_req->frame = buf_frame;
        return 0;
 }
 EXPORT_SYMBOL_GPL(mmc_rpmb_pre_frame);
 
-int mmc_rpmb_partition_ops(struct mmc_rpmb_req *p_req,
+int mmc_rpmb_partition_ops(struct mmc_core_rpmb_req *rpmb_req,
                struct mmc_card *card)
 {
        int err = 0;
+       struct mmc_rpmb_req *p_req = rpmb_req->req;
        __u16 type, blks;
-       __u8 *buf_frame = p_req->frame;
+       __u8 *buf_frame = rpmb_req->frame;
 
-       if (!p_req->ready || !buf_frame) {
+       if (!p_req || !rpmb_req->ready || !buf_frame) {
                pr_err("%s: mmc_rpmb_req is not prepared\n",
                                mmc_hostname(card->host));
                return -EINVAL;
index 584f4f2..0470b2d 100644 (file)
@@ -132,7 +132,7 @@ struct mmc_request {
 };
 
 /*
- * RPMB frame structure
+ * RPMB frame structure for external user
  */
 struct mmc_rpmb_req {
        __u16 type;                     /* RPMB request type */
@@ -143,6 +143,13 @@ struct mmc_rpmb_req {
        __u8 *nonce;                    /* Ramdom number */
        __u8 *data;                     /* Buffer of the user data */
        __u8 *mac;                      /* Message Authentication Code */
+};
+
+/*
+ * RPMB frame structure for MMC core stack
+ */
+struct mmc_core_rpmb_req {
+       struct mmc_rpmb_req *req;
        __u8 *frame;
        bool ready;
 };
@@ -178,10 +185,10 @@ extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
        struct mmc_command *, int);
 extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int);
 
-extern int mmc_rpmb_partition_ops(struct mmc_rpmb_req *,
+extern int mmc_rpmb_partition_ops(struct mmc_core_rpmb_req *,
                struct mmc_card *);
-extern int mmc_rpmb_pre_frame(struct mmc_rpmb_req *, struct mmc_card *);
-extern void mmc_rpmb_post_frame(struct mmc_rpmb_req *);
+extern int mmc_rpmb_pre_frame(struct mmc_core_rpmb_req *, struct mmc_card *);
+extern void mmc_rpmb_post_frame(struct mmc_core_rpmb_req *);
 
 #define MMC_ERASE_ARG          0x00000000
 #define MMC_SECURE_ERASE_ARG   0x80000000