Skip to content

Commit f33ff11

Browse files
srivatsabhatgregkh
authored andcommitted
block, char_dev: Use correct format specifier for unsigned ints
register_blkdev() and __register_chrdev_region() treat the major number as an unsigned int. So print it the same way to avoid absurd error statements such as: "... major requested (-1) is greater than the maximum (511) ..." (and also fix off-by-one bugs in the error prints). While at it, also update the comment describing register_blkdev(). Signed-off-by: Srivatsa S. Bhat <srivatsa@csail.mit.edu> Reviewed-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 652d703 commit f33ff11

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

‎block/genhd.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,19 +308,22 @@ void blkdev_show(struct seq_file *seqf, off_t offset)
308308
/**
309309
* register_blkdev - register a new block device
310310
*
311-
* @major: the requested major device number [1..255]. If @major = 0, try to
312-
* allocate any unused major number.
311+
* @major: the requested major device number [1..BLKDEV_MAJOR_MAX-1]. If
312+
* @major = 0, try to allocate any unused major number.
313313
* @name: the name of the new block device as a zero terminated string
314314
*
315315
* The @name must be unique within the system.
316316
*
317317
* The return value depends on the @major input parameter:
318318
*
319-
* - if a major device number was requested in range [1..255] then the
320-
* function returns zero on success, or a negative error code
319+
* - if a major device number was requested in range [1..BLKDEV_MAJOR_MAX-1]
320+
* then the function returns zero on success, or a negative error code
321321
* - if any unused major number was requested with @major = 0 parameter
322322
* then the return value is the allocated major number in range
323-
* [1..255] or a negative error code otherwise
323+
* [1..BLKDEV_MAJOR_MAX-1] or a negative error code otherwise
324+
*
325+
* See Documentation/admin-guide/devices.txt for the list of allocated
326+
* major numbers.
324327
*/
325328
int register_blkdev(unsigned int major, const char *name)
326329
{
@@ -347,8 +350,8 @@ int register_blkdev(unsigned int major, const char *name)
347350
}
348351

349352
if (major >= BLKDEV_MAJOR_MAX) {
350-
pr_err("register_blkdev: major requested (%d) is greater than the maximum (%d) for %s\n",
351-
major, BLKDEV_MAJOR_MAX, name);
353+
pr_err("register_blkdev: major requested (%u) is greater than the maximum (%u) for %s\n",
354+
major, BLKDEV_MAJOR_MAX-1, name);
352355

353356
ret = -EINVAL;
354357
goto out;
@@ -375,7 +378,7 @@ int register_blkdev(unsigned int major, const char *name)
375378
ret = -EBUSY;
376379

377380
if (ret < 0) {
378-
printk("register_blkdev: cannot get major %d for %s\n",
381+
printk("register_blkdev: cannot get major %u for %s\n",
379382
major, name);
380383
kfree(p);
381384
}

‎fs/char_dev.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
121121
}
122122

123123
if (major >= CHRDEV_MAJOR_MAX) {
124-
pr_err("CHRDEV \"%s\" major requested (%d) is greater than the maximum (%d)\n",
125-
name, major, CHRDEV_MAJOR_MAX);
124+
pr_err("CHRDEV \"%s\" major requested (%u) is greater than the maximum (%u)\n",
125+
name, major, CHRDEV_MAJOR_MAX-1);
126126
ret = -EINVAL;
127127
goto out;
128128
}

0 commit comments

Comments
 (0)