Skip to content

Commit e7f7655

Browse files
Christoph Hellwigaxboe
authored andcommitted
scsi: don't use disk->private_data to find the scsi_driver
Requiring every ULP to have the scsi_drive as first member of the private data is rather fragile and not necessary anyway. Just use the driver hanging off the SCSI device instead. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Reviewed-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Link: https://lore.kernel.org/r/20220308055200.735835-4-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e02657e commit e7f7655

File tree

8 files changed

+11
-21
lines changed

8 files changed

+11
-21
lines changed

drivers/scsi/sd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3515,7 +3515,6 @@ static int sd_probe(struct device *dev)
35153515
}
35163516

35173517
sdkp->device = sdp;
3518-
sdkp->driver = &sd_template;
35193518
sdkp->disk = gd;
35203519
sdkp->index = index;
35213520
sdkp->max_retries = SD_MAX_RETRIES;
@@ -3548,7 +3547,7 @@ static int sd_probe(struct device *dev)
35483547
gd->minors = SD_MINORS;
35493548

35503549
gd->fops = &sd_fops;
3551-
gd->private_data = &sdkp->driver;
3550+
gd->private_data = sdkp;
35523551

35533552
/* defaults, until the device tells us otherwise */
35543553
sdp->sector_size = 512;

drivers/scsi/sd.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ enum {
6868
};
6969

7070
struct scsi_disk {
71-
struct scsi_driver *driver; /* always &sd_template */
7271
struct scsi_device *device;
7372
struct device dev;
7473
struct gendisk *disk;
@@ -131,7 +130,7 @@ struct scsi_disk {
131130

132131
static inline struct scsi_disk *scsi_disk(struct gendisk *disk)
133132
{
134-
return container_of(disk->private_data, struct scsi_disk, driver);
133+
return disk->private_data;
135134
}
136135

137136
#define sd_printk(prefix, sdsk, fmt, a...) \

drivers/scsi/sr.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static void sr_kref_release(struct kref *kref);
147147

148148
static inline struct scsi_cd *scsi_cd(struct gendisk *disk)
149149
{
150-
return container_of(disk->private_data, struct scsi_cd, driver);
150+
return disk->private_data;
151151
}
152152

153153
static int sr_runtime_suspend(struct device *dev)
@@ -692,7 +692,6 @@ static int sr_probe(struct device *dev)
692692

693693
cd->device = sdev;
694694
cd->disk = disk;
695-
cd->driver = &sr_template;
696695
cd->capacity = 0x1fffff;
697696
cd->device->changed = 1; /* force recheck CD type */
698697
cd->media_present = 1;
@@ -713,7 +712,7 @@ static int sr_probe(struct device *dev)
713712
sr_vendor_init(cd);
714713

715714
set_capacity(disk, cd->capacity);
716-
disk->private_data = &cd->driver;
715+
disk->private_data = cd;
717716

718717
if (register_cdrom(disk, &cd->cdi))
719718
goto fail_minor;

drivers/scsi/sr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ struct scsi_device;
3232

3333

3434
typedef struct scsi_cd {
35-
struct scsi_driver *driver;
3635
unsigned capacity; /* size in blocks */
3736
struct scsi_device *device;
3837
unsigned int vendor; /* vendor code, see sr_vendor.c */

drivers/scsi/st.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4276,7 +4276,6 @@ static int st_probe(struct device *dev)
42764276
goto out_buffer_free;
42774277
}
42784278
kref_init(&tpnt->kref);
4279-
tpnt->driver = &st_template;
42804279

42814280
tpnt->device = SDp;
42824281
if (SDp->scsi_level <= 2)

drivers/scsi/st.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ struct scsi_tape_stats {
117117

118118
/* The tape drive descriptor */
119119
struct scsi_tape {
120-
struct scsi_driver *driver;
121120
struct scsi_device *device;
122121
struct mutex lock; /* For serialization */
123122
struct completion wait; /* For SCSI commands */

include/scsi/scsi_cmnd.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <scsi/scsi_request.h>
1414

1515
struct Scsi_Host;
16-
struct scsi_driver;
1716

1817
/*
1918
* MAX_COMMAND_SIZE is:
@@ -159,14 +158,6 @@ static inline void *scsi_cmd_priv(struct scsi_cmnd *cmd)
159158
return cmd + 1;
160159
}
161160

162-
/* make sure not to use it with passthrough commands */
163-
static inline struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd)
164-
{
165-
struct request *rq = scsi_cmd_to_rq(cmd);
166-
167-
return *(struct scsi_driver **)rq->q->disk->private_data;
168-
}
169-
170161
void scsi_done(struct scsi_cmnd *cmd);
171162

172163
extern void scsi_finish_command(struct scsi_cmnd *cmd);

include/scsi/scsi_driver.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
#include <linux/blk_types.h>
66
#include <linux/device.h>
7+
#include <scsi/scsi_cmnd.h>
78

89
struct module;
910
struct request;
10-
struct scsi_cmnd;
11-
struct scsi_device;
1211

1312
struct scsi_driver {
1413
struct device_driver gendrv;
@@ -31,4 +30,10 @@ extern int scsi_register_interface(struct class_interface *);
3130
#define scsi_unregister_interface(intf) \
3231
class_interface_unregister(intf)
3332

33+
/* make sure not to use it with passthrough commands */
34+
static inline struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd)
35+
{
36+
return to_scsi_driver(cmd->device->sdev_gendev.driver);
37+
}
38+
3439
#endif /* _SCSI_SCSI_DRIVER_H */

0 commit comments

Comments
 (0)