Skip to contentSkip to conversation

staging: r8188eu: refactor two small functions

PATCH New Michael Straube 1 participant 5 messages Mar 29, 2022 Staging

lore
Share & tools
lore
#0 lore raw

cover staging: r8188eu: refactor two small functions

This series refactors two small functions to improve readability.

Tested on x86_64 with Inter-Tech DMG-02.

Michael Straube (4):
staging: r8188eu: refactor rtw_usb_bulk_size_boundary()
staging: r8188eu: refactor rtw_inc_and_chk_continual_urb_error()
staging: r8188eu: convert rtw_usb_bulk_size_boundary() to bool
staging: r8188eu: convert rtw_inc_and_chk_continual_urb_error() to
bool

 drivers/staging/r8188eu/include/usb_ops.h | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)
Signature · 1 line
2.35.1
#1 lore raw

PATCH 1/4 staging: r8188eu: refactor rtw_usb_bulk_size_boundary()

Using ternary operator to set a variable to true or false is not needed. Convert two such uses of ternary operator in rtw_usb_bulk_size_boundary() to just use the condition and return the value directly instead of using a return variable. This shortens the code and improves readability. While at it, remove an unneeded line break from the function head.

---
 drivers/staging/r8188eu/include/usb_ops.h | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/staging/r8188eu/include/usb_ops.h +3 -8
index 14526fcff4ae..3416c8baceb6 100644
@@ -47,19 +47,14 @@ static inline void rtw_reset_continual_urb_error(struct dvobj_priv *dvobj)
 #define USB_HIGH_SPEED_BULK_SIZE	512
 #define USB_FULL_SPEED_BULK_SIZE	64
 
-static inline u8 rtw_usb_bulk_size_boundary(struct adapter *padapter,
-					    int buf_len)
+static inline u8 rtw_usb_bulk_size_boundary(struct adapter *padapter, int buf_len)
 {
-	u8 rst = true;
 	struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
 
 	if (pdvobjpriv->pusbdev->speed == USB_SPEED_HIGH)
-		rst = (0 == (buf_len) % USB_HIGH_SPEED_BULK_SIZE) ?
-		      true : false;
+		return buf_len % USB_HIGH_SPEED_BULK_SIZE == 0;
 	else
-		rst = (0 == (buf_len) % USB_FULL_SPEED_BULK_SIZE) ?
-		      true : false;
-	return rst;
+		return buf_len % USB_FULL_SPEED_BULK_SIZE == 0;
 }
 
 #endif /* __USB_OPS_H_ */
Signature · 1 line
2.35.1
#2 lore raw

PATCH 2/4 staging: r8188eu: refactor rtw_inc_and_chk_continual_urb_error()

In reply to Michael Straube

Refactor rtw_inc_and_chk_continual_urb_error(). Return directly instead of using a return variable and initialize the variable 'value' at declaration. This shortens the code and improves readability.

---
 drivers/staging/r8188eu/include/usb_ops.h | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/r8188eu/include/usb_ops.h +4 -5
index 3416c8baceb6..cfcf6f84d2cf 100644
@@ -27,13 +27,12 @@
  */
 static inline int rtw_inc_and_chk_continual_urb_error(struct dvobj_priv *dvobj)
 {
-	int ret = false;
-	int value;
-	value = atomic_inc_return(&dvobj->continual_urb_error);
+	int value = atomic_inc_return(&dvobj->continual_urb_error);
+
 	if (value > MAX_CONTINUAL_URB_ERR)
-		ret = true;
+		return true;
 
-	return ret;
+	return false;
 }
 
 /*
Signature · 1 line
2.35.1
#3 lore raw

PATCH 3/4 staging: r8188eu: convert rtw_usb_bulk_size_boundary() to bool

In reply to Michael Straube

Function rtw_usb_bulk_size_boundary() returns boolean values. Change its return type from u8 to bool.

---
 drivers/staging/r8188eu/include/usb_ops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/r8188eu/include/usb_ops.h +1 -1
index cfcf6f84d2cf..5ee1c8c7940d 100644
@@ -46,7 +46,7 @@ static inline void rtw_reset_continual_urb_error(struct dvobj_priv *dvobj)
 #define USB_HIGH_SPEED_BULK_SIZE	512
 #define USB_FULL_SPEED_BULK_SIZE	64
 
-static inline u8 rtw_usb_bulk_size_boundary(struct adapter *padapter, int buf_len)
+static inline bool rtw_usb_bulk_size_boundary(struct adapter *padapter, int buf_len)
 {
 	struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
 
Signature · 1 line
2.35.1
#4 lore raw

PATCH 4/4 staging: r8188eu: convert rtw_inc_and_chk_continual_urb_error() to bool

In reply to Michael Straube

Function rtw_inc_and_chk_continual_urb_error() returns boolean values. Change its return type from int to bool.

---
 drivers/staging/r8188eu/include/usb_ops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/r8188eu/include/usb_ops.h +1 -1
index 5ee1c8c7940d..ddc46cb44358 100644
@@ -25,7 +25,7 @@
  * @return true:
  * @return false:
  */
-static inline int rtw_inc_and_chk_continual_urb_error(struct dvobj_priv *dvobj)
+static inline bool rtw_inc_and_chk_continual_urb_error(struct dvobj_priv *dvobj)
 {
 	int value = atomic_inc_return(&dvobj->continual_urb_error);
 
Signature · 1 line
2.35.1