Skip to content

Commit 9d8ca62

Browse files
MrVanJassiBrar
authored andcommitted
mailbox: imx-mailbox: fix scu msg header size check
The i.MX8 SCU message header size is the number of "u32" elements, not "u8", so fix the check. Reported-by: coverity-bot <[email protected]> Addresses-Coverity-ID: 1461658 ("Memory - corruptions") Signed-off-by: Peng Fan <[email protected]> Reviewed-by: Leonard Crestez <[email protected]> Acked-by: Oleksij Rempel <[email protected]> Signed-off-by: Jassi Brar <[email protected]>
1 parent ca27fc2 commit 9d8ca62

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

drivers/mailbox/imx-mailbox.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,17 @@ static int imx_mu_scu_tx(struct imx_mu_priv *priv,
155155

156156
switch (cp->type) {
157157
case IMX_MU_TYPE_TX:
158-
if (msg->hdr.size > sizeof(*msg)) {
158+
/*
159+
* msg->hdr.size specifies the number of u32 words while
160+
* sizeof yields bytes.
161+
*/
162+
163+
if (msg->hdr.size > sizeof(*msg) / 4) {
159164
/*
160165
* The real message size can be different to
161166
* struct imx_sc_rpc_msg_max size
162167
*/
163-
dev_err(priv->dev, "Exceed max msg size (%zu) on TX, got: %i\n", sizeof(*msg), msg->hdr.size);
168+
dev_err(priv->dev, "Maximal message size (%zu bytes) exceeded on TX; got: %i bytes\n", sizeof(*msg), msg->hdr.size << 2);
164169
return -EINVAL;
165170
}
166171

@@ -199,9 +204,8 @@ static int imx_mu_scu_rx(struct imx_mu_priv *priv,
199204
imx_mu_xcr_rmw(priv, 0, IMX_MU_xCR_RIEn(0));
200205
*data++ = imx_mu_read(priv, priv->dcfg->xRR[0]);
201206

202-
if (msg.hdr.size > sizeof(msg)) {
203-
dev_err(priv->dev, "Exceed max msg size (%zu) on RX, got: %i\n",
204-
sizeof(msg), msg.hdr.size);
207+
if (msg.hdr.size > sizeof(msg) / 4) {
208+
dev_err(priv->dev, "Maximal message size (%zu bytes) exceeded on RX; got: %i bytes\n", sizeof(msg), msg.hdr.size << 2);
205209
return -EINVAL;
206210
}
207211

0 commit comments

Comments
 (0)