Merge branches 'core-fixes-for-linus' and 'irq-fixes-for-linus' of git://git.kernel...
[pandora-kernel.git] / drivers / mmc / core / sd_ops.c
index 797cdb5..021fed1 100644 (file)
@@ -9,6 +9,7 @@
  * your option) any later version.
  */
 
+#include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/scatterlist.h>
 
 #include "core.h"
 #include "sd_ops.h"
 
-static int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
+int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
 {
        int err;
-       struct mmc_command cmd;
+       struct mmc_command cmd = {0};
 
        BUG_ON(!host);
        BUG_ON(card && (card->host != host));
@@ -48,6 +49,7 @@ static int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(mmc_app_cmd);
 
 /**
  *     mmc_wait_for_app_cmd - start an application command and wait for
@@ -65,7 +67,7 @@ static int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
 int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
        struct mmc_command *cmd, int retries)
 {
-       struct mmc_request mrq;
+       struct mmc_request mrq = {0};
 
        int i, err;
 
@@ -118,13 +120,11 @@ EXPORT_SYMBOL(mmc_wait_for_app_cmd);
 int mmc_app_set_bus_width(struct mmc_card *card, int width)
 {
        int err;
-       struct mmc_command cmd;
+       struct mmc_command cmd = {0};
 
        BUG_ON(!card);
        BUG_ON(!card->host);
 
-       memset(&cmd, 0, sizeof(struct mmc_command));
-
        cmd.opcode = SD_APP_SET_BUS_WIDTH;
        cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
 
@@ -148,13 +148,11 @@ int mmc_app_set_bus_width(struct mmc_card *card, int width)
 
 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
 {
-       struct mmc_command cmd;
+       struct mmc_command cmd = {0};
        int i, err = 0;
 
        BUG_ON(!host);
 
-       memset(&cmd, 0, sizeof(struct mmc_command));
-
        cmd.opcode = SD_APP_OP_COND;
        if (mmc_host_is_spi(host))
                cmd.arg = ocr & (1 << 30); /* SPI only defines one bit */
@@ -193,7 +191,7 @@ int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
 
 int mmc_send_if_cond(struct mmc_host *host, u32 ocr)
 {
-       struct mmc_command cmd;
+       struct mmc_command cmd = {0};
        int err;
        static const u8 test_pattern = 0xAA;
        u8 result_pattern;
@@ -225,13 +223,11 @@ int mmc_send_if_cond(struct mmc_host *host, u32 ocr)
 int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca)
 {
        int err;
-       struct mmc_command cmd;
+       struct mmc_command cmd = {0};
 
        BUG_ON(!host);
        BUG_ON(!rca);
 
-       memset(&cmd, 0, sizeof(struct mmc_command));
-
        cmd.opcode = SD_SEND_RELATIVE_ADDR;
        cmd.arg = 0;
        cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR;
@@ -248,10 +244,11 @@ int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca)
 int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
 {
        int err;
-       struct mmc_request mrq;
-       struct mmc_command cmd;
-       struct mmc_data data;
+       struct mmc_request mrq = {0};
+       struct mmc_command cmd = {0};
+       struct mmc_data data = {0};
        struct scatterlist sg;
+       void *data_buf;
 
        BUG_ON(!card);
        BUG_ON(!card->host);
@@ -263,9 +260,12 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
        if (err)
                return err;
 
-       memset(&mrq, 0, sizeof(struct mmc_request));
-       memset(&cmd, 0, sizeof(struct mmc_command));
-       memset(&data, 0, sizeof(struct mmc_data));
+       /* dma onto stack is unsafe/nonportable, but callers to this
+        * routine normally provide temporary on-stack buffers ...
+        */
+       data_buf = kmalloc(sizeof(card->raw_scr), GFP_KERNEL);
+       if (data_buf == NULL)
+               return -ENOMEM;
 
        mrq.cmd = &cmd;
        mrq.data = &data;
@@ -280,12 +280,15 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
        data.sg = &sg;
        data.sg_len = 1;
 
-       sg_init_one(&sg, scr, 8);
+       sg_init_one(&sg, data_buf, 8);
 
        mmc_set_data_timeout(&data, card);
 
        mmc_wait_for_req(card->host, &mrq);
 
+       memcpy(scr, data_buf, sizeof(card->raw_scr));
+       kfree(data_buf);
+
        if (cmd.error)
                return cmd.error;
        if (data.error)
@@ -300,9 +303,9 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
        u8 value, u8 *resp)
 {
-       struct mmc_request mrq;
-       struct mmc_command cmd;
-       struct mmc_data data;
+       struct mmc_request mrq = {0};
+       struct mmc_command cmd = {0};
+       struct mmc_data data = {0};
        struct scatterlist sg;
 
        BUG_ON(!card);
@@ -313,10 +316,6 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
        mode = !!mode;
        value &= 0xF;
 
-       memset(&mrq, 0, sizeof(struct mmc_request));
-       memset(&cmd, 0, sizeof(struct mmc_command));
-       memset(&data, 0, sizeof(struct mmc_data));
-
        mrq.cmd = &cmd;
        mrq.data = &data;
 
@@ -349,9 +348,9 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
 int mmc_app_sd_status(struct mmc_card *card, void *ssr)
 {
        int err;
-       struct mmc_request mrq;
-       struct mmc_command cmd;
-       struct mmc_data data;
+       struct mmc_request mrq = {0};
+       struct mmc_command cmd = {0};
+       struct mmc_data data = {0};
        struct scatterlist sg;
 
        BUG_ON(!card);
@@ -364,10 +363,6 @@ int mmc_app_sd_status(struct mmc_card *card, void *ssr)
        if (err)
                return err;
 
-       memset(&mrq, 0, sizeof(struct mmc_request));
-       memset(&cmd, 0, sizeof(struct mmc_command));
-       memset(&data, 0, sizeof(struct mmc_data));
-
        mrq.cmd = &cmd;
        mrq.data = &data;