public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: luka.gejak@linux.dev
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Luka Gejak <luka.gejak@linux.dev>,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	Dan Carpenter <error27@gmail.com>
Subject: [PATCH v2] staging: rtl8723bs: clean up memcpy() in rtw_check_bcn_info
Date: Wed, 15 Apr 2026 10:56:38 +0200	[thread overview]
Message-ID: <20260415085638.6427-1-luka.gejak@linux.dev> (raw)

From: Luka Gejak <luka.gejak@linux.dev>

Move the ssid memcpy() inside the ie null-check to avoid calling it
with a NULL-derived pointer (p + 2) when the ie is missing.

While the kernel handles 0-length memcpy() safely as a no-op, keeping
the call outside the check is confusing and poor practice. This
change improves code readability.

Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
---
As Dan pointed out kernel handles 0-length memcpy() safely as a no-op 
therefore it doesn't cause kernel oops or panics so in v2 changed commit
message to move from bugfix to cleanup and removed fixes tag.

 drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c
index 6a7c09db4cd9..2a8aec37d9b0 100644
--- a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c
+++ b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c
@@ -1204,8 +1204,8 @@ int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len)
 		ssid_len = *(p + 1);
 		if (ssid_len > NDIS_802_11_LENGTH_SSID)
 			ssid_len = 0;
+		memcpy(bssid->ssid.ssid, (p + 2), ssid_len);
 	}
-	memcpy(bssid->ssid.ssid, (p + 2), ssid_len);
 	bssid->ssid.ssid_length = ssid_len;
 
 	if (memcmp(bssid->ssid.ssid, cur_network->network.ssid.ssid, 32) ||
-- 
2.53.0


             reply	other threads:[~2026-04-15  8:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15  8:56 luka.gejak [this message]
2026-04-15 10:07 ` [PATCH v2] staging: rtl8723bs: clean up memcpy() in rtw_check_bcn_info 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=20260415085638.6427-1-luka.gejak@linux.dev \
    --to=luka.gejak@linux.dev \
    --cc=error27@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