Skip to content

Commit 9445cbb

Browse files
committed
Merge: SCSI sg driver -stable fixes for regression in 9.4
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4216 This MR contains 2 fixes from -stable to fix a regression in the 9.4 kernel that is causing a customer crash. The second fix is itself a fix for the first fix. scsi: sg: Avoid sg device teardown race Fixes: db59133 ("scsi: sg: fix blktrace debugfs entries leakage") scsi: sg: Avoid race in error handling & drop bogus warn Fixes: 27f58c0 ("scsi: sg: Avoid sg device teardown race") JIRA: https://issues.redhat.com/browse/RHEL-35659 Upstream Status: From upstream linux mainline Signed-off-by: Ewan D. Milne <emilne@redhat.com> Approved-by: Maurizio Lombardi <mlombard@redhat.com> Approved-by: John Meneghini <jmeneghi@redhat.com> Approved-by: Ming Lei <ming.lei@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Lucas Zampieri <lzampier@redhat.com>
2 parents ae17acf + 7cbd131 commit 9445cbb

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

drivers/scsi/sg.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ sg_open(struct inode *inode, struct file *filp)
285285
int dev = iminor(inode);
286286
int flags = filp->f_flags;
287287
struct request_queue *q;
288+
struct scsi_device *device;
288289
Sg_device *sdp;
289290
Sg_fd *sfp;
290291
int retval;
@@ -301,19 +302,20 @@ sg_open(struct inode *inode, struct file *filp)
301302

302303
/* This driver's module count bumped by fops_get in <linux/fs.h> */
303304
/* Prevent the device driver from vanishing while we sleep */
304-
retval = scsi_device_get(sdp->device);
305+
device = sdp->device;
306+
retval = scsi_device_get(device);
305307
if (retval)
306308
goto sg_put;
307309

308-
retval = scsi_autopm_get_device(sdp->device);
310+
retval = scsi_autopm_get_device(device);
309311
if (retval)
310312
goto sdp_put;
311313

312314
/* scsi_block_when_processing_errors() may block so bypass
313315
* check if O_NONBLOCK. Permits SCSI commands to be issued
314316
* during error recovery. Tread carefully. */
315317
if (!((flags & O_NONBLOCK) ||
316-
scsi_block_when_processing_errors(sdp->device))) {
318+
scsi_block_when_processing_errors(device))) {
317319
retval = -ENXIO;
318320
/* we are in error recovery for this device */
319321
goto error_out;
@@ -344,7 +346,7 @@ sg_open(struct inode *inode, struct file *filp)
344346

345347
if (sdp->open_cnt < 1) { /* no existing opens */
346348
sdp->sgdebug = 0;
347-
q = sdp->device->request_queue;
349+
q = device->request_queue;
348350
sdp->sg_tablesize = queue_max_segments(q);
349351
}
350352
sfp = sg_add_sfp(sdp);
@@ -370,10 +372,11 @@ sg_open(struct inode *inode, struct file *filp)
370372
error_mutex_locked:
371373
mutex_unlock(&sdp->open_rel_lock);
372374
error_out:
373-
scsi_autopm_put_device(sdp->device);
375+
scsi_autopm_put_device(device);
374376
sdp_put:
375-
scsi_device_put(sdp->device);
376-
goto sg_put;
377+
kref_put(&sdp->d_ref, sg_device_destroy);
378+
scsi_device_put(device);
379+
return retval;
377380
}
378381

379382
/* Release resources associated with a successful sg_open()
@@ -2185,6 +2188,7 @@ sg_remove_sfp_usercontext(struct work_struct *work)
21852188
{
21862189
struct sg_fd *sfp = container_of(work, struct sg_fd, ew.work);
21872190
struct sg_device *sdp = sfp->parentdp;
2191+
struct scsi_device *device = sdp->device;
21882192
Sg_request *srp;
21892193
unsigned long iflags;
21902194

@@ -2210,8 +2214,8 @@ sg_remove_sfp_usercontext(struct work_struct *work)
22102214
"sg_remove_sfp: sfp=0x%p\n", sfp));
22112215
kfree(sfp);
22122216

2213-
scsi_device_put(sdp->device);
22142217
kref_put(&sdp->d_ref, sg_device_destroy);
2218+
scsi_device_put(device);
22152219
module_put(THIS_MODULE);
22162220
}
22172221

0 commit comments

Comments
 (0)