Linux kernel staging patches
 help / color / mirror / Atom feed
From: William Hansen-Baird <william.hansen.baird@gmail.com>
To: gregkh@linuxfoundation.org
Cc: dan.carpenter@linaro.org, david.laight.linux@gmail.com,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	William Hansen-Baird <william.hansen.baird@gmail.com>
Subject: [PATCH v4] staging: rtl8723bs: replace ternary min comparison with min()
Date: Sat,  7 Feb 2026 17:01:36 -0500	[thread overview]
Message-ID: <20260207220136.67923-1-william.hansen.baird@gmail.com> (raw)

Change type of local variable wpa_ie_len from int to u8.
wpa_ie_len gets its value either from elems->wpa_ie_len or
elems->rsn_ie_len which are both u8, and thus there's no reason
to cast them to int.

This allows rewriting ternary min comparison using the min() function from
linux/minmax.h as now both sides are unsigned.

Rewrite as well wpa_ie_len + 2 to wpa_ie_len + 2u,
to keep the expression unsigned and avoid overflows.

Signed-off-by: William Hansen-Baird <william.hansen.baird@gmail.com>
---
v4:
-Rebased changes on main tree rather than previous patches.

v3:
-Applied feedback from David Laight and Dan Carpenter
-Reorder include alphabetically
-Made wpa_ie_len unsigned
-Rewrote title and body to reflect change from min_t() to min(), as
 min_t() is now unnecessary after changes, and should be avoided.

v2:
-Drop unrelated style changes and fix style issues by running checkpatch.
-Keep min_t() to make the signedness of the comparison explicit.

 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index ac49bfbaa5bb..4c3a89064c3f 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -8,6 +8,7 @@
 #include <rtw_wifi_regd.h>
 #include <hal_btcoex.h>
 #include <linux/kernel.h>
+#include <linux/minmax.h>
 #include <linux/unaligned.h>
 
 static struct mlme_handler mlme_sta_tbl[] = {
@@ -936,7 +937,8 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
 	struct sta_info *pstat;
 	unsigned char *p, *pos, *wpa_ie;
 	unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
-	int		i, ie_len, wpa_ie_len, left;
+	int		i, ie_len, left;
+	u8 wpa_ie_len;
 	unsigned char supportRate[16];
 	int					supportRateNum;
 	unsigned short		status = WLAN_STATUS_SUCCESS;
@@ -1158,7 +1160,7 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
 			pstat->flags |= WLAN_STA_WPS;
 			copy_len = 0;
 		} else {
-			copy_len = ((wpa_ie_len+2) > sizeof(pstat->wpa_ie)) ? (sizeof(pstat->wpa_ie)):(wpa_ie_len+2);
+			copy_len = min(sizeof(pstat->wpa_ie), wpa_ie_len + 2u);
 		}
 
 
-- 
2.52.0


             reply	other threads:[~2026-02-07 22:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-07 22:01 William Hansen-Baird [this message]
2026-02-09  5:37 ` [PATCH v4] staging: rtl8723bs: replace ternary min comparison with min() Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260207220136.67923-1-william.hansen.baird@gmail.com \
    --to=william.hansen.baird@gmail.com \
    --cc=dan.carpenter@linaro.org \
    --cc=david.laight.linux@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox