Skip to content

Commit f06c915

Browse files
Andrei Warkentincjb
authored andcommitted
mmc: Ensure hardware partitions don't mess with mmcblk device naming.
With the hardware partitions support (which represent additional logical devices present on MMC), devidx does not correspond with index used to form /dev/mmcblkX names. So use an additional allocated index for device names. Signed-off-by: Andrei Warkentin <[email protected]> Signed-off-by: Chris Ball <[email protected]>
1 parent 393c1a3 commit f06c915

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

drivers/mmc/card/block.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static int max_devices;
7575

7676
/* 256 minors, so at most 256 separate devices */
7777
static DECLARE_BITMAP(dev_use, 256);
78+
static DECLARE_BITMAP(name_use, 256);
7879

7980
/*
8081
* There is one mmc_blk_data per slot.
@@ -88,6 +89,7 @@ struct mmc_blk_data {
8889
unsigned int usage;
8990
unsigned int read_only;
9091
unsigned int part_type;
92+
unsigned int name_idx;
9193

9294
/*
9395
* Only set in main mmc_blk_data associated
@@ -766,6 +768,20 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
766768
goto out;
767769
}
768770

771+
/*
772+
* !subname implies we are creating main mmc_blk_data that will be
773+
* associated with mmc_card with mmc_set_drvdata. Due to device
774+
* partitions, devidx will not coincide with a per-physical card
775+
* index anymore so we keep track of a name index.
776+
*/
777+
if (!subname) {
778+
md->name_idx = find_first_zero_bit(name_use, max_devices);
779+
__set_bit(md->name_idx, name_use);
780+
}
781+
else
782+
md->name_idx = ((struct mmc_blk_data *)
783+
dev_to_disk(parent)->private_data)->name_idx;
784+
769785
/*
770786
* Set the read-only status based on the supported commands
771787
* and the write protect switch.
@@ -811,13 +827,8 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
811827
* messages to tell when the card is present.
812828
*/
813829

814-
if (subname)
815-
snprintf(md->disk->disk_name, sizeof(md->disk->disk_name),
816-
"mmcblk%d%s",
817-
mmc_get_devidx(dev_to_disk(parent)), subname);
818-
else
819-
snprintf(md->disk->disk_name, sizeof(md->disk->disk_name),
820-
"mmcblk%d", devidx);
830+
snprintf(md->disk->disk_name, sizeof(md->disk->disk_name),
831+
"mmcblk%d%s", md->name_idx, subname ? subname : "");
821832

822833
blk_queue_logical_block_size(md->queue.queue, 512);
823834
set_capacity(md->disk, size);
@@ -944,6 +955,7 @@ static void mmc_blk_remove_parts(struct mmc_card *card,
944955
struct list_head *pos, *q;
945956
struct mmc_blk_data *part_md;
946957

958+
__clear_bit(md->name_idx, name_use);
947959
list_for_each_safe(pos, q, &md->part) {
948960
part_md = list_entry(pos, struct mmc_blk_data, part);
949961
list_del(pos);

0 commit comments

Comments
 (0)