Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

st: do not allocate a gendisk

st is a character driver and thus does not need to allocate a gendisk,
which is only used for file system-like block layer I/O on block
devices.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20210816131910.615153-3-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
45938335 5f432cce

+13 -38
+12 -37
drivers/scsi/st.c
··· 309 309 } 310 310 311 311 312 - static inline char *tape_name(struct scsi_tape *tape) 313 - { 314 - return tape->disk->disk_name; 315 - } 316 - 317 312 #define st_printk(prefix, t, fmt, a...) \ 318 - sdev_prefix_printk(prefix, (t)->device, tape_name(t), fmt, ##a) 313 + sdev_prefix_printk(prefix, (t)->device, (t)->name, fmt, ##a) 319 314 #ifdef DEBUG 320 315 #define DEBC_printk(t, fmt, a...) \ 321 316 if (debugging) { st_printk(ST_DEB_MSG, t, fmt, ##a ); } ··· 358 363 int result = SRpnt->result; 359 364 u8 scode; 360 365 DEB(const char *stp;) 361 - char *name = tape_name(STp); 366 + char *name = STp->name; 362 367 struct st_cmdstatus *cmdstatp; 363 368 364 369 if (!result) ··· 3836 3841 !capable(CAP_SYS_RAWIO)) 3837 3842 i = -EPERM; 3838 3843 else 3839 - i = scsi_cmd_ioctl(STp->disk->queue, STp->disk, 3840 - file->f_mode, cmd_in, p); 3844 + i = scsi_cmd_ioctl(STp->device->request_queue, 3845 + NULL, file->f_mode, cmd_in, 3846 + p); 3841 3847 if (i != -ENOTTY) 3842 3848 return i; 3843 3849 break; ··· 4212 4216 4213 4217 i = mode << (4 - ST_NBR_MODE_BITS); 4214 4218 snprintf(name, 10, "%s%s%s", rew ? "n" : "", 4215 - tape->disk->disk_name, st_formats[i]); 4219 + tape->name, st_formats[i]); 4216 4220 4217 4221 dev = device_create(&st_sysfs_class, &tape->device->sdev_gendev, 4218 4222 cdev_devno, &tape->modes[mode], "%s", name); ··· 4267 4271 static int st_probe(struct device *dev) 4268 4272 { 4269 4273 struct scsi_device *SDp = to_scsi_device(dev); 4270 - struct gendisk *disk = NULL; 4271 4274 struct scsi_tape *tpnt = NULL; 4272 4275 struct st_modedef *STm; 4273 4276 struct st_partstat *STps; ··· 4296 4301 goto out; 4297 4302 } 4298 4303 4299 - disk = alloc_disk(1); 4300 - if (!disk) { 4301 - sdev_printk(KERN_ERR, SDp, 4302 - "st: out of memory. Device not attached.\n"); 4303 - goto out_buffer_free; 4304 - } 4305 - 4306 4304 tpnt = kzalloc(sizeof(struct scsi_tape), GFP_KERNEL); 4307 4305 if (tpnt == NULL) { 4308 4306 sdev_printk(KERN_ERR, SDp, 4309 4307 "st: Can't allocate device descriptor.\n"); 4310 - goto out_put_disk; 4308 + goto out_buffer_free; 4311 4309 } 4312 4310 kref_init(&tpnt->kref); 4313 - tpnt->disk = disk; 4314 - disk->private_data = &tpnt->driver; 4315 - /* SCSI tape doesn't register this gendisk via add_disk(). Manually 4316 - * take queue reference that release_disk() expects. */ 4317 - if (!blk_get_queue(SDp->request_queue)) 4318 - goto out_put_disk; 4319 - disk->queue = SDp->request_queue; 4320 4311 tpnt->driver = &st_template; 4321 4312 4322 4313 tpnt->device = SDp; ··· 4375 4394 idr_preload_end(); 4376 4395 if (error < 0) { 4377 4396 pr_warn("st: idr allocation failed: %d\n", error); 4378 - goto out_put_queue; 4397 + goto out_free_tape; 4379 4398 } 4380 4399 tpnt->index = error; 4381 - sprintf(disk->disk_name, "st%d", tpnt->index); 4400 + sprintf(tpnt->name, "st%d", tpnt->index); 4382 4401 tpnt->stats = kzalloc(sizeof(struct scsi_tape_stats), GFP_KERNEL); 4383 4402 if (tpnt->stats == NULL) { 4384 4403 sdev_printk(KERN_ERR, SDp, ··· 4395 4414 scsi_autopm_put_device(SDp); 4396 4415 4397 4416 sdev_printk(KERN_NOTICE, SDp, 4398 - "Attached scsi tape %s\n", tape_name(tpnt)); 4417 + "Attached scsi tape %s\n", tpnt->name); 4399 4418 sdev_printk(KERN_INFO, SDp, "%s: try direct i/o: %s (alignment %d B)\n", 4400 - tape_name(tpnt), tpnt->try_dio ? "yes" : "no", 4419 + tpnt->name, tpnt->try_dio ? "yes" : "no", 4401 4420 queue_dma_alignment(SDp->request_queue) + 1); 4402 4421 4403 4422 return 0; ··· 4409 4428 spin_lock(&st_index_lock); 4410 4429 idr_remove(&st_index_idr, tpnt->index); 4411 4430 spin_unlock(&st_index_lock); 4412 - out_put_queue: 4413 - blk_put_queue(disk->queue); 4414 - out_put_disk: 4415 - put_disk(disk); 4431 + out_free_tape: 4416 4432 kfree(tpnt); 4417 4433 out_buffer_free: 4418 4434 kfree(buffer); ··· 4448 4470 static void scsi_tape_release(struct kref *kref) 4449 4471 { 4450 4472 struct scsi_tape *tpnt = to_scsi_tape(kref); 4451 - struct gendisk *disk = tpnt->disk; 4452 4473 4453 4474 tpnt->device = NULL; 4454 4475 ··· 4457 4480 kfree(tpnt->buffer); 4458 4481 } 4459 4482 4460 - disk->private_data = NULL; 4461 - put_disk(disk); 4462 4483 kfree(tpnt->stats); 4463 4484 kfree(tpnt); 4464 4485 return;
+1 -1
drivers/scsi/st.h
··· 187 187 unsigned char last_cmnd[6]; 188 188 unsigned char last_sense[16]; 189 189 #endif 190 - struct gendisk *disk; 190 + char name[DISK_NAME_LEN]; 191 191 struct kref kref; 192 192 struct scsi_tape_stats *stats; 193 193 };