[PATCH] mmc ioctl: Notify mmc core of ext_csd change

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Let mmc core know of ext_csd change when userspace utilizes ioctl to
change PARTITION_CONFIG (previously BOOT_CONFIG). Otherwise changing
boot partitions from userspace can be trampled on.

Signed-off-by: Brandon Schaefer <brandon.schaefer@xxxxxxxxxxxxxxxxx>
---
 drivers/mmc/core/block.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 64f9fda..d5b0085 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -63,7 +63,9 @@ MODULE_ALIAS("mmc:block");
 
 #define MMC_BLK_TIMEOUT_MS  (10 * 60 * 1000)        /* 10 minute timeout */
 #define MMC_SANITIZE_REQ_TIMEOUT 240000
-#define MMC_EXTRACT_INDEX_FROM_ARG(x) ((x & 0x00FF0000) >> 16)
+#define MMC_EXTRACT_SWITCH_MODE_FROM_ARG(x) (((x) & 0x030F0000) >> 24)
+#define MMC_EXTRACT_INDEX_FROM_ARG(x) (((x) & 0x00FF0000) >> 16)
+#define MMC_EXTRACT_VALUE_FROM_ARG(x) (((x) & 0x00000FF0) >> 8)
 
 #define mmc_req_rel_wr(req)	((req->cmd_flags & REQ_FUA) && \
 				  (rq_data_dir(req) == WRITE))
@@ -517,6 +519,24 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
 		return err;
 	}
 
+	if ((MMC_EXTRACT_INDEX_FROM_ARG(cmd.arg) == EXT_CSD_PART_CONFIG) &&
+	    (cmd.opcode == MMC_SWITCH)) {
+		u8 mode = MMC_EXTRACT_SWITCH_MODE_FROM_ARG(cmd.arg);
+		u8 value = MMC_EXTRACT_VALUE_FROM_ARG(cmd.arg);
+
+		switch (mode) {
+		case MMC_SWITCH_MODE_SET_BITS:
+			card->ext_csd.part_config |= value;
+			break;
+		case MMC_SWITCH_MODE_CLEAR_BITS:
+			card->ext_csd.part_config &= ~value;
+			break;
+		case MMC_SWITCH_MODE_WRITE_BYTE:
+			card->ext_csd.part_config = value;
+			break;
+		}
+	}
+
 	mmc_wait_for_req(card->host, &mrq);
 
 	if (cmd.error) {
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux