Linux-ide Archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: dlemoal@kernel.org
Cc: linux-ide@vger.kernel.org
Subject: [bug report] scsi: sd: Fix TCG OPAL unlock on system resume
Date: Thu, 11 Apr 2024 16:30:06 +0300	[thread overview]
Message-ID: <1c19822c-5622-4073-bc91-16523bb14302@moroto.mountain> (raw)

Hello Damien Le Moal,

Commit 0c76106cb975 ("scsi: sd: Fix TCG OPAL unlock on system
resume") from Mar 19, 2024 (linux-next), leads to the following
Smatch static checker warning:

	drivers/ata/libata-scsi.c:4774 ata_scsi_dev_rescan()
	error: double unlocked 'ap->lock' (orig line 4757)

drivers/ata/libata-scsi.c
    4726 void ata_scsi_dev_rescan(struct work_struct *work)
    4727 {
    4728         struct ata_port *ap =
    4729                 container_of(work, struct ata_port, scsi_rescan_task.work);
    4730         struct ata_link *link;
    4731         struct ata_device *dev;
    4732         unsigned long flags;
    4733         bool do_resume;
    4734         int ret = 0;
    4735 
    4736         mutex_lock(&ap->scsi_scan_mutex);
    4737         spin_lock_irqsave(ap->lock, flags);
    4738 
    4739         ata_for_each_link(link, ap, EDGE) {
    4740                 ata_for_each_dev(dev, link, ENABLED) {
    4741                         struct scsi_device *sdev = dev->sdev;
    4742 
    4743                         /*
    4744                          * If the port was suspended before this was scheduled,
    4745                          * bail out.
    4746                          */
    4747                         if (ap->pflags & ATA_PFLAG_SUSPENDED)
    4748                                 goto unlock;
    4749 
    4750                         if (!sdev)
    4751                                 continue;
    4752                         if (scsi_device_get(sdev))
    4753                                 continue;
    4754 
    4755                         do_resume = dev->flags & ATA_DFLAG_RESUMING;
    4756 
    4757                         spin_unlock_irqrestore(ap->lock, flags);
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    4758                         if (do_resume) {
    4759                                 ret = scsi_resume_device(sdev);
    4760                                 if (ret == -EWOULDBLOCK)
    4761                                         goto unlock;
                                                 ^^^^^^^^^^^^

    4762                                 dev->flags &= ~ATA_DFLAG_RESUMING;
    4763                         }
    4764                         ret = scsi_rescan_device(sdev);
    4765                         scsi_device_put(sdev);
    4766                         spin_lock_irqsave(ap->lock, flags);
    4767 
    4768                         if (ret)
    4769                                 goto unlock;
    4770                 }
    4771         }
    4772 
    4773 unlock:
--> 4774         spin_unlock_irqrestore(ap->lock, flags);
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Double unlock

    4775         mutex_unlock(&ap->scsi_scan_mutex);
    4776 
    4777         /* Reschedule with a delay if scsi_rescan_device() returned an error */
    4778         if (ret)
    4779                 schedule_delayed_work(&ap->scsi_rescan_task,
    4780                                       msecs_to_jiffies(5));
    4781 }

regards,
dan carpenter

                 reply	other threads:[~2024-04-11 13:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1c19822c-5622-4073-bc91-16523bb14302@moroto.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=dlemoal@kernel.org \
    --cc=linux-ide@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).