Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Srivatsa S. Bhat and committed by
Greg Kroah-Hartman
f33ff110 652d703b

+13 -10
+11 -8
block/genhd.c
··· 308 308 /** 309 309 * register_blkdev - register a new block device 310 310 * 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. 313 313 * @name: the name of the new block device as a zero terminated string 314 314 * 315 315 * The @name must be unique within the system. 316 316 * 317 317 * The return value depends on the @major input parameter: 318 318 * 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 321 321 * - if any unused major number was requested with @major = 0 parameter 322 322 * 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. 324 327 */ 325 328 int register_blkdev(unsigned int major, const char *name) 326 329 { ··· 350 347 } 351 348 352 349 if (major >= BLKDEV_MAJOR_MAX) { 353 - pr_err("register_blkdev: major requested (%d) is greater than the maximum (%d) for %s\n", 354 - major, BLKDEV_MAJOR_MAX, name); 350 + pr_err("register_blkdev: major requested (%u) is greater than the maximum (%u) for %s\n", 351 + major, BLKDEV_MAJOR_MAX-1, name); 355 352 356 353 ret = -EINVAL; 357 354 goto out; ··· 378 375 ret = -EBUSY; 379 376 380 377 if (ret < 0) { 381 - printk("register_blkdev: cannot get major %d for %s\n", 378 + printk("register_blkdev: cannot get major %u for %s\n", 382 379 major, name); 383 380 kfree(p); 384 381 }
+2 -2
fs/char_dev.c
··· 121 121 } 122 122 123 123 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); 126 126 ret = -EINVAL; 127 127 goto out; 128 128 }