Commit 5aeddf90 authored by Borislav Petkov's avatar Borislav Petkov Committed by Bartlomiej Zolnierkiewicz

ide: unify conversion macros

Introduce to_ide_drv() and ide_drv_g() macros and replace the respective
definitions of similar ones in each driver.

There should be no functionality change resulting from this patch.
Signed-off-by: default avatarBorislav Petkov <petkovbb@gmail.com>
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
parent 91ddc998
...@@ -52,11 +52,6 @@ ...@@ -52,11 +52,6 @@
static DEFINE_MUTEX(idecd_ref_mutex); static DEFINE_MUTEX(idecd_ref_mutex);
#define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref)
#define ide_cd_g(disk) \
container_of((disk)->private_data, struct cdrom_info, driver)
static void ide_cd_release(struct kref *); static void ide_cd_release(struct kref *);
static struct cdrom_info *ide_cd_get(struct gendisk *disk) static struct cdrom_info *ide_cd_get(struct gendisk *disk)
...@@ -64,7 +59,7 @@ static struct cdrom_info *ide_cd_get(struct gendisk *disk) ...@@ -64,7 +59,7 @@ static struct cdrom_info *ide_cd_get(struct gendisk *disk)
struct cdrom_info *cd = NULL; struct cdrom_info *cd = NULL;
mutex_lock(&idecd_ref_mutex); mutex_lock(&idecd_ref_mutex);
cd = ide_cd_g(disk); cd = ide_drv_g(disk, cdrom_info);
if (cd) { if (cd) {
if (ide_device_get(cd->drive)) if (ide_device_get(cd->drive))
cd = NULL; cd = NULL;
...@@ -1941,7 +1936,7 @@ static void ide_cd_remove(ide_drive_t *drive) ...@@ -1941,7 +1936,7 @@ static void ide_cd_remove(ide_drive_t *drive)
static void ide_cd_release(struct kref *kref) static void ide_cd_release(struct kref *kref)
{ {
struct cdrom_info *info = to_ide_cd(kref); struct cdrom_info *info = to_ide_drv(kref, cdrom_info);
struct cdrom_device_info *devinfo = &info->devinfo; struct cdrom_device_info *devinfo = &info->devinfo;
ide_drive_t *drive = info->drive; ide_drive_t *drive = info->drive;
struct gendisk *g = info->disk; struct gendisk *g = info->disk;
...@@ -1999,7 +1994,7 @@ static int idecd_open(struct inode *inode, struct file *file) ...@@ -1999,7 +1994,7 @@ static int idecd_open(struct inode *inode, struct file *file)
static int idecd_release(struct inode *inode, struct file *file) static int idecd_release(struct inode *inode, struct file *file)
{ {
struct gendisk *disk = inode->i_bdev->bd_disk; struct gendisk *disk = inode->i_bdev->bd_disk;
struct cdrom_info *info = ide_cd_g(disk); struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
cdrom_release(&info->devinfo, file); cdrom_release(&info->devinfo, file);
...@@ -2051,7 +2046,7 @@ static int idecd_ioctl(struct inode *inode, struct file *file, ...@@ -2051,7 +2046,7 @@ static int idecd_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
struct block_device *bdev = inode->i_bdev; struct block_device *bdev = inode->i_bdev;
struct cdrom_info *info = ide_cd_g(bdev->bd_disk); struct cdrom_info *info = ide_drv_g(bdev->bd_disk, cdrom_info);
int err; int err;
switch (cmd) { switch (cmd) {
...@@ -2072,13 +2067,13 @@ static int idecd_ioctl(struct inode *inode, struct file *file, ...@@ -2072,13 +2067,13 @@ static int idecd_ioctl(struct inode *inode, struct file *file,
static int idecd_media_changed(struct gendisk *disk) static int idecd_media_changed(struct gendisk *disk)
{ {
struct cdrom_info *info = ide_cd_g(disk); struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
return cdrom_media_changed(&info->devinfo); return cdrom_media_changed(&info->devinfo);
} }
static int idecd_revalidate_disk(struct gendisk *disk) static int idecd_revalidate_disk(struct gendisk *disk)
{ {
struct cdrom_info *info = ide_cd_g(disk); struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
struct request_sense sense; struct request_sense sense;
ide_cd_read_toc(info->drive, &sense); ide_cd_read_toc(info->drive, &sense);
......
...@@ -84,11 +84,6 @@ ...@@ -84,11 +84,6 @@
static DEFINE_MUTEX(idefloppy_ref_mutex); static DEFINE_MUTEX(idefloppy_ref_mutex);
#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
#define ide_floppy_g(disk) \
container_of((disk)->private_data, struct ide_floppy_obj, driver)
static void idefloppy_cleanup_obj(struct kref *); static void idefloppy_cleanup_obj(struct kref *);
static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk) static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
...@@ -96,7 +91,7 @@ static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk) ...@@ -96,7 +91,7 @@ static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
struct ide_floppy_obj *floppy = NULL; struct ide_floppy_obj *floppy = NULL;
mutex_lock(&idefloppy_ref_mutex); mutex_lock(&idefloppy_ref_mutex);
floppy = ide_floppy_g(disk); floppy = ide_drv_g(disk, ide_floppy_obj);
if (floppy) { if (floppy) {
if (ide_device_get(floppy->drive)) if (ide_device_get(floppy->drive))
floppy = NULL; floppy = NULL;
...@@ -625,7 +620,7 @@ static void ide_floppy_remove(ide_drive_t *drive) ...@@ -625,7 +620,7 @@ static void ide_floppy_remove(ide_drive_t *drive)
static void idefloppy_cleanup_obj(struct kref *kref) static void idefloppy_cleanup_obj(struct kref *kref)
{ {
struct ide_floppy_obj *floppy = to_ide_floppy(kref); struct ide_floppy_obj *floppy = to_ide_drv(kref, ide_floppy_obj);
ide_drive_t *drive = floppy->drive; ide_drive_t *drive = floppy->drive;
struct gendisk *g = floppy->disk; struct gendisk *g = floppy->disk;
...@@ -733,7 +728,7 @@ static int idefloppy_open(struct inode *inode, struct file *filp) ...@@ -733,7 +728,7 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
static int idefloppy_release(struct inode *inode, struct file *filp) static int idefloppy_release(struct inode *inode, struct file *filp)
{ {
struct gendisk *disk = inode->i_bdev->bd_disk; struct gendisk *disk = inode->i_bdev->bd_disk;
struct ide_floppy_obj *floppy = ide_floppy_g(disk); struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
ide_drive_t *drive = floppy->drive; ide_drive_t *drive = floppy->drive;
debug_log("Reached %s\n", __func__); debug_log("Reached %s\n", __func__);
...@@ -752,7 +747,8 @@ static int idefloppy_release(struct inode *inode, struct file *filp) ...@@ -752,7 +747,8 @@ static int idefloppy_release(struct inode *inode, struct file *filp)
static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo) static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
{ {
struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk); struct ide_floppy_obj *floppy = ide_drv_g(bdev->bd_disk,
ide_floppy_obj);
ide_drive_t *drive = floppy->drive; ide_drive_t *drive = floppy->drive;
geo->heads = drive->bios_head; geo->heads = drive->bios_head;
...@@ -783,7 +779,8 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file, ...@@ -783,7 +779,8 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
struct block_device *bdev = inode->i_bdev; struct block_device *bdev = inode->i_bdev;
struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk); struct ide_floppy_obj *floppy = ide_drv_g(bdev->bd_disk,
ide_floppy_obj);
ide_drive_t *drive = floppy->drive; ide_drive_t *drive = floppy->drive;
struct ide_atapi_pc pc; struct ide_atapi_pc pc;
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
...@@ -812,7 +809,7 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file, ...@@ -812,7 +809,7 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file,
static int idefloppy_media_changed(struct gendisk *disk) static int idefloppy_media_changed(struct gendisk *disk)
{ {
struct ide_floppy_obj *floppy = ide_floppy_g(disk); struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
ide_drive_t *drive = floppy->drive; ide_drive_t *drive = floppy->drive;
int ret; int ret;
...@@ -828,7 +825,7 @@ static int idefloppy_media_changed(struct gendisk *disk) ...@@ -828,7 +825,7 @@ static int idefloppy_media_changed(struct gendisk *disk)
static int idefloppy_revalidate_disk(struct gendisk *disk) static int idefloppy_revalidate_disk(struct gendisk *disk)
{ {
struct ide_floppy_obj *floppy = ide_floppy_g(disk); struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
set_capacity(disk, idefloppy_capacity(floppy->drive)); set_capacity(disk, idefloppy_capacity(floppy->drive));
return 0; return 0;
} }
......
...@@ -267,11 +267,6 @@ static DEFINE_MUTEX(idetape_ref_mutex); ...@@ -267,11 +267,6 @@ static DEFINE_MUTEX(idetape_ref_mutex);
static struct class *idetape_sysfs_class; static struct class *idetape_sysfs_class;
#define to_ide_tape(obj) container_of(obj, struct ide_tape_obj, kref)
#define ide_tape_g(disk) \
container_of((disk)->private_data, struct ide_tape_obj, driver)
static void ide_tape_release(struct kref *); static void ide_tape_release(struct kref *);
static struct ide_tape_obj *ide_tape_get(struct gendisk *disk) static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
...@@ -279,7 +274,7 @@ static struct ide_tape_obj *ide_tape_get(struct gendisk *disk) ...@@ -279,7 +274,7 @@ static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
struct ide_tape_obj *tape = NULL; struct ide_tape_obj *tape = NULL;
mutex_lock(&idetape_ref_mutex); mutex_lock(&idetape_ref_mutex);
tape = ide_tape_g(disk); tape = ide_drv_g(disk, ide_tape_obj);
if (tape) { if (tape) {
if (ide_device_get(tape->drive)) if (ide_device_get(tape->drive))
tape = NULL; tape = NULL;
...@@ -306,8 +301,6 @@ static void ide_tape_put(struct ide_tape_obj *tape) ...@@ -306,8 +301,6 @@ static void ide_tape_put(struct ide_tape_obj *tape)
*/ */
static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES]; static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES];
#define ide_tape_f(file) ((file)->private_data)
static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i) static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
{ {
struct ide_tape_obj *tape = NULL; struct ide_tape_obj *tape = NULL;
...@@ -1542,7 +1535,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op, ...@@ -1542,7 +1535,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
static ssize_t idetape_chrdev_read(struct file *file, char __user *buf, static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct ide_tape_obj *tape = ide_tape_f(file); struct ide_tape_obj *tape = file->private_data;
ide_drive_t *drive = tape->drive; ide_drive_t *drive = tape->drive;
ssize_t bytes_read, temp, actually_read = 0, rc; ssize_t bytes_read, temp, actually_read = 0, rc;
ssize_t ret = 0; ssize_t ret = 0;
...@@ -1604,7 +1597,7 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf, ...@@ -1604,7 +1597,7 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf, static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct ide_tape_obj *tape = ide_tape_f(file); struct ide_tape_obj *tape = file->private_data;
ide_drive_t *drive = tape->drive; ide_drive_t *drive = tape->drive;
ssize_t actually_written = 0; ssize_t actually_written = 0;
ssize_t ret = 0; ssize_t ret = 0;
...@@ -1836,7 +1829,7 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count) ...@@ -1836,7 +1829,7 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
static int idetape_chrdev_ioctl(struct inode *inode, struct file *file, static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
struct ide_tape_obj *tape = ide_tape_f(file); struct ide_tape_obj *tape = file->private_data;
ide_drive_t *drive = tape->drive; ide_drive_t *drive = tape->drive;
struct mtop mtop; struct mtop mtop;
struct mtget mtget; struct mtget mtget;
...@@ -2013,7 +2006,7 @@ static void idetape_write_release(ide_drive_t *drive, unsigned int minor) ...@@ -2013,7 +2006,7 @@ static void idetape_write_release(ide_drive_t *drive, unsigned int minor)
static int idetape_chrdev_release(struct inode *inode, struct file *filp) static int idetape_chrdev_release(struct inode *inode, struct file *filp)
{ {
struct ide_tape_obj *tape = ide_tape_f(filp); struct ide_tape_obj *tape = filp->private_data;
ide_drive_t *drive = tape->drive; ide_drive_t *drive = tape->drive;
unsigned int minor = iminor(inode); unsigned int minor = iminor(inode);
...@@ -2272,7 +2265,7 @@ static void ide_tape_remove(ide_drive_t *drive) ...@@ -2272,7 +2265,7 @@ static void ide_tape_remove(ide_drive_t *drive)
static void ide_tape_release(struct kref *kref) static void ide_tape_release(struct kref *kref)
{ {
struct ide_tape_obj *tape = to_ide_tape(kref); struct ide_tape_obj *tape = to_ide_drv(kref, ide_tape_obj);
ide_drive_t *drive = tape->drive; ide_drive_t *drive = tape->drive;
struct gendisk *g = tape->disk; struct gendisk *g = tape->disk;
...@@ -2355,7 +2348,7 @@ static int idetape_open(struct inode *inode, struct file *filp) ...@@ -2355,7 +2348,7 @@ static int idetape_open(struct inode *inode, struct file *filp)
static int idetape_release(struct inode *inode, struct file *filp) static int idetape_release(struct inode *inode, struct file *filp)
{ {
struct gendisk *disk = inode->i_bdev->bd_disk; struct gendisk *disk = inode->i_bdev->bd_disk;
struct ide_tape_obj *tape = ide_tape_g(disk); struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj);
ide_tape_put(tape); ide_tape_put(tape);
...@@ -2366,7 +2359,7 @@ static int idetape_ioctl(struct inode *inode, struct file *file, ...@@ -2366,7 +2359,7 @@ static int idetape_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
struct block_device *bdev = inode->i_bdev; struct block_device *bdev = inode->i_bdev;
struct ide_tape_obj *tape = ide_tape_g(bdev->bd_disk); struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj);
ide_drive_t *drive = tape->drive; ide_drive_t *drive = tape->drive;
int err = generic_ide_ioctl(drive, file, bdev, cmd, arg); int err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
if (err == -EINVAL) if (err == -EINVAL)
......
...@@ -570,7 +570,13 @@ struct ide_drive_s { ...@@ -570,7 +570,13 @@ struct ide_drive_s {
typedef struct ide_drive_s ide_drive_t; typedef struct ide_drive_s ide_drive_t;
#define to_ide_device(dev)container_of(dev, ide_drive_t, gendev) #define to_ide_device(dev) container_of(dev, ide_drive_t, gendev)
#define to_ide_drv(obj, cont_type) \
container_of(obj, struct cont_type, kref)
#define ide_drv_g(disk, cont_type) \
container_of((disk)->private_data, struct cont_type, driver)
struct ide_task_s; struct ide_task_s;
struct ide_port_info; struct ide_port_info;
......
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