From: cgel.zte@gmail.com
To: luciano.coelho@intel.com
Cc: kvalo@kernel.org, davem@davemloft.net, kuba@kernel.org,
trix@redhat.com, johannes.berg@intel.com,
linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
Minghao Chi <chi.minghao@zte.com.cn>,
Zeal Robot <zealci@zte.com.cn>
Subject: [PATCH] dvm: use struct_size over open coded arithmetic
Date: Fri, 28 Jan 2022 08:02:06 +0000 [thread overview]
Message-ID: <20220128080206.1211452-1-chi.minghao@zte.com.cn> (raw)
From: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
Replace zero-length array with flexible-array member and make use
of the struct_size() helper in kmalloc(). For example:
struct iwl_wipan_noa_data {
...
u8 data[];
};
Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
---
drivers/net/wireless/intel/iwlwifi/dvm/rx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/rx.c b/drivers/net/wireless/intel/iwlwifi/dvm/rx.c
index db0c41bbeb0e..d0d842b25b86 100644
--- a/drivers/net/wireless/intel/iwlwifi/dvm/rx.c
+++ b/drivers/net/wireless/intel/iwlwifi/dvm/rx.c
@@ -915,7 +915,7 @@ static void iwlagn_rx_noa_notification(struct iwl_priv *priv,
len += 1 + 2;
copylen += 1 + 2;
- new_data = kmalloc(sizeof(*new_data) + len, GFP_ATOMIC);
+ new_data = kmalloc(struct_size(*new_data, data, len), GFP_ATOMIC);
if (new_data) {
new_data->length = len;
new_data->data[0] = WLAN_EID_VENDOR_SPECIFIC;
--
2.25.1
next reply other threads:[~2022-01-28 8:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-28 8:02 cgel.zte [this message]
2022-01-28 9:01 ` [PATCH] dvm: use struct_size over open coded arithmetic Kalle Valo
2022-01-28 9:31 ` [PATCH v2] iwlwifi: " cgel.zte
2022-01-28 12:34 ` Coelho, Luciano
2022-01-28 21:03 ` [PATCH] " kernel test robot
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=20220128080206.1211452-1-chi.minghao@zte.com.cn \
--to=cgel.zte@gmail.com \
--cc=chi.minghao@zte.com.cn \
--cc=davem@davemloft.net \
--cc=johannes.berg@intel.com \
--cc=kuba@kernel.org \
--cc=kvalo@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=luciano.coelho@intel.com \
--cc=netdev@vger.kernel.org \
--cc=trix@redhat.com \
--cc=zealci@zte.com.cn \
/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;
as well as URLs for NNTP newsgroup(s).