[PATCH] mci: avoid out of bounds partition access

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

 



The mci->part array has MMC_NUM_PHY_PARTITION. Avoid creating more
partitions than we have entries in the array and print an error
message instead.

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
Reported-by: Florian Otte <fotte@xxxxxxxxxxxxxxxxx>
---
 drivers/mci/mci-core.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 0261f36d89..ec4a5c0749 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -651,7 +651,15 @@ static void mci_part_add(struct mci *mci, uint64_t size,
                         unsigned int part_cfg, char *name, char *partname, int idx, bool ro,
                         int area_type)
 {
-	struct mci_part *part = &mci->part[mci->nr_parts];
+	struct mci_part *part;
+
+	if (mci->nr_parts == MMC_NUM_PHY_PARTITION) {
+		dev_err(&mci->dev, "Out of physical partitions, cannot create partition %s\n",
+			name);
+		return;
+	}
+
+	part = &mci->part[mci->nr_parts];
 
 	part->mci = mci;
 	part->size = size;
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux