History

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().

Srivatsa S. Bhat committed 8 years ago

Commit f33ff111 parent 652d7032 files · +13 −10Browse files

Unified · Split

2 files
  1. block/genhd.c +11 −8
  2. fs/char_dev.c +2 −2
block/genhd.c+11−8
@@ -308,19 +308,22 @@ void blkdev_show(struct seq_file *seqf, off_t offset) · 307 unmodified lines
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) · 20 unmodified lines
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) · 20 unmodified lines
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+2−2
@@ -121,8 +121,8 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor, · 120 unmodified lines
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 }