Skip to content

Commit 042f552

Browse files
bvanasschefloatious
authored andcommitted
ata: Annotate functions in the issuing path with __must_hold()
Annotate the following functions used in the issuing path: ata_qc_issue(), ata_sas_queuecmd(), ata_scsi_qc_issue(), ata_scsi_translate(), __ata_scsi_queuecmd() These functions are all used in the issuing path, so context analysis will be able to verify that the ap lock is held, from it is taken in sas_queuecommand() or ata_scsi_queuecmd() all the way down to ata_qc_issue(). Commenting out the spin_lock_irqsave() successfully results in a compiler error on Clang 23. Signed-off-by: Bart Van Assche <bvanassche@acm.org> Co-developed-by: Niklas Cassel <cassel@kernel.org> Reviewed-by: Hannes Reinecke <hare@kernel.org> Signed-off-by: Niklas Cassel <cassel@kernel.org>
1 parent b241235 commit 042f552

5 files changed

Lines changed: 11 additions & 3 deletions

File tree

drivers/ata/libata-core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5162,6 +5162,7 @@ EXPORT_SYMBOL_GPL(ata_qc_get_active);
51625162
* spin_lock_irqsave(host lock)
51635163
*/
51645164
void ata_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc)
5165+
__must_hold(ap->lock)
51655166
{
51665167
struct ata_link *link = qc->dev->link;
51675168
u8 prot = qc->tf.protocol;

drivers/ata/libata-sata.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ EXPORT_SYMBOL_GPL(ata_sas_sdev_configure);
13771377
*/
13781378

13791379
int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap)
1380+
__must_hold(ap->lock)
13801381
{
13811382
if (likely(ata_dev_enabled(ap->link.device)))
13821383
return __ata_scsi_queuecmd(cmd, ap->link.device, ap);

drivers/ata/libata-scsi.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,7 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
17691769
}
17701770

17711771
static int ata_scsi_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc)
1772+
__must_hold(ap->lock)
17721773
{
17731774
struct ata_link *link = qc->dev->link;
17741775
int ret;
@@ -1864,6 +1865,7 @@ static int ata_scsi_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc)
18641865
*/
18651866
static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
18661867
ata_xlat_func_t xlat_func, struct ata_port *ap)
1868+
__must_hold(ap->lock)
18671869
{
18681870
struct ata_queued_cmd *qc;
18691871

@@ -4523,6 +4525,7 @@ static void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd)
45234525
enum scsi_qc_status __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
45244526
struct ata_device *dev,
45254527
struct ata_port *ap)
4528+
__must_hold(ap->lock)
45264529
{
45274530
u8 scsi_op = scmd->cmnd[0];
45284531
ata_xlat_func_t xlat_func;

drivers/ata/libata.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel);
8888
extern unsigned int ata_dev_set_feature(struct ata_device *dev,
8989
u8 subcmd, u8 action);
9090
extern void ata_qc_free(struct ata_queued_cmd *qc);
91-
extern void ata_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc);
91+
extern void ata_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc)
92+
__must_hold(ap->lock);
9293
extern void __ata_qc_complete(struct ata_queued_cmd *qc);
9394
extern int atapi_check_dma(struct ata_queued_cmd *qc);
9495
extern void swap_buf_le16(u16 *buf, unsigned int buf_words);
@@ -167,7 +168,8 @@ int ata_scsi_dev_config(struct scsi_device *sdev, struct queue_limits *lim,
167168
struct ata_device *dev);
168169
enum scsi_qc_status __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
169170
struct ata_device *dev,
170-
struct ata_port *ap);
171+
struct ata_port *ap)
172+
__must_hold(ap->lock);
171173
void ata_scsi_deferred_qc_work(struct work_struct *work);
172174
void ata_scsi_requeue_deferred_qc(struct ata_port *ap);
173175

include/linux/libata.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,8 @@ extern int ata_tport_add(struct device *parent, struct ata_port *ap);
13151315
extern void ata_tport_delete(struct ata_port *ap);
13161316
int ata_sas_sdev_configure(struct scsi_device *sdev, struct queue_limits *lim,
13171317
struct ata_port *ap);
1318-
extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
1318+
extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap)
1319+
__must_hold(ap->lock);
13191320
extern void ata_tf_to_fis(const struct ata_taskfile *tf,
13201321
u8 pmp, int is_cmd, u8 *fis);
13211322
extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf);

0 commit comments

Comments
 (0)