The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Jiasheng Jiang <jiashengjiangcool@gmail.com>
To: przemyslaw.kitszel@intel.com
Cc: arkadiusz.kubalewski@intel.com, davem@davemloft.net,
	jan.glaza@intel.com, jiashengjiangcool@gmail.com,
	jiri@resnulli.us, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, stable@vger.kernel.org,
	vadim.fedorenko@linux.dev
Subject: [PATCH v4 net-next] dpll: Add an assertion to check freq_supported_num
Date: Fri, 28 Feb 2025 15:02:10 +0000	[thread overview]
Message-ID: <20250228150210.34404-1-jiashengjiangcool@gmail.com> (raw)

Since the driver is broken in the case that src->freq_supported is not
NULL but src->freq_supported_num is 0, add an assertion for it.

Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
Changelog:

v3 -> v4:

1. Add return after WARN_ON().

v2 -> v3:

1. Add "net-next" to the subject.
2. Remove the "Fixes" tag and "Cc: stable".
3. Replace BUG_ON with WARN_ON.

v1 -> v2:

1. Replace the check with an assertion.
---
 drivers/dpll/dpll_core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c
index 32019dc33cca..940c26b9dd53 100644
--- a/drivers/dpll/dpll_core.c
+++ b/drivers/dpll/dpll_core.c
@@ -443,8 +443,11 @@ static void dpll_pin_prop_free(struct dpll_pin_properties *prop)
 static int dpll_pin_prop_dup(const struct dpll_pin_properties *src,
 			     struct dpll_pin_properties *dst)
 {
+	if (WARN_ON(src->freq_supported && !src->freq_supported_num))
+		return -EINVAL;
+
 	memcpy(dst, src, sizeof(*dst));
-	if (src->freq_supported && src->freq_supported_num) {
+	if (src->freq_supported) {
 		size_t freq_size = src->freq_supported_num *
 				   sizeof(*src->freq_supported);
 		dst->freq_supported = kmemdup(src->freq_supported,
-- 
2.25.1


             reply	other threads:[~2025-02-28 15:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-28 15:02 Jiasheng Jiang [this message]
2025-02-28 15:22 ` [PATCH v4 net-next] dpll: Add an assertion to check freq_supported_num Jiri Pirko
2025-02-28 16:37 ` Vadim Fedorenko
2025-02-28 16:42 ` Kubalewski, Arkadiusz
2025-03-05  1:20 ` patchwork-bot+netdevbpf

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=20250228150210.34404-1-jiashengjiangcool@gmail.com \
    --to=jiashengjiangcool@gmail.com \
    --cc=arkadiusz.kubalewski@intel.com \
    --cc=davem@davemloft.net \
    --cc=jan.glaza@intel.com \
    --cc=jiri@resnulli.us \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=stable@vger.kernel.org \
    --cc=vadim.fedorenko@linux.dev \
    /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