Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f33ff110 authored by Srivatsa S. Bhat's avatar Srivatsa S. Bhat Committed by Greg Kroah-Hartman
Browse files

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: default avatarSrivatsa S. Bhat <srivatsa@csail.mit.edu>
Reviewed-by: default avatarLogan Gunthorpe <logang@deltatee.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 652d703b
Loading
Loading
Loading
Loading
+11 −8
Original line number Original line Diff line number Diff line
@@ -308,19 +308,22 @@ void blkdev_show(struct seq_file *seqf, off_t offset)
/**
/**
 * register_blkdev - register a new block device
 * register_blkdev - register a new block device
 *
 *
 * @major: the requested major device number [1..255]. If @major = 0, try to
 * @major: the requested major device number [1..BLKDEV_MAJOR_MAX-1]. If
 *         allocate any unused major number.
 *         @major = 0, try to allocate any unused major number.
 * @name: the name of the new block device as a zero terminated string
 * @name: the name of the new block device as a zero terminated string
 *
 *
 * The @name must be unique within the system.
 * The @name must be unique within the system.
 *
 *
 * The return value depends on the @major input parameter:
 * The return value depends on the @major input parameter:
 *
 *
 *  - if a major device number was requested in range [1..255] then the
 *  - if a major device number was requested in range [1..BLKDEV_MAJOR_MAX-1]
 *    function returns zero on success, or a negative error code
 *    then the function returns zero on success, or a negative error code
 *  - if any unused major number was requested with @major = 0 parameter
 *  - if any unused major number was requested with @major = 0 parameter
 *    then the return value is the allocated major number in range
 *    then the return value is the allocated major number in range
 *    [1..255] or a negative error code otherwise
 *    [1..BLKDEV_MAJOR_MAX-1] or a negative error code otherwise
 *
 * See Documentation/admin-guide/devices.txt for the list of allocated
 * major numbers.
 */
 */
int register_blkdev(unsigned int major, const char *name)
int register_blkdev(unsigned int major, const char *name)
{
{
@@ -347,8 +350,8 @@ int register_blkdev(unsigned int major, const char *name)
	}
	}


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


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


	if (ret < 0) {
	if (ret < 0) {
		printk("register_blkdev: cannot get major %d for %s\n",
		printk("register_blkdev: cannot get major %u for %s\n",
		       major, name);
		       major, name);
		kfree(p);
		kfree(p);
	}
	}
+2 −2
Original line number Original line Diff line number Diff line
@@ -121,8 +121,8 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
	}
	}


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