Skip to contentSkip to conversation

thunderbolt: Don't display nvm_version unless upgrade supported

PATCH Applied Mario Limonciello 2 participants 2 messages Dec 9, 2024 – Dec 11, 2024

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

PATCH v2 1/1 thunderbolt: Don't display nvm_version unless upgrade supported

From: Mario Limonciello <[email protected]>

The read will never succeed if nvm wasn't initialized due to an unknown format.

Add a new callback for visibility to only show when supported.

Fixes aef9c693e7e5 ("thunderbolt: Move vendor specific NVM handling into nvm.c")

---
v2:
* Use no_nvm_upgrade instead of changing logic
* Adjust commit message

---
 drivers/thunderbolt/retimer.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/thunderbolt/retimer.c +15 -4
index 89d2919d0193e..eeb64433ebbca 100644
@@ -103,6 +103,7 @@ static int tb_retimer_nvm_add(struct tb_retimer *rt)
 
 err_nvm:
 	dev_dbg(&rt->dev, "NVM upgrade disabled\n");
+	rt->no_nvm_upgrade = true;
 	if (!IS_ERR(nvm))
 		tb_nvm_free(nvm);
 
@@ -182,8 +183,6 @@ static ssize_t nvm_authenticate_show(struct device *dev,
 
 	if (!rt->nvm)
 		ret = -EAGAIN;
-	else if (rt->no_nvm_upgrade)
-		ret = -EOPNOTSUPP;
 	else
 		ret = sysfs_emit(buf, "%#x\n", rt->auth_status);
 
@@ -323,8 +322,6 @@ static ssize_t nvm_version_show(struct device *dev,
 
 	if (!rt->nvm)
 		ret = -EAGAIN;
-	else if (rt->no_nvm_upgrade)
-		ret = -EOPNOTSUPP;
 	else
 		ret = sysfs_emit(buf, "%x.%x\n", rt->nvm->major, rt->nvm->minor);
 
@@ -342,6 +339,19 @@ static ssize_t vendor_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(vendor);
 
+static umode_t retimer_is_visible(struct kobject *kobj, struct attribute *attr,
+				  int n)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	struct tb_retimer *rt = tb_to_retimer(dev);
+
+	if (attr == &dev_attr_nvm_authenticate.attr ||
+	    attr == &dev_attr_nvm_version.attr)
+		return rt->no_nvm_upgrade ? 0 : attr->mode;
+
+	return attr->mode;
+}
+
 static struct attribute *retimer_attrs[] = {
 	&dev_attr_device.attr,
 	&dev_attr_nvm_authenticate.attr,
@@ -351,6 +361,7 @@ static struct attribute *retimer_attrs[] = {
 };
 
 static const struct attribute_group retimer_group = {
+	.is_visible = retimer_is_visible,
 	.attrs = retimer_attrs,
 };
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 11 lines · Mario Limonciello

From: Mario Limonciello <[email protected]>

The read will never succeed if nvm wasn't initialized due to an unknown format.

Add a new callback for visibility to only show when supported.

Fixes aef9c693e7e5 ("thunderbolt: Move vendor specific NVM handling into nvm.c")

Applied to thunderbolt.git/fixes, thanks Mario!