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
308/**308/**
309 * register_blkdev - register a new block device309 * register_blkdev - register a new block device
310 *310 *
311 * @major: the requested major device number [1..255]. If @major = 0, try to311 * @major: the requested major device number [1..BLKDEV_MAJOR_MAX-1]. If
312 * allocate any unused major number.312 * @major = 0, try to allocate any unused major number.
313 * @name: the name of the new block device as a zero terminated string313 * @name: the name of the new block device as a zero terminated string
314 *314 *
315 * The @name must be unique within the system.315 * The @name must be unique within the system.
316 *316 *
317 * The return value depends on the @major input parameter: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 the319 * - if a major device number was requested in range [1..BLKDEV_MAJOR_MAX-1]
320 * function returns zero on success, or a negative error code320 * then the function returns zero on success, or a negative error code
321 * - if any unused major number was requested with @major = 0 parameter321 * - if any unused major number was requested with @major = 0 parameter
322 * then the return value is the allocated major number in range322 * then the return value is the allocated major number in range
323 * [1..255] or a negative error code otherwise323 * [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 */
325int register_blkdev(unsigned int major, const char *name)328int register_blkdev(unsigned int major, const char *name)
326{329{
@@ -347,8 +350,8 @@ int register_blkdev(unsigned int major, const char *name) · 20 unmodified lines
347 }350 }
348 351
349 if (major >= BLKDEV_MAJOR_MAX) {352 if (major >= BLKDEV_MAJOR_MAX) {
350 pr_err("register_blkdev: major requested (%d) is greater than the maximum (%d) for %s\n",353 pr_err("register_blkdev: major requested (%u) is greater than the maximum (%u) for %s\n",
351 major, BLKDEV_MAJOR_MAX, name);354 major, BLKDEV_MAJOR_MAX-1, name);
352 355
353 ret = -EINVAL;356 ret = -EINVAL;
354 goto out;357 goto out;
@@ -375,7 +378,7 @@ int register_blkdev(unsigned int major, const char *name) · 20 unmodified lines
375 ret = -EBUSY;378 ret = -EBUSY;
376 379
377 if (ret < 0) {380 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",
379 major, name);382 major, name);
380 kfree(p);383 kfree(p);
381 }384 }
fs/char_dev.c+2−2
@@ -121,8 +121,8 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor, · 120 unmodified lines
121 }121 }
122 122
123 if (major >= CHRDEV_MAJOR_MAX) {123 if (major >= CHRDEV_MAJOR_MAX) {
124 pr_err("CHRDEV \"%s\" major requested (%d) is greater than the maximum (%d)\n",124 pr_err("CHRDEV \"%s\" major requested (%u) is greater than the maximum (%u)\n",
125 name, major, CHRDEV_MAJOR_MAX);125 name, major, CHRDEV_MAJOR_MAX-1);
126 ret = -EINVAL;126 ret = -EINVAL;
127 goto out;127 goto out;
128 }128 }