ide: add ide_device_{get,put}() helpers
* Add 'struct ide_host *host' field to ide_hwif_t and set it in ide_host_alloc_all(). * Add ide_device_{get,put}() helpers loosely based on SCSI's scsi_device_{get,put}() ones. * Convert IDE device drivers to use ide_device_{get,put}(). Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
This commit is contained in:
parent
6cdf6eb357
commit
08da591e14
@ -57,23 +57,29 @@ static DEFINE_MUTEX(idecd_ref_mutex);
|
|||||||
#define ide_cd_g(disk) \
|
#define ide_cd_g(disk) \
|
||||||
container_of((disk)->private_data, struct cdrom_info, driver)
|
container_of((disk)->private_data, struct cdrom_info, driver)
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
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_cd_g(disk);
|
||||||
if (cd)
|
if (cd) {
|
||||||
kref_get(&cd->kref);
|
kref_get(&cd->kref);
|
||||||
|
if (ide_device_get(cd->drive)) {
|
||||||
|
kref_put(&cd->kref, ide_cd_release);
|
||||||
|
cd = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
mutex_unlock(&idecd_ref_mutex);
|
mutex_unlock(&idecd_ref_mutex);
|
||||||
return cd;
|
return cd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ide_cd_release(struct kref *);
|
|
||||||
|
|
||||||
static void ide_cd_put(struct cdrom_info *cd)
|
static void ide_cd_put(struct cdrom_info *cd)
|
||||||
{
|
{
|
||||||
mutex_lock(&idecd_ref_mutex);
|
mutex_lock(&idecd_ref_mutex);
|
||||||
|
ide_device_put(cd->drive);
|
||||||
kref_put(&cd->kref, ide_cd_release);
|
kref_put(&cd->kref, ide_cd_release);
|
||||||
mutex_unlock(&idecd_ref_mutex);
|
mutex_unlock(&idecd_ref_mutex);
|
||||||
}
|
}
|
||||||
|
@ -56,23 +56,29 @@ static DEFINE_MUTEX(idedisk_ref_mutex);
|
|||||||
#define ide_disk_g(disk) \
|
#define ide_disk_g(disk) \
|
||||||
container_of((disk)->private_data, struct ide_disk_obj, driver)
|
container_of((disk)->private_data, struct ide_disk_obj, driver)
|
||||||
|
|
||||||
|
static void ide_disk_release(struct kref *);
|
||||||
|
|
||||||
static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
|
static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
|
||||||
{
|
{
|
||||||
struct ide_disk_obj *idkp = NULL;
|
struct ide_disk_obj *idkp = NULL;
|
||||||
|
|
||||||
mutex_lock(&idedisk_ref_mutex);
|
mutex_lock(&idedisk_ref_mutex);
|
||||||
idkp = ide_disk_g(disk);
|
idkp = ide_disk_g(disk);
|
||||||
if (idkp)
|
if (idkp) {
|
||||||
kref_get(&idkp->kref);
|
kref_get(&idkp->kref);
|
||||||
|
if (ide_device_get(idkp->drive)) {
|
||||||
|
kref_put(&idkp->kref, ide_disk_release);
|
||||||
|
idkp = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
mutex_unlock(&idedisk_ref_mutex);
|
mutex_unlock(&idedisk_ref_mutex);
|
||||||
return idkp;
|
return idkp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ide_disk_release(struct kref *);
|
|
||||||
|
|
||||||
static void ide_disk_put(struct ide_disk_obj *idkp)
|
static void ide_disk_put(struct ide_disk_obj *idkp)
|
||||||
{
|
{
|
||||||
mutex_lock(&idedisk_ref_mutex);
|
mutex_lock(&idedisk_ref_mutex);
|
||||||
|
ide_device_put(idkp->drive);
|
||||||
kref_put(&idkp->kref, ide_disk_release);
|
kref_put(&idkp->kref, ide_disk_release);
|
||||||
mutex_unlock(&idedisk_ref_mutex);
|
mutex_unlock(&idedisk_ref_mutex);
|
||||||
}
|
}
|
||||||
|
@ -158,23 +158,29 @@ static DEFINE_MUTEX(idefloppy_ref_mutex);
|
|||||||
#define ide_floppy_g(disk) \
|
#define ide_floppy_g(disk) \
|
||||||
container_of((disk)->private_data, struct ide_floppy_obj, driver)
|
container_of((disk)->private_data, struct ide_floppy_obj, driver)
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
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_floppy_g(disk);
|
||||||
if (floppy)
|
if (floppy) {
|
||||||
kref_get(&floppy->kref);
|
kref_get(&floppy->kref);
|
||||||
|
if (ide_device_get(floppy->drive)) {
|
||||||
|
kref_put(&floppy->kref, idefloppy_cleanup_obj);
|
||||||
|
floppy = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
mutex_unlock(&idefloppy_ref_mutex);
|
mutex_unlock(&idefloppy_ref_mutex);
|
||||||
return floppy;
|
return floppy;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void idefloppy_cleanup_obj(struct kref *);
|
|
||||||
|
|
||||||
static void ide_floppy_put(struct ide_floppy_obj *floppy)
|
static void ide_floppy_put(struct ide_floppy_obj *floppy)
|
||||||
{
|
{
|
||||||
mutex_lock(&idefloppy_ref_mutex);
|
mutex_lock(&idefloppy_ref_mutex);
|
||||||
|
ide_device_put(floppy->drive);
|
||||||
kref_put(&floppy->kref, idefloppy_cleanup_obj);
|
kref_put(&floppy->kref, idefloppy_cleanup_obj);
|
||||||
mutex_unlock(&idefloppy_ref_mutex);
|
mutex_unlock(&idefloppy_ref_mutex);
|
||||||
}
|
}
|
||||||
|
@ -1595,6 +1595,8 @@ struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
|
|||||||
|
|
||||||
ide_init_port_data(hwif, idx);
|
ide_init_port_data(hwif, idx);
|
||||||
|
|
||||||
|
hwif->host = host;
|
||||||
|
|
||||||
host->ports[i] = hwif;
|
host->ports[i] = hwif;
|
||||||
host->n_ports++;
|
host->n_ports++;
|
||||||
}
|
}
|
||||||
|
@ -322,23 +322,29 @@ static struct class *idetape_sysfs_class;
|
|||||||
#define ide_tape_g(disk) \
|
#define ide_tape_g(disk) \
|
||||||
container_of((disk)->private_data, struct ide_tape_obj, driver)
|
container_of((disk)->private_data, struct ide_tape_obj, driver)
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
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_tape_g(disk);
|
||||||
if (tape)
|
if (tape) {
|
||||||
kref_get(&tape->kref);
|
kref_get(&tape->kref);
|
||||||
|
if (ide_device_get(tape->drive)) {
|
||||||
|
kref_put(&tape->kref, ide_tape_release);
|
||||||
|
tape = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
mutex_unlock(&idetape_ref_mutex);
|
mutex_unlock(&idetape_ref_mutex);
|
||||||
return tape;
|
return tape;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ide_tape_release(struct kref *);
|
|
||||||
|
|
||||||
static void ide_tape_put(struct ide_tape_obj *tape)
|
static void ide_tape_put(struct ide_tape_obj *tape)
|
||||||
{
|
{
|
||||||
mutex_lock(&idetape_ref_mutex);
|
mutex_lock(&idetape_ref_mutex);
|
||||||
|
ide_device_put(tape->drive);
|
||||||
kref_put(&tape->kref, ide_tape_release);
|
kref_put(&tape->kref, ide_tape_release);
|
||||||
mutex_unlock(&idetape_ref_mutex);
|
mutex_unlock(&idetape_ref_mutex);
|
||||||
}
|
}
|
||||||
|
@ -618,6 +618,53 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device
|
|||||||
|
|
||||||
EXPORT_SYMBOL(generic_ide_ioctl);
|
EXPORT_SYMBOL(generic_ide_ioctl);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ide_device_get - get an additional reference to a ide_drive_t
|
||||||
|
* @drive: device to get a reference to
|
||||||
|
*
|
||||||
|
* Gets a reference to the ide_drive_t and increments the use count of the
|
||||||
|
* underlying LLDD module.
|
||||||
|
*/
|
||||||
|
int ide_device_get(ide_drive_t *drive)
|
||||||
|
{
|
||||||
|
struct device *host_dev;
|
||||||
|
struct module *module;
|
||||||
|
|
||||||
|
if (!get_device(&drive->gendev))
|
||||||
|
return -ENXIO;
|
||||||
|
|
||||||
|
host_dev = drive->hwif->host->dev[0];
|
||||||
|
module = host_dev ? host_dev->driver->owner : NULL;
|
||||||
|
|
||||||
|
if (module && !try_module_get(module)) {
|
||||||
|
put_device(&drive->gendev);
|
||||||
|
return -ENXIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(ide_device_get);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ide_device_put - release a reference to a ide_drive_t
|
||||||
|
* @drive: device to release a reference on
|
||||||
|
*
|
||||||
|
* Release a reference to the ide_drive_t and decrements the use count of
|
||||||
|
* the underlying LLDD module.
|
||||||
|
*/
|
||||||
|
void ide_device_put(ide_drive_t *drive)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_MODULE_UNLOAD
|
||||||
|
struct device *host_dev = drive->hwif->host->dev[0];
|
||||||
|
struct module *module = host_dev ? host_dev->driver->owner : NULL;
|
||||||
|
|
||||||
|
if (module)
|
||||||
|
module_put(module);
|
||||||
|
#endif
|
||||||
|
put_device(&drive->gendev);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(ide_device_put);
|
||||||
|
|
||||||
static int ide_bus_match(struct device *dev, struct device_driver *drv)
|
static int ide_bus_match(struct device *dev, struct device_driver *drv)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -101,8 +101,13 @@ static struct ide_scsi_obj *ide_scsi_get(struct gendisk *disk)
|
|||||||
|
|
||||||
mutex_lock(&idescsi_ref_mutex);
|
mutex_lock(&idescsi_ref_mutex);
|
||||||
scsi = ide_scsi_g(disk);
|
scsi = ide_scsi_g(disk);
|
||||||
if (scsi)
|
if (scsi) {
|
||||||
scsi_host_get(scsi->host);
|
scsi_host_get(scsi->host);
|
||||||
|
if (ide_device_get(scsi->drive)) {
|
||||||
|
scsi_host_put(scsi->host);
|
||||||
|
scsi = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
mutex_unlock(&idescsi_ref_mutex);
|
mutex_unlock(&idescsi_ref_mutex);
|
||||||
return scsi;
|
return scsi;
|
||||||
}
|
}
|
||||||
@ -110,6 +115,7 @@ static struct ide_scsi_obj *ide_scsi_get(struct gendisk *disk)
|
|||||||
static void ide_scsi_put(struct ide_scsi_obj *scsi)
|
static void ide_scsi_put(struct ide_scsi_obj *scsi)
|
||||||
{
|
{
|
||||||
mutex_lock(&idescsi_ref_mutex);
|
mutex_lock(&idescsi_ref_mutex);
|
||||||
|
ide_device_put(scsi->drive);
|
||||||
scsi_host_put(scsi->host);
|
scsi_host_put(scsi->host);
|
||||||
mutex_unlock(&idescsi_ref_mutex);
|
mutex_unlock(&idescsi_ref_mutex);
|
||||||
}
|
}
|
||||||
|
@ -532,12 +532,16 @@ struct ide_dma_ops {
|
|||||||
void (*dma_timeout)(struct ide_drive_s *);
|
void (*dma_timeout)(struct ide_drive_s *);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ide_host;
|
||||||
|
|
||||||
typedef struct hwif_s {
|
typedef struct hwif_s {
|
||||||
struct hwif_s *next; /* for linked-list in ide_hwgroup_t */
|
struct hwif_s *next; /* for linked-list in ide_hwgroup_t */
|
||||||
struct hwif_s *mate; /* other hwif from same PCI chip */
|
struct hwif_s *mate; /* other hwif from same PCI chip */
|
||||||
struct hwgroup_s *hwgroup; /* actually (ide_hwgroup_t *) */
|
struct hwgroup_s *hwgroup; /* actually (ide_hwgroup_t *) */
|
||||||
struct proc_dir_entry *proc; /* /proc/ide/ directory entry */
|
struct proc_dir_entry *proc; /* /proc/ide/ directory entry */
|
||||||
|
|
||||||
|
struct ide_host *host;
|
||||||
|
|
||||||
char name[6]; /* name of interface, eg. "ide0" */
|
char name[6]; /* name of interface, eg. "ide0" */
|
||||||
|
|
||||||
struct ide_io_ports io_ports;
|
struct ide_io_ports io_ports;
|
||||||
@ -876,6 +880,9 @@ struct ide_driver_s {
|
|||||||
|
|
||||||
#define to_ide_driver(drv) container_of(drv, ide_driver_t, gen_driver)
|
#define to_ide_driver(drv) container_of(drv, ide_driver_t, gen_driver)
|
||||||
|
|
||||||
|
int ide_device_get(ide_drive_t *);
|
||||||
|
void ide_device_put(ide_drive_t *);
|
||||||
|
|
||||||
int generic_ide_ioctl(ide_drive_t *, struct file *, struct block_device *, unsigned, unsigned long);
|
int generic_ide_ioctl(ide_drive_t *, struct file *, struct block_device *, unsigned, unsigned long);
|
||||||
|
|
||||||
extern int ide_vlb_clk;
|
extern int ide_vlb_clk;
|
||||||
|
Loading…
Reference in New Issue
Block a user