RE: [PATCH resent] mei: Fix exception handling in mei_cl_irq_read_msg()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Date: Tue, 21 Mar 2023 18:11:13 +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.
> 
> Fixes: a808c80cdaa83939b220176fcdffca8385d88ba6 ("mei: add read callback
> on demand for fixed_address clients")
> Fixes: 17ba8a08b58a01bbac35790ffca4388ca92b7790 ("mei: consolidate
> repeating code in mei_cl_irq_read_msg")


This is a refactoring not a bug fix, or am I missing something 

> Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>

This looks better than the original code, but I would drop the 'Fix' wording.  


> ---
>  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
> 0a0e984e5673..9800d30b7693 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:
> +	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.40.0





[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux