Add conflict resolution for tpm-virtio branch for v5.18-rc2

Signed-off-by: Łukasz Bartosik <ukaszb@google.com>
diff --git a/603654946ebe99b16c1c05b4e546c3373b6c73b115580e69e58b3954.patch b/603654946ebe99b16c1c05b4e546c3373b6c73b115580e69e58b3954.patch
new file mode 100644
index 0000000..edb368b
--- /dev/null
+++ b/603654946ebe99b16c1c05b4e546c3373b6c73b115580e69e58b3954.patch
@@ -0,0 +1,121 @@
+From f68ef175da77be8eb2709afbe7ff60d8e555794e Mon Sep 17 00:00:00 2001
+From: Zyta Szpak <zyta@google.com>
+Date: Mon, 13 Dec 2021 11:48:52 +0000
+Subject: [PATCH] FIXUP: CHROMIUM: tpm: remove hardcoded index
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Remove the WARN_ON groups_cnt being zero.
+
+When the warning was added it was assumed that sysfs attributes
+always land in 0-index and the for-loop in tpm_add_legacy_sysfs had it
+hardcoded to 0. To be compliant with this it had to be checked if we are
+starting from 0 when adding groups in tpm-sysfs.c, otherwise it was
+missing the right place in the table.
+
+Add checking if attributes group name was defined for each group in
+the table.
+
+If name is defined then the sysfs entries land in 'name' subdirectory.
+This case is handled separately for each dir (like ppi). If name is not
+defined, we create legacy sysfs entry for every attribute of this group.
+
+Fixes: WARNING: CPU: 2 PID: 1 at
+drivers/char/tpm/tpm-sysfs.c:612 tpm_sysfs_add_device+0x426/0x4c7
+and improper legacy sysfs mapping (missing entries)
+
+BUG=b:197836367
+TEST=build kernel from chromeos-kernelupstream-5.14-rc7 branch with debug
+options enabled for delbin/caroline; load the kernel and observe warnings
+during boot
+
+Signed-off-by: Zyta Szpak <zyta@google.com>
+Change-Id: I3676f407a0fcc168a880f083e0b91ac2c74bb2c6
+Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/3329890
+Reviewed-by: Yi Chou <yich@google.com>
+Commit-Queue: Yi Chou <yich@google.com>
+Commit-Queue: Łukasz Bartosik <ukaszb@google.com>
+---
+ drivers/char/tpm/tpm-chip.c  | 30 ++++++++++++++++++++++--------
+ drivers/char/tpm/tpm-sysfs.c |  2 --
+ 2 files changed, 22 insertions(+), 10 deletions(-)
+
+diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
+index 968cf0ab6638..e37ff7d32d16 100644
+--- a/drivers/char/tpm/tpm-chip.c
++++ b/drivers/char/tpm/tpm-chip.c
+@@ -465,6 +465,7 @@ static void tpm_del_char_device(struct tpm_chip *chip)
+ static void tpm_del_legacy_sysfs(struct tpm_chip *chip)
+ {
+ 	struct attribute **i;
++	int k;
+ 
+ 	if (chip->flags & TPM_CHIP_FLAG_VIRTUAL ||
+ 		tpm_is_firmware_upgrade(chip))
+@@ -472,8 +473,14 @@ static void tpm_del_legacy_sysfs(struct tpm_chip *chip)
+ 
+ 	sysfs_remove_link(&chip->dev.parent->kobj, "ppi");
+ 
+-	for (i = chip->groups[0]->attrs; *i != NULL; ++i)
+-		sysfs_remove_link(&chip->dev.parent->kobj, (*i)->name);
++	for (k = 0; k < chip->groups_cnt; k++) {
++		if (chip->groups[k]->name)
++			continue;
++		else {
++			for (i = chip->groups[k]->attrs; *i != NULL; ++i)
++				sysfs_remove_link(&chip->dev.parent->kobj, (*i)->name);
++		}
++	}
+ }
+ 
+ /* For compatibility with legacy sysfs paths we provide symlinks from the
+@@ -484,6 +491,7 @@ static int tpm_add_legacy_sysfs(struct tpm_chip *chip)
+ {
+ 	struct attribute **i;
+ 	int rc;
++	int k;
+ 
+ 	if (chip->flags & TPM_CHIP_FLAG_VIRTUAL ||
+ 		tpm_is_firmware_upgrade(chip))
+@@ -495,12 +503,18 @@ static int tpm_add_legacy_sysfs(struct tpm_chip *chip)
+ 		return rc;
+ 
+ 	/* All the names from tpm-sysfs */
+-	for (i = chip->groups[0]->attrs; *i != NULL; ++i) {
+-		rc = compat_only_sysfs_link_entry_to_kobj(
+-		    &chip->dev.parent->kobj, &chip->dev.kobj, (*i)->name, NULL);
+-		if (rc) {
+-			tpm_del_legacy_sysfs(chip);
+-			return rc;
++	for (k = 0; k < chip->groups_cnt; k++) {
++		if (chip->groups[k]->name)
++			continue;
++		else {
++			for (i = chip->groups[k]->attrs; *i != NULL; ++i) {
++				rc = compat_only_sysfs_link_entry_to_kobj(
++					&chip->dev.parent->kobj, &chip->dev.kobj, (*i)->name, NULL);
++				if (rc) {
++					tpm_del_legacy_sysfs(chip);
++					return rc;
++				}
++			}
+ 		}
+ 	}
+ 
+diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
+index 0116f46d1977..4781bd2f4fde 100644
+--- a/drivers/char/tpm/tpm-sysfs.c
++++ b/drivers/char/tpm/tpm-sysfs.c
+@@ -609,8 +609,6 @@ void tpm_sysfs_add_device(struct tpm_chip *chip)
+ 	/* FIXME: update tpm_sysfs to explicitly lock chip->ops for TPM 2.0 */
+ 	int i;
+ 
+-	WARN_ON(chip->groups_cnt != 0);
+-
+ 	if (tpm_is_firmware_upgrade(chip))
+ 		return;
+ 
+-- 
+2.36.0.rc0.470.gd361397f0d-goog
+