linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: cgel.zte@gmail.com
To: kvalo@kernel.org
Cc: cgel.zte@gmail.com, chi.minghao@zte.com.cn, davem@davemloft.net,
	johannes.berg@intel.com, kuba@kernel.org,
	linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org,
	luciano.coelho@intel.com, netdev@vger.kernel.org,
	trix@redhat.com, zealci@zte.com.cn
Subject: [PATCH v2] iwlwifi: dvm: use struct_size over open coded arithmetic
Date: Fri, 28 Jan 2022 09:31:47 +0000	[thread overview]
Message-ID: <20220128093147.1213351-1-chi.minghao@zte.com.cn> (raw)
In-Reply-To: <87o83wi67x.fsf@kernel.org>

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


  reply	other threads:[~2022-01-28  9:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-28  8:02 [PATCH] dvm: use struct_size over open coded arithmetic cgel.zte
2022-01-28  9:01 ` Kalle Valo
2022-01-28  9:31   ` cgel.zte [this message]
2022-01-28 12:34     ` [PATCH v2] iwlwifi: " Coelho, Luciano
2022-01-28 21:03 ` [PATCH] " kernel test robot
2022-02-10  6:09 [PATCH V2] iwlwifi: " cgel.zte

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=20220128093147.1213351-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).