include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / ide / ide-proc.c
index b269264..a3133d7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Copyright (C) 1997-1998    Mark Lord
- *  Copyright (C) 2003         Red Hat <alan@redhat.com>
+ *  Copyright (C) 2003         Red Hat
  *
  *  Some code was moved here from ide.c, see it for original copyrights.
  */
 #include <linux/ctype.h>
 #include <linux/ide.h>
 #include <linux/seq_file.h>
+#include <linux/slab.h>
 
 #include <asm/io.h>
 
 static struct proc_dir_entry *proc_ide_root;
 
-static int proc_ide_read_imodel
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
+static int ide_imodel_proc_show(struct seq_file *m, void *v)
 {
-       ide_hwif_t      *hwif = (ide_hwif_t *) data;
-       int             len;
+       ide_hwif_t      *hwif = (ide_hwif_t *) m->private;
        const char      *name;
 
        switch (hwif->chipset) {
@@ -46,10 +45,6 @@ static int proc_ide_read_imodel
        case ide_qd65xx:        name = "qd65xx";        break;
        case ide_umc8672:       name = "umc8672";       break;
        case ide_ht6560b:       name = "ht6560b";       break;
-       case ide_rz1000:        name = "rz1000";        break;
-       case ide_trm290:        name = "trm290";        break;
-       case ide_cmd646:        name = "cmd646";        break;
-       case ide_cy82c693:      name = "cy82c693";      break;
        case ide_4drives:       name = "4drives";       break;
        case ide_pmac:          name = "mac-io";        break;
        case ide_au1xxx:        name = "au1xxx";        break;
@@ -57,63 +52,108 @@ static int proc_ide_read_imodel
        case ide_acorn:         name = "acorn";         break;
        default:                name = "(unknown)";     break;
        }
-       len = sprintf(page, "%s\n", name);
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+       seq_printf(m, "%s\n", name);
+       return 0;
+}
+
+static int ide_imodel_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, ide_imodel_proc_show, PDE(inode)->data);
 }
 
-static int proc_ide_read_mate
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
+static const struct file_operations ide_imodel_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = ide_imodel_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int ide_mate_proc_show(struct seq_file *m, void *v)
 {
-       ide_hwif_t      *hwif = (ide_hwif_t *) data;
-       int             len;
+       ide_hwif_t      *hwif = (ide_hwif_t *) m->private;
 
        if (hwif && hwif->mate)
-               len = sprintf(page, "%s\n", hwif->mate->name);
+               seq_printf(m, "%s\n", hwif->mate->name);
        else
-               len = sprintf(page, "(none)\n");
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+               seq_printf(m, "(none)\n");
+       return 0;
+}
+
+static int ide_mate_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, ide_mate_proc_show, PDE(inode)->data);
 }
 
-static int proc_ide_read_channel
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
+static const struct file_operations ide_mate_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = ide_mate_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int ide_channel_proc_show(struct seq_file *m, void *v)
 {
-       ide_hwif_t      *hwif = (ide_hwif_t *) data;
-       int             len;
+       ide_hwif_t      *hwif = (ide_hwif_t *) m->private;
 
-       page[0] = hwif->channel ? '1' : '0';
-       page[1] = '\n';
-       len = 2;
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+       seq_printf(m, "%c\n", hwif->channel ? '1' : '0');
+       return 0;
 }
 
-static int proc_ide_read_identify
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
+static int ide_channel_proc_open(struct inode *inode, struct file *file)
 {
-       ide_drive_t     *drive = (ide_drive_t *)data;
-       int             len = 0, i = 0;
-       int             err = 0;
+       return single_open(file, ide_channel_proc_show, PDE(inode)->data);
+}
+
+static const struct file_operations ide_channel_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = ide_channel_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
 
-       len = sprintf(page, "\n");
+static int ide_identify_proc_show(struct seq_file *m, void *v)
+{
+       ide_drive_t *drive = (ide_drive_t *)m->private;
+       u8 *buf;
 
-       if (drive) {
-               __le16 *val = (__le16 *)page;
+       if (!drive) {
+               seq_putc(m, '\n');
+               return 0;
+       }
 
-               err = taskfile_lib_get_identify(drive, page);
-               if (!err) {
-                       char *out = (char *)page + SECTOR_SIZE;
+       buf = kmalloc(SECTOR_SIZE, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+       if (taskfile_lib_get_identify(drive, buf) == 0) {
+               __le16 *val = (__le16 *)buf;
+               int i;
 
-                       page = out;
-                       do {
-                               out += sprintf(out, "%04x%c",
-                                       le16_to_cpup(val), (++i & 7) ? ' ' : '\n');
-                               val += 1;
-                       } while (i < SECTOR_SIZE / 2);
-                       len = out - page;
+               for (i = 0; i < SECTOR_SIZE / 2; i++) {
+                       seq_printf(m, "%04x%c", le16_to_cpu(val[i]),
+                                       (i % 8) == 7 ? '\n' : ' ');
                }
-       }
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+       } else
+               seq_putc(m, buf[0]);
+       kfree(buf);
+       return 0;
 }
 
+static int ide_identify_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, ide_identify_proc_show, PDE(inode)->data);
+}
+
+static const struct file_operations ide_identify_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = ide_identify_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
 /**
  *     ide_find_setting        -       find a specific setting
  *     @st: setting table pointer
@@ -155,13 +195,8 @@ static int ide_read_setting(ide_drive_t *drive,
        const struct ide_devset *ds = setting->setting;
        int val = -EINVAL;
 
-       if (ds->get) {
-               unsigned long flags;
-
-               spin_lock_irqsave(&ide_lock, flags);
+       if (ds->get)
                val = ds->get(drive);
-               spin_unlock_irqrestore(&ide_lock, flags);
-       }
 
        return val;
 }
@@ -203,26 +238,20 @@ ide_devset_get(xfer_rate, current_speed);
 
 static int set_xfer_rate (ide_drive_t *drive, int arg)
 {
-       ide_task_t task;
-       int err;
+       struct ide_cmd cmd;
 
        if (arg < XFER_PIO_0 || arg > XFER_UDMA_6)
                return -EINVAL;
 
-       memset(&task, 0, sizeof(task));
-       task.tf.command = ATA_CMD_SET_FEATURES;
-       task.tf.feature = SETFEATURES_XFER;
-       task.tf.nsect   = (u8)arg;
-       task.tf_flags = IDE_TFLAG_OUT_FEATURE | IDE_TFLAG_OUT_NSECT |
-                       IDE_TFLAG_IN_NSECT;
-
-       err = ide_no_data_taskfile(drive, &task);
+       memset(&cmd, 0, sizeof(cmd));
+       cmd.tf.command = ATA_CMD_SET_FEATURES;
+       cmd.tf.feature = SETFEATURES_XFER;
+       cmd.tf.nsect   = (u8)arg;
+       cmd.valid.out.tf = IDE_VALID_FEATURE | IDE_VALID_NSECT;
+       cmd.valid.in.tf  = IDE_VALID_NSECT;
+       cmd.tf_flags   = IDE_TFLAG_SET_XFER;
 
-       if (!err) {
-               ide_set_xfer_rate(drive, (u8) arg);
-               ide_driveid_update(drive);
-       }
-       return err;
+       return ide_no_data_taskfile(drive, &cmd);
 }
 
 ide_devset_rw(current_speed, xfer_rate);
@@ -240,37 +269,29 @@ static const struct ide_proc_devset ide_generic_settings[] = {
        IDE_PROC_DEVSET(pio_mode, 0, 255),
        IDE_PROC_DEVSET(unmaskirq, 0, 1),
        IDE_PROC_DEVSET(using_dma, 0, 1),
-       { 0 },
+       { NULL },
 };
 
 static void proc_ide_settings_warn(void)
 {
-       static int warned;
-
-       if (warned)
-               return;
-
-       printk(KERN_WARNING "Warning: /proc/ide/hd?/settings interface is "
+       printk_once(KERN_WARNING "Warning: /proc/ide/hd?/settings interface is "
                            "obsolete, and will be removed soon!\n");
-       warned = 1;
 }
 
-static int proc_ide_read_settings
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
+static int ide_settings_proc_show(struct seq_file *m, void *v)
 {
        const struct ide_proc_devset *setting, *g, *d;
        const struct ide_devset *ds;
-       ide_drive_t     *drive = (ide_drive_t *) data;
-       char            *out = page;
-       int             len, rc, mul_factor, div_factor;
+       ide_drive_t     *drive = (ide_drive_t *) m->private;
+       int             rc, mul_factor, div_factor;
 
        proc_ide_settings_warn();
 
        mutex_lock(&ide_setting_mtx);
        g = ide_generic_settings;
        d = drive->settings;
-       out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
-       out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
+       seq_printf(m, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
+       seq_printf(m, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
        while (g->name || (d && d->name)) {
                /* read settings in the alphabetical order */
                if (g->name && d && d->name) {
@@ -284,31 +305,35 @@ static int proc_ide_read_settings
                        setting = g++;
                mul_factor = setting->mulf ? setting->mulf(drive) : 1;
                div_factor = setting->divf ? setting->divf(drive) : 1;
-               out += sprintf(out, "%-24s", setting->name);
+               seq_printf(m, "%-24s", setting->name);
                rc = ide_read_setting(drive, setting);
                if (rc >= 0)
-                       out += sprintf(out, "%-16d", rc * mul_factor / div_factor);
+                       seq_printf(m, "%-16d", rc * mul_factor / div_factor);
                else
-                       out += sprintf(out, "%-16s", "write-only");
-               out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor);
+                       seq_printf(m, "%-16s", "write-only");
+               seq_printf(m, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor);
                ds = setting->setting;
                if (ds->get)
-                       out += sprintf(out, "r");
+                       seq_printf(m, "r");
                if (ds->set)
-                       out += sprintf(out, "w");
-               out += sprintf(out, "\n");
+                       seq_printf(m, "w");
+               seq_printf(m, "\n");
        }
-       len = out - page;
        mutex_unlock(&ide_setting_mtx);
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+       return 0;
+}
+
+static int ide_settings_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, ide_settings_proc_show, PDE(inode)->data);
 }
 
 #define MAX_LEN        30
 
-static int proc_ide_write_settings(struct file *file, const char __user *buffer,
-                                  unsigned long count, void *data)
+static ssize_t ide_settings_proc_write(struct file *file, const char __user *buffer,
+                                      size_t count, loff_t *pos)
 {
-       ide_drive_t     *drive = (ide_drive_t *) data;
+       ide_drive_t     *drive = (ide_drive_t *) PDE(file->f_path.dentry->d_inode)->data;
        char            name[MAX_LEN + 1];
        int             for_real = 0, mul_factor, div_factor;
        unsigned long   n;
@@ -403,63 +428,104 @@ static int proc_ide_write_settings(struct file *file, const char __user *buffer,
        return count;
 parse_error:
        free_page((unsigned long)buf);
-       printk("proc_ide_write_settings(): parse error\n");
+       printk("%s(): parse error\n", __func__);
        return -EINVAL;
 }
 
-int proc_ide_read_capacity
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
+static const struct file_operations ide_settings_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = ide_settings_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+       .write          = ide_settings_proc_write,
+};
+
+static int ide_capacity_proc_show(struct seq_file *m, void *v)
+{
+       seq_printf(m, "%llu\n", (long long)0x7fffffff);
+       return 0;
+}
+
+static int ide_capacity_proc_open(struct inode *inode, struct file *file)
 {
-       int len = sprintf(page, "%llu\n", (long long)0x7fffffff);
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+       return single_open(file, ide_capacity_proc_show, NULL);
 }
 
-EXPORT_SYMBOL_GPL(proc_ide_read_capacity);
+const struct file_operations ide_capacity_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = ide_capacity_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+EXPORT_SYMBOL_GPL(ide_capacity_proc_fops);
 
-int proc_ide_read_geometry
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
+static int ide_geometry_proc_show(struct seq_file *m, void *v)
 {
-       ide_drive_t     *drive = (ide_drive_t *) data;
-       char            *out = page;
-       int             len;
+       ide_drive_t     *drive = (ide_drive_t *) m->private;
 
-       out += sprintf(out, "physical     %d/%d/%d\n",
+       seq_printf(m, "physical     %d/%d/%d\n",
                        drive->cyl, drive->head, drive->sect);
-       out += sprintf(out, "logical      %d/%d/%d\n",
+       seq_printf(m, "logical      %d/%d/%d\n",
                        drive->bios_cyl, drive->bios_head, drive->bios_sect);
+       return 0;
+}
 
-       len = out - page;
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+static int ide_geometry_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, ide_geometry_proc_show, PDE(inode)->data);
 }
 
-EXPORT_SYMBOL(proc_ide_read_geometry);
+const struct file_operations ide_geometry_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = ide_geometry_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+EXPORT_SYMBOL(ide_geometry_proc_fops);
 
-static int proc_ide_read_dmodel
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
+static int ide_dmodel_proc_show(struct seq_file *seq, void *v)
 {
-       ide_drive_t     *drive = (ide_drive_t *) data;
+       ide_drive_t     *drive = (ide_drive_t *) seq->private;
        char            *m = (char *)&drive->id[ATA_ID_PROD];
-       int             len;
 
-       len = sprintf(page, "%.40s\n", m[0] ? m : "(none)");
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+       seq_printf(seq, "%.40s\n", m[0] ? m : "(none)");
+       return 0;
 }
 
-static int proc_ide_read_driver
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
+static int ide_dmodel_proc_open(struct inode *inode, struct file *file)
 {
-       ide_drive_t     *drive = (ide_drive_t *) data;
-       struct device   *dev = &drive->gendev;
-       ide_driver_t    *ide_drv;
-       int             len;
+       return single_open(file, ide_dmodel_proc_show, PDE(inode)->data);
+}
+
+static const struct file_operations ide_dmodel_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = ide_dmodel_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int ide_driver_proc_show(struct seq_file *m, void *v)
+{
+       ide_drive_t             *drive = (ide_drive_t *)m->private;
+       struct device           *dev = &drive->gendev;
+       struct ide_driver       *ide_drv;
 
        if (dev->driver) {
-               ide_drv = container_of(dev->driver, ide_driver_t, gen_driver);
-               len = sprintf(page, "%s version %s\n",
+               ide_drv = to_ide_driver(dev->driver);
+               seq_printf(m, "%s version %s\n",
                                dev->driver->name, ide_drv->version);
        } else
-               len = sprintf(page, "ide-default version 0.9.newide\n");
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+               seq_printf(m, "ide-default version 0.9.newide\n");
+       return 0;
+}
+
+static int ide_driver_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, ide_driver_proc_show, PDE(inode)->data);
 }
 
 static int ide_replace_subdriver(ide_drive_t *drive, const char *driver)
@@ -489,10 +555,10 @@ static int ide_replace_subdriver(ide_drive_t *drive, const char *driver)
        return ret;
 }
 
-static int proc_ide_write_driver
-       (struct file *file, const char __user *buffer, unsigned long count, void *data)
+static ssize_t ide_driver_proc_write(struct file *file, const char __user *buffer,
+                                    size_t count, loff_t *pos)
 {
-       ide_drive_t     *drive = (ide_drive_t *) data;
+       ide_drive_t     *drive = (ide_drive_t *) PDE(file->f_path.dentry->d_inode)->data;
        char name[32];
 
        if (!capable(CAP_SYS_ADMIN))
@@ -507,12 +573,19 @@ static int proc_ide_write_driver
        return count;
 }
 
-static int proc_ide_read_media
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
+static const struct file_operations ide_driver_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = ide_driver_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+       .write          = ide_driver_proc_write,
+};
+
+static int ide_media_proc_show(struct seq_file *m, void *v)
 {
-       ide_drive_t     *drive = (ide_drive_t *) data;
+       ide_drive_t     *drive = (ide_drive_t *) m->private;
        const char      *media;
-       int             len;
 
        switch (drive->media) {
        case ide_disk:          media = "disk\n";       break;
@@ -522,20 +595,30 @@ static int proc_ide_read_media
        case ide_optical:       media = "optical\n";    break;
        default:                media = "UNKNOWN\n";    break;
        }
-       strcpy(page, media);
-       len = strlen(media);
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+       seq_puts(m, media);
+       return 0;
 }
 
+static int ide_media_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, ide_media_proc_show, PDE(inode)->data);
+}
+
+static const struct file_operations ide_media_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = ide_media_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
 static ide_proc_entry_t generic_drive_entries[] = {
-       { "driver",     S_IFREG|S_IRUGO,         proc_ide_read_driver,
-                                                proc_ide_write_driver },
-       { "identify",   S_IFREG|S_IRUSR,         proc_ide_read_identify, NULL },
-       { "media",      S_IFREG|S_IRUGO,         proc_ide_read_media,    NULL },
-       { "model",      S_IFREG|S_IRUGO,         proc_ide_read_dmodel,   NULL },
-       { "settings",   S_IFREG|S_IRUSR|S_IWUSR, proc_ide_read_settings,
-                                                proc_ide_write_settings },
-       { NULL, 0, NULL, NULL }
+       { "driver",     S_IFREG|S_IRUGO,         &ide_driver_proc_fops  },
+       { "identify",   S_IFREG|S_IRUSR,         &ide_identify_proc_fops},
+       { "media",      S_IFREG|S_IRUGO,         &ide_media_proc_fops   },
+       { "model",      S_IFREG|S_IRUGO,         &ide_dmodel_proc_fops  },
+       { "settings",   S_IFREG|S_IRUSR|S_IWUSR, &ide_settings_proc_fops},
+       {}
 };
 
 static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data)
@@ -545,11 +628,8 @@ static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p
        if (!dir || !p)
                return;
        while (p->name != NULL) {
-               ent = create_proc_entry(p->name, p->mode, dir);
+               ent = proc_create_data(p->name, p->mode, dir, p->proc_fops, data);
                if (!ent) return;
-               ent->data = data;
-               ent->read_proc = p->read_proc;
-               ent->write_proc = p->write_proc;
                p++;
        }
 }
@@ -564,13 +644,13 @@ static void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t
        }
 }
 
-void ide_proc_register_driver(ide_drive_t *drive, ide_driver_t *driver)
+void ide_proc_register_driver(ide_drive_t *drive, struct ide_driver *driver)
 {
        mutex_lock(&ide_setting_mtx);
-       drive->settings = driver->settings;
+       drive->settings = driver->proc_devsets(drive);
        mutex_unlock(&ide_setting_mtx);
 
-       ide_add_proc_entries(drive->proc, driver->proc, drive);
+       ide_add_proc_entries(drive->proc, driver->proc_entries(drive), drive);
 }
 
 EXPORT_SYMBOL(ide_proc_register_driver);
@@ -583,46 +663,33 @@ EXPORT_SYMBOL(ide_proc_register_driver);
  *     Clean up the driver specific /proc files and IDE settings
  *     for a given drive.
  *
- *     Takes ide_setting_mtx and ide_lock.
- *     Caller must hold none of the locks.
+ *     Takes ide_setting_mtx.
  */
 
-void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver)
+void ide_proc_unregister_driver(ide_drive_t *drive, struct ide_driver *driver)
 {
-       unsigned long flags;
-
-       ide_remove_proc_entries(drive->proc, driver->proc);
+       ide_remove_proc_entries(drive->proc, driver->proc_entries(drive));
 
        mutex_lock(&ide_setting_mtx);
-       spin_lock_irqsave(&ide_lock, flags);
        /*
-        * ide_setting_mtx protects the settings list
-        * ide_lock protects the use of settings
-        *
-        * so we need to hold both, ide_settings_sem because we want to
-        * modify the settings list, and ide_lock because we cannot take
-        * a setting out that is being used.
-        *
-        * OTOH both ide_{read,write}_setting are only ever used under
-        * ide_setting_mtx.
+        * ide_setting_mtx protects both the settings list and the use
+        * of settings (we cannot take a setting out that is being used).
         */
        drive->settings = NULL;
-       spin_unlock_irqrestore(&ide_lock, flags);
        mutex_unlock(&ide_setting_mtx);
 }
 EXPORT_SYMBOL(ide_proc_unregister_driver);
 
 void ide_proc_port_register_devices(ide_hwif_t *hwif)
 {
-       int     d;
        struct proc_dir_entry *ent;
        struct proc_dir_entry *parent = hwif->proc;
+       ide_drive_t *drive;
        char name[64];
+       int i;
 
-       for (d = 0; d < MAX_DRIVES; d++) {
-               ide_drive_t *drive = &hwif->drives[d];
-
-               if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0 || drive->proc)
+       ide_port_for_each_dev(i, drive, hwif) {
+               if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
                        continue;
 
                drive->proc = proc_mkdir(drive->name, parent);
@@ -645,10 +712,10 @@ void ide_proc_unregister_device(ide_drive_t *drive)
 }
 
 static ide_proc_entry_t hwif_entries[] = {
-       { "channel",    S_IFREG|S_IRUGO,        proc_ide_read_channel,  NULL },
-       { "mate",       S_IFREG|S_IRUGO,        proc_ide_read_mate,     NULL },
-       { "model",      S_IFREG|S_IRUGO,        proc_ide_read_imodel,   NULL },
-       { NULL, 0, NULL, NULL }
+       { "channel",    S_IFREG|S_IRUGO,        &ide_channel_proc_fops  },
+       { "mate",       S_IFREG|S_IRUGO,        &ide_mate_proc_fops     },
+       { "model",      S_IFREG|S_IRUGO,        &ide_imodel_proc_fops   },
+       {}
 };
 
 void ide_proc_register_port(ide_hwif_t *hwif)
@@ -674,7 +741,7 @@ void ide_proc_unregister_port(ide_hwif_t *hwif)
 
 static int proc_print_driver(struct device_driver *drv, void *data)
 {
-       ide_driver_t *ide_drv = container_of(drv, ide_driver_t, gen_driver);
+       struct ide_driver *ide_drv = to_ide_driver(drv);
        struct seq_file *s = data;
 
        seq_printf(s, "%s version %s\n", drv->name, ide_drv->version);