[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CY5PR11MB6366D07A7F302780A87160E6EDCB2@CY5PR11MB6366.namprd11.prod.outlook.com>
Date: Wed, 5 Mar 2025 07:08:48 +0000
From: "Usyskin, Alexander" <alexander.usyskin@...el.com>
To: Markus Elfring <Markus.Elfring@....de>, "kernel-janitors@...r.kernel.org"
<kernel-janitors@...r.kernel.org>, Arnd Bergmann <arnd@...db.de>, "Greg
Kroah-Hartman" <gregkh@...uxfoundation.org>, Tomas Winkler
<tomas.winkler@...el.com>
CC: "cocci@...ia.fr" <cocci@...ia.fr>, LKML <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH v2] mei: Improve exception handling in
mei_cl_irq_read_msg()
>
> From: Markus Elfring <elfring@...rs.sourceforge.net>
> Date: Tue, 4 Mar 2025 18:11:05 +0100
>
> The label “discard” was used to jump to another pointer check despite of
> the detail in the implementation of the function “mei_cl_irq_read_msg”
> that it was determined already that a corresponding variable contained
> a null pointer.
>
> * Thus use an additional label instead.
>
> * Delete a redundant check.
>
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@...rs.sourceforge.net>
> ---
>
> V2:
> * The summary phrase was adjusted a bit.
>
> * The Fixes tags were omitted.
>
> * The change suggestion was rebased on source files of
> the software “Linux next-20250228”.
>
>
> drivers/misc/mei/interrupt.c | 22 +++++++++++-----------
> 1 file changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/misc/mei/interrupt.c b/drivers/misc/mei/interrupt.c
> index b09b79fedaba..af5f01eefea4 100644
> --- a/drivers/misc/mei/interrupt.c
> +++ b/drivers/misc/mei/interrupt.c
> @@ -136,7 +136,7 @@ static int mei_cl_irq_read_msg(struct mei_cl *cl,
> cb->ext_hdr = kzalloc(sizeof(*gsc_f2h),
> GFP_KERNEL);
> if (!cb->ext_hdr) {
> cb->status = -ENOMEM;
> - goto discard;
> + goto move_tail;
> }
> break;
> case MEI_EXT_HDR_NONE:
> @@ -153,7 +153,7 @@ static int mei_cl_irq_read_msg(struct mei_cl *cl,
> if (!vtag_hdr && !gsc_f2h) {
> cl_dbg(dev, cl, "no vtag or gsc found in extended
> header.\n");
> cb->status = -EPROTO;
> - goto discard;
> + goto move_tail;
> }
> }
>
> @@ -163,7 +163,7 @@ static int mei_cl_irq_read_msg(struct mei_cl *cl,
> cl_err(dev, cl, "mismatched tag: %d != %d\n",
> cb->vtag, vtag_hdr->vtag);
> cb->status = -EPROTO;
> - goto discard;
> + goto move_tail;
> }
> cb->vtag = vtag_hdr->vtag;
> }
> @@ -174,18 +174,18 @@ static int mei_cl_irq_read_msg(struct mei_cl *cl,
> if (!dev->hbm_f_gsc_supported) {
> cl_err(dev, cl, "gsc extended header is not
> supported\n");
> cb->status = -EPROTO;
> - goto discard;
> + goto move_tail;
> }
>
> if (length) {
> cl_err(dev, cl, "no data allowed in cb with gsc\n");
> cb->status = -EPROTO;
> - goto discard;
> + goto move_tail;
> }
> if (ext_hdr_len > sizeof(*gsc_f2h)) {
> cl_err(dev, cl, "gsc extended header is too big %u\n",
> ext_hdr_len);
> cb->status = -EPROTO;
> - goto discard;
> + goto move_tail;
> }
> memcpy(cb->ext_hdr, gsc_f2h, ext_hdr_len);
> }
> @@ -193,7 +193,7 @@ static int mei_cl_irq_read_msg(struct mei_cl *cl,
> if (!mei_cl_is_connected(cl)) {
> cl_dbg(dev, cl, "not connected\n");
> cb->status = -ENODEV;
> - goto discard;
> + goto move_tail;
> }
>
> if (mei_hdr->dma_ring)
> @@ -205,14 +205,14 @@ static int mei_cl_irq_read_msg(struct mei_cl *cl,
> cl_err(dev, cl, "message is too big len %d idx %zu\n",
> length, cb->buf_idx);
> cb->status = -EMSGSIZE;
> - goto discard;
> + goto move_tail;
> }
>
> if (cb->buf.size < buf_sz) {
> cl_dbg(dev, cl, "message overflow. size %zu len %d idx
> %zu\n",
> cb->buf.size, length, cb->buf_idx);
> cb->status = -EMSGSIZE;
> - goto discard;
> + goto move_tail;
> }
>
> if (mei_hdr->dma_ring) {
> @@ -235,9 +235,9 @@ static int mei_cl_irq_read_msg(struct mei_cl *cl,
>
> return 0;
>
> +move_tail:
In general, why not, but the label naming is bad.
It hides the original intent to discard this message.
Let's rename existing label to discard_nocb: and leave a new one as discard:.
Also, the patch will be smaller in this way.
- -
Thanks,
Sasha
> + list_move_tail(&cb->list, cmpl_list);
> discard:
> - if (cb)
> - list_move_tail(&cb->list, cmpl_list);
> mei_irq_discard_msg(dev, mei_hdr, length);
> return 0;
> }
> --
> 2.48.1
Powered by blists - more mailing lists