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

scsi: sg: Enable runtime power management

In 2010, runtime power management support was implemented in the SCSI
core. The description of patch "[SCSI] implement runtime Power
Management" mentions that the sg driver is skipped but not why. This
patch enables runtime power management even if an instance of the sg
driver is held open. Enabling runtime PM for the sg driver is safe
because all interactions of the sg driver with the SCSI device pass
through the block layer (blk_execute_rq_nowait()) and the block layer
already supports runtime PM.

Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Douglas Gilbert <dgilbert@interlog.com>
Fixes: bc4f24014de5 ("[SCSI] implement runtime Power Management")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20241030220310.1373569-1-bvanassche@acm.org
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Bart Van Assche and committed by
Martin K. Petersen
4045de89 95bbdca4

+1 -8
+1 -8
drivers/scsi/sg.c
··· 307 307 if (retval) 308 308 goto sg_put; 309 309 310 - retval = scsi_autopm_get_device(device); 311 - if (retval) 312 - goto sdp_put; 313 - 314 310 /* scsi_block_when_processing_errors() may block so bypass 315 311 * check if O_NONBLOCK. Permits SCSI commands to be issued 316 312 * during error recovery. Tread carefully. */ ··· 314 318 scsi_block_when_processing_errors(device))) { 315 319 retval = -ENXIO; 316 320 /* we are in error recovery for this device */ 317 - goto error_out; 321 + goto sdp_put; 318 322 } 319 323 320 324 mutex_lock(&sdp->open_rel_lock); ··· 367 371 } 368 372 error_mutex_locked: 369 373 mutex_unlock(&sdp->open_rel_lock); 370 - error_out: 371 - scsi_autopm_put_device(device); 372 374 sdp_put: 373 375 kref_put(&sdp->d_ref, sg_device_destroy); 374 376 scsi_device_put(device); ··· 386 392 SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, "sg_release\n")); 387 393 388 394 mutex_lock(&sdp->open_rel_lock); 389 - scsi_autopm_put_device(sdp->device); 390 395 kref_put(&sfp->f_ref, sg_remove_sfp); 391 396 sdp->open_cnt--; 392 397