]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mailbox: imx-mailbox: fix scu msg header size check
authorPeng Fan <peng.fan@nxp.com>
Tue, 14 Apr 2020 13:21:15 +0000 (21:21 +0800)
committerJassi Brar <jaswinder.singh@linaro.org>
Sat, 30 May 2020 23:07:07 +0000 (18:07 -0500)
The i.MX8 SCU message header size is the number of "u32" elements,
not "u8", so fix the check.

Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1461658 ("Memory - corruptions")
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com>
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
drivers/mailbox/imx-mailbox.c

index 19f8d79cebac07e8f7197322949abad82682e220..bd69ecfb93522a7a98e036a8d64f9d60b6784962 100644 (file)
@@ -155,12 +155,17 @@ static int imx_mu_scu_tx(struct imx_mu_priv *priv,
 
        switch (cp->type) {
        case IMX_MU_TYPE_TX:
-               if (msg->hdr.size > sizeof(*msg)) {
+               /*
+                * msg->hdr.size specifies the number of u32 words while
+                * sizeof yields bytes.
+                */
+
+               if (msg->hdr.size > sizeof(*msg) / 4) {
                        /*
                         * The real message size can be different to
                         * struct imx_sc_rpc_msg_max size
                         */
-                       dev_err(priv->dev, "Exceed max msg size (%zu) on TX, got: %i\n", sizeof(*msg), msg->hdr.size);
+                       dev_err(priv->dev, "Maximal message size (%zu bytes) exceeded on TX; got: %i bytes\n", sizeof(*msg), msg->hdr.size << 2);
                        return -EINVAL;
                }
 
@@ -199,9 +204,8 @@ static int imx_mu_scu_rx(struct imx_mu_priv *priv,
        imx_mu_xcr_rmw(priv, 0, IMX_MU_xCR_RIEn(0));
        *data++ = imx_mu_read(priv, priv->dcfg->xRR[0]);
 
-       if (msg.hdr.size > sizeof(msg)) {
-               dev_err(priv->dev, "Exceed max msg size (%zu) on RX, got: %i\n",
-                       sizeof(msg), msg.hdr.size);
+       if (msg.hdr.size > sizeof(msg) / 4) {
+               dev_err(priv->dev, "Maximal message size (%zu bytes) exceeded on RX; got: %i bytes\n", sizeof(msg), msg.hdr.size << 2);
                return -EINVAL;
        }