[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <3b412741-4fda-4285-b1bb-80c89f0fcf38@zohomail.com>
Date: Sun, 20 Apr 2025 18:43:37 +0800
From: Li Ming <ming.li@...omail.com>
To: Purva Yeshi <purvayeshi550@...il.com>
Cc: huang.ying.caritas@...il.com, linux-cxl@...r.kernel.org,
linux-kernel@...r.kernel.org, dave@...olabs.net,
jonathan.cameron@...wei.com, dave.jiang@...el.com,
alison.schofield@...el.com, vishal.l.verma@...el.com, ira.weiny@...el.com,
dan.j.williams@...el.com
Subject: Re: [PATCH] cxl: core: Initialize eiw and eig to fix potential
uninitialized use
On 4/20/2025 4:35 AM, Purva Yeshi wrote:
> Fix Smatch-detected issue:
>
> drivers/cxl/core/region.c:1292 check_interleave_cap()
> error: uninitialized symbol 'eiw'.
> drivers/cxl/core/region.c:1297 check_interleave_cap()
> error: uninitialized symbol 'eig'.
> drivers/cxl/core/region.c:1299 check_interleave_cap()
> error: uninitialized symbol 'eig'.
>
> Smatch reports possible uninitialized usage of these variables if
> the helper functions ways_to_eiw() or granularity_to_eig() fail to
> assign values under certain conditions.
>
> Initialize the eiw and eig variables to zero when they are declared
> in check_interleave_cap() to prevent potential use of uninitialized
> values.
I also met them during checking cxl drivers code with code inspection tools. But they are not real issues, because both iw and ig are checked before calling check_interleave_cap(). That means check_interleave_cap() will always get a eiw and a eig correctly.
they are checked in cxl_port_setup_targets() in auto-assembly case, otherwise checked in interleave_ways_store() and interleave_guranularity_store().
I am not sure if we need this patch, let's see if other reviewers have more comments.
Ming
>
> Signed-off-by: Purva Yeshi <purvayeshi550@...il.com>
> ---
> drivers/cxl/core/region.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index c3f4dc244df7..edf8636f190a 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -1266,8 +1266,8 @@ static int check_interleave_cap(struct cxl_decoder *cxld, int iw, int ig)
> struct cxl_port *port = to_cxl_port(cxld->dev.parent);
> struct cxl_hdm *cxlhdm = dev_get_drvdata(&port->dev);
> unsigned int interleave_mask;
> - u8 eiw;
> - u16 eig;
> + u8 eiw = 0;
> + u16 eig = 0;
> int high_pos, low_pos;
>
> if (!test_bit(iw, &cxlhdm->iw_cap_mask))
Powered by blists - more mailing lists