DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>,
	stable@dpdk.org, Anatoly Burakov <anatoly.burakov@intel.com>,
	David Hunt <david.hunt@intel.com>,
	Sivaprasad Tummala <sivaprasad.tummala@amd.com>,
	Tadhg Kearney <tadhg.kearney@intel.com>
Subject: [PATCH 1/2] power/intel_uncore: fix crash closing uninitialized driver
Date: Thu, 15 May 2025 17:58:53 +0100	[thread overview]
Message-ID: <20250515165854.1087247-1-bruce.richardson@intel.com> (raw)

When the power_intel_uncore_autotest unit test is run as an unprivileged
user which cannot init the power library, it crashes the unit test
binary due to calling "rte_power_uncore_exit" after the first test case
(initialization) fails. This crash is due to trying to write to NULL
file handles.

Fix the crash by checking each file handle is non-null before writing to
it and closing it.

Fixes: 60b8a661a957 ("power: add Intel uncore frequency control")
Cc: stable@dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 drivers/power/intel_uncore/intel_uncore.c | 35 ++++++++++++-----------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/drivers/power/intel_uncore/intel_uncore.c b/drivers/power/intel_uncore/intel_uncore.c
index 804ad5d755..6759ea1445 100644
--- a/drivers/power/intel_uncore/intel_uncore.c
+++ b/drivers/power/intel_uncore/intel_uncore.c
@@ -307,27 +307,28 @@ power_intel_uncore_exit(unsigned int pkg, unsigned int die)
 
 	ui = &uncore_info[pkg][die];
 
-	if (fprintf(ui->f_cur_min, "%u", ui->org_min_freq) < 0) {
-		POWER_LOG(ERR, "Fail to write original uncore frequency for "
-				"pkg %02u die %02u", ui->pkg, ui->die);
-		return -1;
+	if (ui->f_cur_min != NULL) {
+		if (fprintf(ui->f_cur_min, "%u", ui->org_min_freq) < 0) {
+			POWER_LOG(ERR, "Fail to write original uncore frequency for pkg %02u die %02u",
+					 ui->pkg, ui->die);
+			return -1;
+		}
+		fflush(ui->f_cur_min);
+		fclose(ui->f_cur_min);
+		ui->f_cur_min = NULL;
 	}
 
-	if (fprintf(ui->f_cur_max, "%u", ui->org_max_freq) < 0) {
-		POWER_LOG(ERR, "Fail to write original uncore frequency for "
-				"pkg %02u die %02u", ui->pkg, ui->die);
-		return -1;
+	if (ui->f_cur_max != NULL) {
+		if (fprintf(ui->f_cur_max, "%u", ui->org_max_freq) < 0) {
+			POWER_LOG(ERR, "Fail to write original uncore frequency for pkg %02u die %02u",
+					 ui->pkg, ui->die);
+			return -1;
+		}
+		fflush(ui->f_cur_max);
+		fclose(ui->f_cur_max);
+		ui->f_cur_max = NULL;
 	}
 
-	fflush(ui->f_cur_min);
-	fflush(ui->f_cur_max);
-
-	/* Close FD of setting freq */
-	fclose(ui->f_cur_min);
-	fclose(ui->f_cur_max);
-	ui->f_cur_min = NULL;
-	ui->f_cur_max = NULL;
-
 	return 0;
 }
 
-- 
2.48.1


             reply	other threads:[~2025-05-15 16:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-15 16:58 Bruce Richardson [this message]
2025-05-15 16:58 ` [PATCH 2/2] test/power_intel_uncore: skip test if init fails Bruce Richardson

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=20250515165854.1087247-1-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=anatoly.burakov@intel.com \
    --cc=david.hunt@intel.com \
    --cc=dev@dpdk.org \
    --cc=sivaprasad.tummala@amd.com \
    --cc=stable@dpdk.org \
    --cc=tadhg.kearney@intel.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;
as well as URLs for NNTP newsgroup(s).