Skip to content

Commit

Permalink
ata: libata-eh: fix sloppy result type of ata_eh_nr_in_flight()
Browse files Browse the repository at this point in the history
ata_eh_nr_in_flight() counts the # of the active tagged commands and
thus cannot return a negative value but the result type is nevertheless
int.  Switching it to unsigned int (along with the local variables
receiving the function's result) helps avoiding the sign extension
instructions when comparing with or assigning to unsigned long
ata_port::fastdrain_cnt and thus results in a more compact 64-bit
code.

Found by Linux Verification Center (linuxtesting.org) with the SVACE
static analysis tool.

[Damien]
Fixed commit message.

Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
  • Loading branch information
Sergey Shtylyov authored and Damien Le Moal committed Jun 19, 2022
1 parent 4d6119f commit afae461
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/ata/libata-eh.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,11 +802,11 @@ void ata_port_wait_eh(struct ata_port *ap)
}
EXPORT_SYMBOL_GPL(ata_port_wait_eh);

static int ata_eh_nr_in_flight(struct ata_port *ap)
static unsigned int ata_eh_nr_in_flight(struct ata_port *ap)
{
struct ata_queued_cmd *qc;
unsigned int tag;
int nr = 0;
unsigned int nr = 0;

/* count only non-internal commands */
ata_qc_for_each(ap, qc, tag) {
Expand All @@ -821,7 +821,7 @@ void ata_eh_fastdrain_timerfn(struct timer_list *t)
{
struct ata_port *ap = from_timer(ap, t, fastdrain_timer);
unsigned long flags;
int cnt;
unsigned int cnt;

spin_lock_irqsave(ap->lock, flags);

Expand Down Expand Up @@ -870,7 +870,7 @@ void ata_eh_fastdrain_timerfn(struct timer_list *t)
*/
static void ata_eh_set_pending(struct ata_port *ap, int fastdrain)
{
int cnt;
unsigned int cnt;

/* already scheduled? */
if (ap->pflags & ATA_PFLAG_EH_PENDING)
Expand Down

0 comments on commit afae461

Please sign in to comment.