Commit cb690f52 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'for-5.16/drivers-2021-11-09' of git://git.kernel.dk/linux-block

Pull more block driver updates from Jens Axboe:

 - Last series adding error handling support for add_disk() in drivers.
   After this one, and once the SCSI side has been merged, we can
   finally annotate add_disk() as must_check. (Luis)

 - bcache fixes (Coly)

 - zram fixes (Ming)

 - ataflop locking fix (Tetsuo)

 - nbd fixes (Ye, Yu)

 - MD merge via Song
      - Cleanup (Yang)
      - sysfs fix (Guoqing)

 - Misc fixes (Geert, Wu, luo)

* tag 'for-5.16/drivers-2021-11-09' of git://git.kernel.dk/linux-block: (34 commits)
  bcache: Revert "bcache: use bvec_virt"
  ataflop: Add missing semicolon to return statement
  floppy: address add_disk() error handling on probe
  ataflop: address add_disk() error handling on probe
  block: update __register_blkdev() probe documentation
  ataflop: remove ataflop_probe_lock mutex
  mtd/ubi/block: add error handling support for add_disk()
  block/sunvdc: add error handling support for add_disk()
  z2ram: add error handling support for add_disk()
  nvdimm/pmem: use add_disk() error handling
  nvdimm/pmem: cleanup the disk if pmem_release_disk() is yet assigned
  nvdimm/blk: add error handling support for add_disk()
  nvdimm/blk: avoid calling del_gendisk() on early failures
  nvdimm/btt: add error handling support for add_disk()
  nvdimm/btt: use goto error labels on btt_blk_init()
  loop: Remove duplicate assignments
  drbd: Fix double free problem in drbd_create_device
  nvdimm/btt: do not call del_gendisk() if not needed
  bcache: fix use-after-free problem in bcache_device_free()
  zram: replace fsync_bdev with sync_blockdev
  ...
parents 3e28850c 2878feae
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -213,7 +213,10 @@ void blkdev_show(struct seq_file *seqf, off_t offset)
 * @major: the requested major device number [1..BLKDEV_MAJOR_MAX-1]. If
 *         @major = 0, try to allocate any unused major number.
 * @name: the name of the new block device as a zero terminated string
 * @probe: allback that is called on access to any minor number of @major
 * @probe: pre-devtmpfs / pre-udev callback used to create disks when their
 *	   pre-created device node is accessed. When a probe call uses
 *	   add_disk() and it fails the driver must cleanup resources. This
 *	   interface may soon be removed.
 *
 * The @name must be unique within the system.
 *
+37 −24
Original line number Diff line number Diff line
@@ -2008,8 +2008,6 @@ static int ataflop_alloc_disk(unsigned int drive, unsigned int type)
	return 0;
}

static DEFINE_MUTEX(ataflop_probe_lock);

static void ataflop_probe(dev_t dev)
{
	int drive = MINOR(dev) & 3;
@@ -2020,14 +2018,38 @@ static void ataflop_probe(dev_t dev)

	if (drive >= FD_MAX_UNITS || type >= NUM_DISK_MINORS)
		return;
	mutex_lock(&ataflop_probe_lock);
	if (!unit[drive].disk[type]) {
		if (ataflop_alloc_disk(drive, type) == 0) {
			add_disk(unit[drive].disk[type]);
	if (unit[drive].disk[type])
		return;
	if (ataflop_alloc_disk(drive, type))
		return;
	if (add_disk(unit[drive].disk[type]))
		goto cleanup_disk;
	unit[drive].registered[type] = true;
	return;

cleanup_disk:
	blk_cleanup_disk(unit[drive].disk[type]);
	unit[drive].disk[type] = NULL;
}

static void atari_floppy_cleanup(void)
{
	int i;
	int type;

	for (i = 0; i < FD_MAX_UNITS; i++) {
		for (type = 0; type < NUM_DISK_MINORS; type++) {
			if (!unit[i].disk[type])
				continue;
			del_gendisk(unit[i].disk[type]);
			blk_cleanup_queue(unit[i].disk[type]->queue);
			put_disk(unit[i].disk[type]);
		}
	mutex_unlock(&ataflop_probe_lock);
		blk_mq_free_tag_set(&unit[i].tag_set);
	}

	del_timer_sync(&fd_timer);
	atari_stram_free(DMABuffer);
}

static void atari_cleanup_floppy_disk(struct atari_floppy_struct *fs)
@@ -2053,11 +2075,6 @@ static int __init atari_floppy_init (void)
		/* Amiga, Mac, ... don't have Atari-compatible floppy :-) */
		return -ENODEV;

	mutex_lock(&ataflop_probe_lock);
	ret = __register_blkdev(FLOPPY_MAJOR, "fd", ataflop_probe);
	if (ret)
		goto out_unlock;

	for (i = 0; i < FD_MAX_UNITS; i++) {
		memset(&unit[i].tag_set, 0, sizeof(unit[i].tag_set));
		unit[i].tag_set.ops = &ataflop_mq_ops;
@@ -2113,7 +2130,12 @@ static int __init atari_floppy_init (void)
	       UseTrackbuffer ? "" : "no ");
	config_types();

	return 0;
	ret = __register_blkdev(FLOPPY_MAJOR, "fd", ataflop_probe);
	if (ret) {
		printk(KERN_ERR "atari_floppy_init: cannot register block device\n");
		atari_floppy_cleanup();
	}
	return ret;

err_out_dma:
	atari_stram_free(DMABuffer);
@@ -2121,9 +2143,6 @@ static int __init atari_floppy_init (void)
	while (--i >= 0)
		atari_cleanup_floppy_disk(&unit[i]);

	unregister_blkdev(FLOPPY_MAJOR, "fd");
out_unlock:
	mutex_unlock(&ataflop_probe_lock);
	return ret;
}

@@ -2168,14 +2187,8 @@ __setup("floppy=", atari_floppy_setup);

static void __exit atari_floppy_exit(void)
{
	int i;

	for (i = 0; i < FD_MAX_UNITS; i++)
		atari_cleanup_floppy_disk(&unit[i]);
	unregister_blkdev(FLOPPY_MAJOR, "fd");

	del_timer_sync(&fd_timer);
	atari_stram_free( DMABuffer );
	atari_floppy_cleanup();
}

module_init(atari_floppy_init)
+7 −2
Original line number Diff line number Diff line
@@ -370,6 +370,7 @@ static int brd_alloc(int i)
	struct brd_device *brd;
	struct gendisk *disk;
	char buf[DISK_NAME_LEN];
	int err = -ENOMEM;

	mutex_lock(&brd_devices_mutex);
	list_for_each_entry(brd, &brd_devices, brd_list) {
@@ -420,16 +421,20 @@ static int brd_alloc(int i)
	/* Tell the block layer that this is not a rotational device */
	blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
	blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, disk->queue);
	add_disk(disk);
	err = add_disk(disk);
	if (err)
		goto out_cleanup_disk;

	return 0;

out_cleanup_disk:
	blk_cleanup_disk(disk);
out_free_dev:
	mutex_lock(&brd_devices_mutex);
	list_del(&brd->brd_list);
	mutex_unlock(&brd_devices_mutex);
	kfree(brd);
	return -ENOMEM;
	return err;
}

static void brd_probe(dev_t dev)
+1 −3
Original line number Diff line number Diff line
@@ -2796,7 +2796,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig

	err = add_disk(disk);
	if (err)
		goto out_cleanup_disk;
		goto out_idr_remove_vol;

	/* inherit the connection state */
	device->state.conn = first_connection(resource)->cstate;
@@ -2810,8 +2810,6 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
	drbd_debugfs_device_add(device);
	return NO_ERROR;

out_cleanup_disk:
	blk_cleanup_disk(disk);
out_idr_remove_vol:
	idr_remove(&connection->peer_devices, vnr);
out_idr_remove_from_resource:
+13 −4
Original line number Diff line number Diff line
@@ -4528,10 +4528,19 @@ static void floppy_probe(dev_t dev)
		return;

	mutex_lock(&floppy_probe_lock);
	if (!disks[drive][type]) {
		if (floppy_alloc_disk(drive, type) == 0)
			add_disk(disks[drive][type]);
	}
	if (disks[drive][type])
		goto out;
	if (floppy_alloc_disk(drive, type))
		goto out;
	if (add_disk(disks[drive][type]))
		goto cleanup_disk;
out:
	mutex_unlock(&floppy_probe_lock);
	return;

cleanup_disk:
	blk_cleanup_disk(disks[drive][type]);
	disks[drive][type] = NULL;
	mutex_unlock(&floppy_probe_lock);
}

Loading