|
@@ -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);
|
|
}
|
|
}
|