From: Robert Richter <rrichter@amd.com>
To: Zicheng Qu <quzicheng@huawei.com>
Cc: dave@stgolabs.net, jonathan.cameron@huawei.com,
dave.jiang@intel.com, alison.schofield@intel.com,
vishal.l.verma@intel.com, ira.weiny@intel.com,
dan.j.williams@intel.com, linux-cxl@vger.kernel.org,
linux-kernel@vger.kernel.org, tanghui20@huawei.com,
zhangqiao22@huawei.com, judy.chenhui@huawei.com
Subject: Re: [PATCH] cxl: core-pmu: Fix the usage of uninitialized variable
Date: Wed, 23 Oct 2024 14:26:32 +0200 [thread overview]
Message-ID: <ZxjreAV-re-rfJsv@rric.localdomain> (raw)
In-Reply-To: <20241023105610.668964-1-quzicheng@huawei.com>
On 23.10.24 10:56:10, Zicheng Qu wrote:
> In the devm_cxl_pmu_add() function, the variable rc might be
> uninitialized before its first use 'if (rc) goto err', leading
> to undefined behavior since its value depends on the compiler.
> Currently, the switch statement is limited to the CXL_PMU_MEMDEV type.
> If additional types are introduced, it could lead to similar concerns.
> If the type range remains unchanged, using a switch case is unnecessary.
> To enhance code extensibility and stability, it is recommended to
> address this potential aspect.
>
> Cc: stable@vger.kernel.org # v6.6+
> Fixes: 1ad3f701c399 ("cxl/pci: Find and register CXL PMU devices")
> Signed-off-by: Zicheng Qu <quzicheng@huawei.com>
> ---
> drivers/cxl/core/pmu.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/cxl/core/pmu.c b/drivers/cxl/core/pmu.c
> index 5d8e06b0ba6e..2d12887c9915 100644
> --- a/drivers/cxl/core/pmu.c
> +++ b/drivers/cxl/core/pmu.c
> @@ -51,6 +51,9 @@ int devm_cxl_pmu_add(struct device *parent, struct cxl_pmu_regs *regs,
> case CXL_PMU_MEMDEV:
> rc = dev_set_name(dev, "pmu_mem%d.%d", assoc_id, index);
> break;
> + default:
> + rc = -EINVAL;
> + break;
You might consider to use the -ENOENT error code and/or to
preinitialize rc with the error code. The default case can be dropped
then.
However, all those variants look ok:
Reviewed-by: Robert Richter <rrichter@amd.com>
> }
> if (rc)
> goto err;
> --
> 2.34.1
>
next prev parent reply other threads:[~2024-10-23 12:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 10:56 [PATCH] cxl: core-pmu: Fix the usage of uninitialized variable Zicheng Qu
2024-10-23 12:26 ` Robert Richter [this message]
2024-10-24 9:38 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZxjreAV-re-rfJsv@rric.localdomain \
--to=rrichter@amd.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=ira.weiny@intel.com \
--cc=jonathan.cameron@huawei.com \
--cc=judy.chenhui@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=quzicheng@huawei.com \
--cc=tanghui20@huawei.com \
--cc=vishal.l.verma@intel.com \
--cc=zhangqiao22@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox