Linux Power Management development
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Dan Carpenter <dan.carpenter@linaro.org>,
	Krzysztof Kozlowski <krzk@kernel.org>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: [PATCH] power: sequencing: fix NULL-pointer dereference in error path
Date: Fri, 12 Jul 2024 16:45:46 +0200	[thread overview]
Message-ID: <20240712144546.222119-1-brgl@bgdev.pl> (raw)

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

We may call pwrseq_target_free() on a target without the final unit
assigned yet. In this case pwrseq_unit_put() will dereference
a NULL-pointer. Add a check to the latter function.

Fixes: 249ebf3f65f8 ("power: sequencing: implement the pwrseq core")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/linux-pm/62a3531e-9927-40f8-b587-254a2dfa47ef@stanley.mountain/
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/power/sequencing/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/power/sequencing/core.c b/drivers/power/sequencing/core.c
index 9c32b07a55e7..fe07100e4b33 100644
--- a/drivers/power/sequencing/core.c
+++ b/drivers/power/sequencing/core.c
@@ -119,7 +119,8 @@ static void pwrseq_unit_release(struct kref *ref);
 
 static void pwrseq_unit_put(struct pwrseq_unit *unit)
 {
-	kref_put(&unit->ref, pwrseq_unit_release);
+	if (unit)
+		kref_put(&unit->ref, pwrseq_unit_release);
 }
 
 /**
-- 
2.43.0


             reply	other threads:[~2024-07-12 14:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-12 14:45 Bartosz Golaszewski [this message]
2024-07-12 14:59 ` [PATCH] power: sequencing: fix NULL-pointer dereference in error path Dan Carpenter
2024-07-12 15:02   ` Bartosz Golaszewski
2024-07-12 15:24     ` Dan Carpenter
2024-07-12 18:23       ` Bartosz Golaszewski

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=20240712144546.222119-1-brgl@bgdev.pl \
    --to=brgl@bgdev.pl \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=dan.carpenter@linaro.org \
    --cc=krzk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    /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