Commit 482a9473 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] dev_t printing

From: Greg KH <greg@kroah.com>

Different architectures use different types for dev_t, so it is hard to
print dev_t variables out correctly.  Quite a lot of code is wrong now, and
will continue to be wrong when 64-bit dev_t is merged.

Greg's patch introduces a little wrapper function which can be used to
safely form a dev_t for printing.  I added the format_dev_t function as
well, which is needed for direct insertion in a printk statement.
parent 81e99e7f
......@@ -336,7 +336,7 @@ static struct sysfs_ops disk_sysfs_ops = {
static ssize_t disk_dev_read(struct gendisk * disk, char *page)
{
dev_t base = MKDEV(disk->major, disk->first_minor);
return sprintf(page, "%04x\n", (unsigned)base);
return print_dev_t(page, base);
}
static ssize_t disk_range_read(struct gendisk * disk, char *page)
{
......
......@@ -2110,7 +2110,7 @@ static spinlock_t tty_dev_list_lock = SPIN_LOCK_UNLOCKED;
static ssize_t show_dev(struct class_device *class_dev, char *buf)
{
struct tty_dev *tty_dev = to_tty_dev(class_dev);
return sprintf(buf, "%04lx\n", (unsigned long)tty_dev->dev);
return print_dev_t(buf, tty_dev->dev);
}
static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
......
......@@ -118,7 +118,7 @@ static void return_i2c_dev(struct i2c_dev *i2c_dev)
static ssize_t show_dev(struct class_device *class_dev, char *buf)
{
struct i2c_dev *i2c_dev = to_i2c_dev(class_dev);
return sprintf(buf, "%04x\n", MKDEV(I2C_MAJOR, i2c_dev->minor));
return print_dev_t(buf, MKDEV(I2C_MAJOR, i2c_dev->minor));
}
static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
......
......@@ -93,7 +93,7 @@ static ssize_t show_dev(struct class_device *class_dev, char *buf)
{
struct usb_interface *intf = class_dev_to_usb_interface(class_dev);
dev_t dev = MKDEV(USB_MAJOR, intf->minor);
return sprintf(buf, "%04x\n", dev);
return print_dev_t(buf, dev);
}
static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
......
......@@ -133,6 +133,15 @@ static inline kdev_t to_kdev_t(int dev)
return mk_kdev(MAJOR(dev),MINOR(dev));
}
#define print_dev_t(buffer, dev) \
sprintf((buffer), "%u:%u\n", MAJOR(dev), MINOR(dev))
#define format_dev_t(buffer, dev) \
({ \
sprintf(buffer, "%u:%u", MAJOR(dev), MINOR(dev)); \
buffer; \
})
#else /* __KERNEL__ */
/*
......
......@@ -58,6 +58,7 @@ static dev_t __init try_name(char *name, int part)
char *s;
int len;
int fd;
unsigned int maj, min;
/* read device number from .../dev */
......@@ -70,8 +71,12 @@ static dev_t __init try_name(char *name, int part)
if (len <= 0 || len == 32 || buf[len - 1] != '\n')
goto fail;
buf[len - 1] = '\0';
res = (dev_t) simple_strtoul(buf, &s, 16);
if (*s)
/*
* The format of dev is now %u:%u -- see print_dev_t()
*/
if (sscanf(buf, "%u:%u", &maj, &min) == 2)
res = MKDEV(maj, min);
else
goto fail;
/* if it's there and we are not looking for a partition - that's it */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment