Skip to contentSkip to conversation

pstore: gracefully handle NULL pstore_info functions

PATCH New Kees Cook 1 participant 1 message Nov 17, 2011 Pstore filesystem

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH v2 1/1 pstore: gracefully handle NULL pstore_info functions

If a pstore backend doesn't want to support various portions of the pstore interface, it can just leave those functions NULL instead of creating no-op stubs.

---
 fs/pstore/inode.c    |    3 ++-
 fs/pstore/platform.c |    8 ++++----
 2 files changed, 6 insertions(+), 5 deletions(-)
fs/pstore/inode.c +2 -1
index 379a02d..b3b426e 100644
@@ -80,7 +80,8 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
 {
 	struct pstore_private *p = dentry->d_inode->i_private;
 
-	p->psi->erase(p->type, p->id, p->psi);
+	if (p->psi->erase)
+		p->psi->erase(p->type, p->id, p->psi);
 
 	return simple_unlink(dir, dentry);
 }
fs/pstore/platform.c +4 -4
index f146d89..c970a66 100644
@@ -203,12 +203,11 @@ void pstore_get_records(int quiet)
 	struct timespec		time;
 	int			failed = 0, rc;
 
-	if (!psi)
+	if (!psi || !psi->read)
 		return;
 
 	mutex_lock(&psi->read_mutex);
-	rc = psi->open(psi);
-	if (rc)
+	if (psi->open && psi->open(psi))
 		goto out;
 
 	while ((size = psi->read(&id, &type, &time, &buf, psi)) > 0) {
@@ -219,7 +218,8 @@ void pstore_get_records(int quiet)
 		if (rc && (rc != -EEXIST || !quiet))
 			failed++;
 	}
-	psi->close(psi);
+	if (psi->close)
+		psi->close(psi);
 out:
 	mutex_unlock(&psi->read_mutex);
 
Signature · 1 line
1.7.0.4