]> www.infradead.org Git - users/hch/block.git/commitdiff
block: move the DISK_MAX_PARTS sanity check into __device_add_disk
authorChristoph Hellwig <hch@lst.de>
Thu, 29 Apr 2021 13:26:16 +0000 (15:26 +0200)
committerChristoph Hellwig <hch@lst.de>
Thu, 20 May 2021 14:43:55 +0000 (16:43 +0200)
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>
block/genhd.c

index 2c00bc3261d94683cebd52a4cfd57e43b297ab65..7f9beaeede116c6a92e1ca7bec2e46eb62a30f6c 100644 (file)
@@ -491,6 +491,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)));
@@ -1264,13 +1270,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;