Esempio n. 1
0
static int swim3_attach(struct macio_dev *mdev,
			const struct of_device_id *match)
{
	struct gendisk *disk;
	int index, rc;

	index = floppy_count++;
	if (index >= MAX_FLOPPIES)
		return -ENXIO;

	/* Add the drive */
	rc = swim3_add_device(mdev, index);
	if (rc)
		return rc;
	/* Now register that disk. Same comment about failure handling */
	disk = disks[index] = alloc_disk(1);
	if (disk == NULL)
		return -ENOMEM;
	disk->queue = blk_init_queue(do_fd_request, &swim3_lock);
	if (disk->queue == NULL) {
		put_disk(disk);
		return -ENOMEM;
	}
	blk_queue_bounce_limit(disk->queue, BLK_BOUNCE_HIGH);
	disk->queue->queuedata = &floppy_states[index];

	if (index == 0) {
		/* If we failed, there isn't much we can do as the driver is still
		 * too dumb to remove the device, just bail out
		 */
		if (register_blkdev(FLOPPY_MAJOR, "fd"))
			return 0;
	}

	disk->major = FLOPPY_MAJOR;
	disk->first_minor = index;
	disk->fops = &floppy_fops;
	disk->private_data = &floppy_states[index];
	disk->flags |= GENHD_FL_REMOVABLE;
	sprintf(disk->disk_name, "fd%d", index);
	set_capacity(disk, 2880);
	add_disk(disk);

	return 0;
}
Esempio n. 2
0
static int __devinit swim3_attach(struct macio_dev *mdev, const struct of_device_id *match)
{
	int i, rc;
	struct gendisk *disk;

	/* Add the drive */
	rc = swim3_add_device(mdev, floppy_count);
	if (rc)
		return rc;

	/* Now create the queue if not there yet */
	if (swim3_queue == NULL) {
		/* If we failed, there isn't much we can do as the driver is still
		 * too dumb to remove the device, just bail out
		 */
		if (register_blkdev(FLOPPY_MAJOR, "fd"))
			return 0;
		swim3_queue = blk_init_queue(do_fd_request, &swim3_lock);
		if (swim3_queue == NULL) {
			unregister_blkdev(FLOPPY_MAJOR, "fd");
			return 0;
		}
	}

	/* Now register that disk. Same comment about failure handling */
	i = floppy_count++;
	disk = disks[i] = alloc_disk(1);
	if (disk == NULL)
		return 0;

	disk->major = FLOPPY_MAJOR;
	disk->first_minor = i;
	disk->fops = &floppy_fops;
	disk->private_data = &floppy_states[i];
	disk->queue = swim3_queue;
	disk->flags |= GENHD_FL_REMOVABLE;
	sprintf(disk->disk_name, "fd%d", i);
	set_capacity(disk, 2880);
	add_disk(disk);

	return 0;
}