Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [bug report] scsi: sd: Fix sshdr use in sd_spinup_disk
@ 2026-05-11  4:29 Dan Carpenter
  0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2026-05-11  4:29 UTC (permalink / raw)
  To: Mike Christie; +Cc: linux-scsi

Hello Mike Christie,

Commit b4d0c33a32c3 ("scsi: sd: Fix sshdr use in sd_spinup_disk")
from Oct 4, 2023 (linux-next), leads to the following Smatch static
checker warning:

	drivers/scsi/sd.c:2525 sd_spinup_disk()
	warn: kernel error codes cast to unsigned 'the_result'

drivers/scsi/sd.c
    2474 static void
    2475 sd_spinup_disk(struct scsi_disk *sdkp)
    2476 {
    2477         static const u8 cmd[10] = { TEST_UNIT_READY };
    2478         unsigned long spintime_expire = 0;
    2479         int spintime, sense_valid = 0;
    2480         unsigned int the_result;
    2481         struct scsi_sense_hdr sshdr;
    2482         struct scsi_failure failure_defs[] = {
    2483                 /* Do not retry Medium Not Present */
    2484                 {
    2485                         .sense = UNIT_ATTENTION,
    2486                         .asc = 0x3A,
    2487                         .ascq = SCMD_FAILURE_ASCQ_ANY,
    2488                         .result = SAM_STAT_CHECK_CONDITION,
    2489                 },
    2490                 {
    2491                         .sense = NOT_READY,
    2492                         .asc = 0x3A,
    2493                         .ascq = SCMD_FAILURE_ASCQ_ANY,
    2494                         .result = SAM_STAT_CHECK_CONDITION,
    2495                 },
    2496                 /* Retry when scsi_status_is_good would return false 3 times */
    2497                 {
    2498                         .result = SCMD_FAILURE_STAT_ANY,
    2499                         .allowed = 3,
    2500                 },
    2501                 {}
    2502         };
    2503         struct scsi_failures failures = {
    2504                 .failure_definitions = failure_defs,
    2505         };
    2506         const struct scsi_exec_args exec_args = {
    2507                 .sshdr = &sshdr,
    2508                 .failures = &failures,
    2509         };
    2510 
    2511         spintime = 0;
    2512 
    2513         /* Spin up drives, as required.  Only do this at boot time */
    2514         /* Spinup needs to be done for module loads too. */
    2515         do {
    2516                 bool media_was_present = sdkp->media_present;
    2517 
    2518                 scsi_failures_reset_retries(&failures);
    2519 
    2520                 the_result = scsi_execute_cmd(sdkp->device, cmd, REQ_OP_DRV_IN,
    2521                                               NULL, 0, SD_TIMEOUT,
    2522                                               sdkp->max_retries, &exec_args);
    2523 
    2524 
--> 2525                 if (the_result > 0) {

The scsi_execute_cmd() function returns negative kernel error codes and
positive SCSI error status codes.  But "the_result" is an unsigned int
so both negative and positive error codes are > 0.

    2526                         /*
    2527                          * If the drive has indicated to us that it doesn't
    2528                          * have any media in it, don't bother with any more
    2529                          * polling.
    2530                          */
    2531                         if (media_not_present(sdkp, &sshdr)) {
    2532                                 if (media_was_present)
    2533                                         sd_printk(KERN_NOTICE, sdkp,
    2534                                                   "Media removed, stopped polling\n");
    2535                                 return;
    2536                         }
    2537                         sense_valid = scsi_sense_valid(&sshdr);
    2538                 }
    2539 
    2540                 if (!scsi_status_is_check_condition(the_result)) {
    2541                         /* no sense, TUR either succeeded or failed
    2542                          * with a status error */
    2543                         if(!spintime && !scsi_status_is_good(the_result)) {
    2544                                 sd_print_result(sdkp, "Test Unit Ready failed",
    2545                                                 the_result);
    2546                         }
    2547                         break;
    2548                 }
    2549 

This email is a free service from the Smatch-CI project [smatch.sf.net].

regards,
dan carpenter

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-05-11  4:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-11  4:29 [bug report] scsi: sd: Fix sshdr use in sd_spinup_disk Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox