Skip to contentSkip to conversation

liquidio: style: Identical condition and return expression 'retval', return value is always 0.

PATCH In review YANG LI 3 participants 3 messages Dec 30, 2020 – Jan 5, 2021

Subsystems (3)
lore
Share & tools
lore

YANG LI

author
#0 lore raw

PATCH 1/1 liquidio: style: Identical condition and return expression 'retval', return value is always 0.

The warning was because of the following line in function liquidio_set_fec():

retval = wait_for_sc_completion_timeout(oct, sc, 0);
    if (retval)
	return (-EIO);

If this statement is not true, retval must be 0 and not updated later. So, It is better to return 0 directly.

---
 drivers/net/ethernet/cavium/liquidio/lio_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cavium/liquidio/lio_core.c +1 -1
index 37d0641..6e2426f 100644
@@ -1747,7 +1747,7 @@ int liquidio_set_fec(struct lio *lio, int on_off)
 			oct->props[lio->ifidx].fec ? "on" : "off");
 	}
 
-	return retval;
+	return 0;
 }
 
 int liquidio_get_fec(struct lio *lio)
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 6 lines · YANG LI

The warning was because of the following line in function liquidio_set_fec():

retval = wait_for_sc_completion_timeout(oct, sc, 0); if (retval)

	return (-EIO);

I presume abaci is a robot

Perhaps also the robot could look for code immediately above this like:

		oct->props[lio->ifidx].fec = var;
		if (resp->fec_setting == SEAPI_CMD_FEC_SET_RS)
			oct->props[lio->ifidx].fec = 1;
		else
			oct->props[lio->ifidx].fec = 0;

where a location is immediately overwritten.

so the line

		oct->props[lio->ifidx].fec = var;

could be highlighted and perhaps removed
and also perhaps the second test and set block could be written

		oct->props[lio->ifidx].fec = resp->fec_setting == SEAPI_CMD_FEC_SET_RS;
maintainer
#2 lore raw
In reply to YANG LI

From: YANG LI <[email protected]>
Date: Wed, 30 Dec 2020 14:07:30 +0800

Quoted 7 lines

The warning was because of the following line in function liquidio_set_fec():

retval = wait_for_sc_completion_timeout(oct, sc, 0);
    if (retval)
	return (-EIO);
Quoted 5 lines

If this statement is not true, retval must be 0 and not updated later. So, It is better to return 0 directly.

Maybe you can remove the rest of the 'retval' usage in this function and even the variable itself?

Thanks.