block: move the DISK_MAX_PARTS sanity check into __device_add_disk
authorChristoph Hellwig <hch@lst.de>
Fri, 21 May 2021 05:50:52 +0000 (07:50 +0200)
committerJens Axboe <axboe@kernel.dk>
Tue, 1 Jun 2021 13:42:23 +0000 (07:42 -0600)
Keep this together with the first place that actually looks at
->minors and prepare for not passing a minors argument to
alloc_disk.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Link: https://lore.kernel.org/r/20210521055116.1053587-3-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/genhd.c

index 3daab80201df500f3810e3947c4a137db2aaa8a0..8c1816d2929e653b8f58a3dac1b647a88e6d4f2a 100644 (file)
@@ -489,6 +489,12 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk,
         */
        if (disk->major) {
                WARN_ON(!disk->minors);
+
+               if (disk->minors > DISK_MAX_PARTS) {
+                       pr_err("block: can't allocate more than %d partitions\n",
+                               DISK_MAX_PARTS);
+                       disk->minors = DISK_MAX_PARTS;
+               }
        } else {
                WARN_ON(disk->minors);
                WARN_ON(!(disk->flags & (GENHD_FL_EXT_DEVT | GENHD_FL_HIDDEN)));
@@ -1255,13 +1261,6 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)
 {
        struct gendisk *disk;
 
-       if (minors > DISK_MAX_PARTS) {
-               printk(KERN_ERR
-                       "block: can't allocate more than %d partitions\n",
-                       DISK_MAX_PARTS);
-               minors = DISK_MAX_PARTS;
-       }
-
        disk = kzalloc_node(sizeof(struct gendisk), GFP_KERNEL, node_id);
        if (!disk)
                return NULL;