diff mbox series

[1/2] ata: libata-eh: fix sloppy result type of ata_eh_nr_in_flight()

Message ID 20220616205149.16157-2-s.shtylyov@omp.ru
State New
Headers show
Series Fix sloppy typing in the fast drain logic | expand

Commit Message

Sergey Shtylyov June 16, 2022, 8:51 p.m. UTC
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.

Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
---
 drivers/ata/libata-eh.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Sergey Shtylyov June 17, 2022, 6:16 p.m. UTC | #1
On 6/16/22 11:51 PM, Sergey Shtylyov wrote:

> 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

   Grr, a typo! Should have been *unsigned long* ata_port::fastdrain_cnt...
Damien, coyld you please fix it?

> thus results in a more compact 64-bit code...
> 
> Found by Linux Verification Center (linuxtesting.org) with the SVACE static
> analysis tool.
> 
> Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
[...]

MBR, Sergey
Damien Le Moal June 19, 2022, 11:15 p.m. UTC | #2
On 6/18/22 03:16, Sergey Shtylyov wrote:
> On 6/16/22 11:51 PM, Sergey Shtylyov wrote:
> 
>> 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
> 
>    Grr, a typo! Should have been *unsigned long* ata_port::fastdrain_cnt...
> Damien, coyld you please fix it?

OK. Note: please stop using markdown stuff like *xxx*. That is not useful
and that will avoid this kind of typos.

> 
>> thus results in a more compact 64-bit code...
>>
>> Found by Linux Verification Center (linuxtesting.org) with the SVACE static
>> analysis tool.
>>
>> Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
> [...]
> 
> MBR, Sergey
diff mbox series

Patch

diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 3307ed45fe4d..25586e16692d 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -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) {
@@ -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);
 
@@ -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)