Skip to contentSkip to conversation

nvme: fix bogus kzalloc() return check in nvme_init_effects_log()

PATCH In review Jens Axboe 5 participants 6 messages Jan 13, 2025 NVMe

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 nvme: fix bogus kzalloc() return check in nvme_init_effects_log()

nvme_init_effects_log() returns failure when kzalloc() is successful, which is obviously wrong and causes failures to boot. Correct the check.

Fixes d4a95adeabc6 ("nvme: Add error path for xa_store in nvme_init_effects")

---

Caused a boot failure on the first test system I tried. Not sure how this got this far without being seen...

drivers/nvme/host/core.c +1 -1
index 9e7f1bb81973..0d21258e2283 100644
@@ -3182,7 +3182,7 @@ static int nvme_init_effects_log(struct nvme_ctrl *ctrl,
 	struct nvme_effects_log *effects, *old;
 
 	effects = kzalloc(sizeof(*effects), GFP_KERNEL);
-	if (effects)
+	if (!effects)
 		return -ENOMEM;
 
 	old = xa_store(&ctrl->cels, csi, effects, GFP_KERNEL);
Signature · 1 line
Jens Axboe
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jens Axboe

nvme_init_effects_log() returns failure when kzalloc() is successful, which is obviously wrong and causes failures to boot. Correct the check.

Fixes d4a95adeabc6 ("nvme: Add error path for xa_store in nvme_init_effects")

Oops. Thanks for the fix

Also applied to nvme-6.14, but feel free to take it directly to block/for-6.14.

Quoted 2 lines

Caused a boot failure on the first test system I tried. Not sure how this got this far without being seen...

I think we've a gap in our blktests for checking driver backward compatibility. The devices we test against support the Effects log, so we didn't see this fallback path for older spec revision devices tested out.

author maintainer
#2 lore raw
Quoted 8 lines · Keith Busch
Quoted 6 lines · Jens Axboe

nvme_init_effects_log() returns failure when kzalloc() is successful, which is obviously wrong and causes failures to boot. Correct the check.

Fixes d4a95adeabc6 ("nvme: Add error path for xa_store in nvme_init_effects")
Quoted 6 lines

Oops. Thanks for the fix

Also applied to nvme-6.14, but feel free to take it directly to block/for-6.14.

I did, figured that was easier. And if it fails on the one test system I tested on, guessing it'd break someone using linux-next as well. Hence let's just shove it in and move on.

Signature · 1 line
Jens Axboe
#3 lore raw
In reply to Jens Axboe
Quoted 3 lines · Jens Axboe

nvme_init_effects_log() returns failure when kzalloc() is successful, which is obviously wrong and causes failures to boot. Correct the check.

Sorry, I should have checked more carefully here... Thank you for this fix.

Keisuke

Quoted 23 lines
Fixes d4a95adeabc6 ("nvme: Add error path for xa_store in nvme_init_effects")

---

Caused a boot failure on the first test system I tried. Not sure how this got this far without being seen...

drivers/nvme/host/core.c +1 -1
index 9e7f1bb81973..0d21258e2283 100644
@@ -3182,7 +3182,7 @@ static int nvme_init_effects_log(struct nvme_ctrl *ctrl,
  	struct nvme_effects_log *effects, *old;
 
  	effects = kzalloc(sizeof(*effects), GFP_KERNEL);
-	if (effects)
+	if (!effects)
  		return -ENOMEM;
 
  	old = xa_store(&ctrl->cels, csi, effects, GFP_KERNEL);