diff
+static int handle_null_error(const char *msg) {
+	pr_err("remove_device_files: %s\n", msg);
+	return -EINVAL;
+}
+
 static int remove_device_files(struct super_block *sb,
 			       struct qib_devdata *dd)
 {
 	struct dentry *dir;
 	char unit[10];
 
 	snprintf(unit, sizeof(unit), "%u", dd->unit);
+	if (sb == NULL) {
+		return handle_null_error("NULL super_block");
+	}
+	if (sb->s_root == NULL) {
+		return handle_null_error("NULL s_root in super_block");
+	}
 	dir = lookup_one_len_unlocked(unit, sb->s_root, strlen(unit));
