Skip to contentSkip to conversation

efi: pstore: Drop efivar lock when efi_pstore_open() returns with an error

PATCH Applied Thomas Huth 2 participants 2 messages Apr 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi: pstore: Drop efivar lock when efi_pstore_open() returns with an error

From: Thomas Huth <[email protected]>

If kzalloc fails, the function returns -ENOMEM without calling efivar_unlock(). Since open() returned an error, the calling site in pstore_get_backend_records() won't call the close() function, so the lock is never released. Thus drop the lock in case of errors here.

Fixes 859748255b434 ("efi: pstore: Omit efivars caching EFI varstore access layer")
Assisted-by Claude:claude-opus-4-6
---
 drivers/firmware/efi/efi-pstore.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/firmware/efi/efi-pstore.c +3 -1
index a253b61449459..a5db3534f0a63 100644
@@ -60,8 +60,10 @@ static int efi_pstore_open(struct pstore_info *psi)
 		return err;
 
 	psi->data = kzalloc(record_size, GFP_KERNEL);
-	if (!psi->data)
+	if (!psi->data) {
+		efivar_unlock();
 		return -ENOMEM;
+	}
 
 	return 0;
 }
Signature · 1 line
2.53.0
maintainer Applied
#1 lore raw

Hi Thomas,

Quoted 7 lines · Thomas Huth

From: Thomas Huth <[email protected]>

If kzalloc fails, the function returns -ENOMEM without calling efivar_unlock(). Since open() returned an error, the calling site in pstore_get_backend_records() won't call the close() function, so the lock is never released. Thus drop the lock in case of errors here.

Quoted 8 lines
Fixes 859748255b434 ("efi: pstore: Omit efivars caching EFI varstore

access layer")

Assisted-by Claude:claude-opus-4-6
---
 drivers/firmware/efi/efi-pstore.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Queued in efi/urgent - thanks.

Quoted 19 lines
drivers/firmware/efi/efi-pstore.c +3 -1
index a253b61449459..a5db3534f0a63 100644
@@ -60,8 +60,10 @@ static int efi_pstore_open(struct pstore_info *psi)
 		return err;
 
 	psi->data = kzalloc(record_size, GFP_KERNEL);
-	if (!psi->data)
+	if (!psi->data) {
+		efivar_unlock();
 		return -ENOMEM;
+	}
 
 	return 0;
 }
Signature · 1 line
2.53.0