thunderbolt: Convert to use sysfs_emit()/sysfs_emit_at() APIs
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 22 Sep 2022 14:32:39 +0000 (17:32 +0300)
committerMika Westerberg <mika.westerberg@linux.intel.com>
Sat, 24 Sep 2022 06:22:01 +0000 (09:22 +0300)
Follow the advice of the Documentation/filesystems/sysfs.rst and show()
should only use sysfs_emit() or sysfs_emit_at() when formatting the value
to be returned to user space.

While at it, use Elvis operator in some cases.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
drivers/thunderbolt/domain.c
drivers/thunderbolt/retimer.c
drivers/thunderbolt/switch.c
drivers/thunderbolt/xdomain.c

index 99211f3..ec7b5f6 100644 (file)
@@ -144,11 +144,9 @@ static ssize_t boot_acl_show(struct device *dev, struct device_attribute *attr,
 
        for (ret = 0, i = 0; i < tb->nboot_acl; i++) {
                if (!uuid_is_null(&uuids[i]))
-                       ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%pUb",
-                                       &uuids[i]);
+                       ret += sysfs_emit_at(buf, ret, "%pUb", &uuids[i]);
 
-               ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%s",
-                              i < tb->nboot_acl - 1 ? "," : "\n");
+               ret += sysfs_emit_at(buf, ret, "%s", i < tb->nboot_acl - 1 ? "," : "\n");
        }
 
 out:
@@ -247,7 +245,7 @@ static ssize_t deauthorization_show(struct device *dev,
            tb->security_level == TB_SECURITY_SECURE)
                deauthorization = !!tb->cm_ops->disapprove_switch;
 
-       return sprintf(buf, "%d\n", deauthorization);
+       return sysfs_emit(buf, "%d\n", deauthorization);
 }
 static DEVICE_ATTR_RO(deauthorization);
 
@@ -270,7 +268,7 @@ static ssize_t security_show(struct device *dev, struct device_attribute *attr,
        if (tb->security_level < ARRAY_SIZE(tb_security_names))
                name = tb_security_names[tb->security_level];
 
-       return sprintf(buf, "%s\n", name);
+       return sysfs_emit(buf, "%s\n", name);
 }
 static DEVICE_ATTR_RO(security);
 
index dd8f033..81252e3 100644 (file)
@@ -162,7 +162,7 @@ static ssize_t device_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_retimer *rt = tb_to_retimer(dev);
 
-       return sprintf(buf, "%#x\n", rt->device);
+       return sysfs_emit(buf, "%#x\n", rt->device);
 }
 static DEVICE_ATTR_RO(device);
 
@@ -180,7 +180,7 @@ static ssize_t nvm_authenticate_show(struct device *dev,
        else if (rt->no_nvm_upgrade)
                ret = -EOPNOTSUPP;
        else
-               ret = sprintf(buf, "%#x\n", rt->auth_status);
+               ret = sysfs_emit(buf, "%#x\n", rt->auth_status);
 
        mutex_unlock(&rt->tb->lock);
 
@@ -255,7 +255,7 @@ static ssize_t nvm_version_show(struct device *dev,
        if (!rt->nvm)
                ret = -EAGAIN;
        else
-               ret = sprintf(buf, "%x.%x\n", rt->nvm->major, rt->nvm->minor);
+               ret = sysfs_emit(buf, "%x.%x\n", rt->nvm->major, rt->nvm->minor);
 
        mutex_unlock(&rt->tb->lock);
        return ret;
@@ -267,7 +267,7 @@ static ssize_t vendor_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_retimer *rt = tb_to_retimer(dev);
 
-       return sprintf(buf, "%#x\n", rt->vendor);
+       return sysfs_emit(buf, "%#x\n", rt->vendor);
 }
 static DEVICE_ATTR_RO(vendor);
 
index 2bcb675..72bc032 100644 (file)
@@ -1694,7 +1694,7 @@ static ssize_t authorized_show(struct device *dev,
 {
        struct tb_switch *sw = tb_to_switch(dev);
 
-       return sprintf(buf, "%u\n", sw->authorized);
+       return sysfs_emit(buf, "%u\n", sw->authorized);
 }
 
 static int disapprove_switch(struct device *dev, void *not_used)
@@ -1804,7 +1804,7 @@ static ssize_t boot_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_switch *sw = tb_to_switch(dev);
 
-       return sprintf(buf, "%u\n", sw->boot);
+       return sysfs_emit(buf, "%u\n", sw->boot);
 }
 static DEVICE_ATTR_RO(boot);
 
@@ -1813,7 +1813,7 @@ static ssize_t device_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_switch *sw = tb_to_switch(dev);
 
-       return sprintf(buf, "%#x\n", sw->device);
+       return sysfs_emit(buf, "%#x\n", sw->device);
 }
 static DEVICE_ATTR_RO(device);
 
@@ -1822,7 +1822,7 @@ device_name_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct tb_switch *sw = tb_to_switch(dev);
 
-       return sprintf(buf, "%s\n", sw->device_name ? sw->device_name : "");
+       return sysfs_emit(buf, "%s\n", sw->device_name ?: "");
 }
 static DEVICE_ATTR_RO(device_name);
 
@@ -1831,7 +1831,7 @@ generation_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct tb_switch *sw = tb_to_switch(dev);
 
-       return sprintf(buf, "%u\n", sw->generation);
+       return sysfs_emit(buf, "%u\n", sw->generation);
 }
 static DEVICE_ATTR_RO(generation);
 
@@ -1845,9 +1845,9 @@ static ssize_t key_show(struct device *dev, struct device_attribute *attr,
                return restart_syscall();
 
        if (sw->key)
-               ret = sprintf(buf, "%*phN\n", TB_SWITCH_KEY_SIZE, sw->key);
+               ret = sysfs_emit(buf, "%*phN\n", TB_SWITCH_KEY_SIZE, sw->key);
        else
-               ret = sprintf(buf, "\n");
+               ret = sysfs_emit(buf, "\n");
 
        mutex_unlock(&sw->tb->lock);
        return ret;
@@ -1892,7 +1892,7 @@ static ssize_t speed_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_switch *sw = tb_to_switch(dev);
 
-       return sprintf(buf, "%u.0 Gb/s\n", sw->link_speed);
+       return sysfs_emit(buf, "%u.0 Gb/s\n", sw->link_speed);
 }
 
 /*
@@ -1907,7 +1907,7 @@ static ssize_t lanes_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_switch *sw = tb_to_switch(dev);
 
-       return sprintf(buf, "%u\n", sw->link_width);
+       return sysfs_emit(buf, "%u\n", sw->link_width);
 }
 
 /*
@@ -1924,7 +1924,7 @@ static ssize_t nvm_authenticate_show(struct device *dev,
        u32 status;
 
        nvm_get_auth_status(sw, &status);
-       return sprintf(buf, "%#x\n", status);
+       return sysfs_emit(buf, "%#x\n", status);
 }
 
 static ssize_t nvm_authenticate_sysfs(struct device *dev, const char *buf,
@@ -2033,7 +2033,7 @@ static ssize_t nvm_version_show(struct device *dev,
        else if (!sw->nvm)
                ret = -EAGAIN;
        else
-               ret = sprintf(buf, "%x.%x\n", sw->nvm->major, sw->nvm->minor);
+               ret = sysfs_emit(buf, "%x.%x\n", sw->nvm->major, sw->nvm->minor);
 
        mutex_unlock(&sw->tb->lock);
 
@@ -2046,7 +2046,7 @@ static ssize_t vendor_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_switch *sw = tb_to_switch(dev);
 
-       return sprintf(buf, "%#x\n", sw->vendor);
+       return sysfs_emit(buf, "%#x\n", sw->vendor);
 }
 static DEVICE_ATTR_RO(vendor);
 
@@ -2055,7 +2055,7 @@ vendor_name_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct tb_switch *sw = tb_to_switch(dev);
 
-       return sprintf(buf, "%s\n", sw->vendor_name ? sw->vendor_name : "");
+       return sysfs_emit(buf, "%s\n", sw->vendor_name ?: "");
 }
 static DEVICE_ATTR_RO(vendor_name);
 
@@ -2064,7 +2064,7 @@ static ssize_t unique_id_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_switch *sw = tb_to_switch(dev);
 
-       return sprintf(buf, "%pUb\n", sw->uuid);
+       return sysfs_emit(buf, "%pUb\n", sw->uuid);
 }
 static DEVICE_ATTR_RO(unique_id);
 
index dcee91f..bbb248a 100644 (file)
@@ -877,7 +877,7 @@ static ssize_t key_show(struct device *dev, struct device_attribute *attr,
         * It should be null terminated but anything else is pretty much
         * allowed.
         */
-       return sprintf(buf, "%*pE\n", (int)strlen(svc->key), svc->key);
+       return sysfs_emit(buf, "%*pE\n", (int)strlen(svc->key), svc->key);
 }
 static DEVICE_ATTR_RO(key);
 
@@ -903,7 +903,7 @@ static ssize_t prtcid_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_service *svc = container_of(dev, struct tb_service, dev);
 
-       return sprintf(buf, "%u\n", svc->prtcid);
+       return sysfs_emit(buf, "%u\n", svc->prtcid);
 }
 static DEVICE_ATTR_RO(prtcid);
 
@@ -912,7 +912,7 @@ static ssize_t prtcvers_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_service *svc = container_of(dev, struct tb_service, dev);
 
-       return sprintf(buf, "%u\n", svc->prtcvers);
+       return sysfs_emit(buf, "%u\n", svc->prtcvers);
 }
 static DEVICE_ATTR_RO(prtcvers);
 
@@ -921,7 +921,7 @@ static ssize_t prtcrevs_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_service *svc = container_of(dev, struct tb_service, dev);
 
-       return sprintf(buf, "%u\n", svc->prtcrevs);
+       return sysfs_emit(buf, "%u\n", svc->prtcrevs);
 }
 static DEVICE_ATTR_RO(prtcrevs);
 
@@ -930,7 +930,7 @@ static ssize_t prtcstns_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_service *svc = container_of(dev, struct tb_service, dev);
 
-       return sprintf(buf, "0x%08x\n", svc->prtcstns);
+       return sysfs_emit(buf, "0x%08x\n", svc->prtcstns);
 }
 static DEVICE_ATTR_RO(prtcstns);
 
@@ -1661,7 +1661,7 @@ static ssize_t device_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
 
-       return sprintf(buf, "%#x\n", xd->device);
+       return sysfs_emit(buf, "%#x\n", xd->device);
 }
 static DEVICE_ATTR_RO(device);
 
@@ -1673,7 +1673,7 @@ device_name_show(struct device *dev, struct device_attribute *attr, char *buf)
 
        if (mutex_lock_interruptible(&xd->lock))
                return -ERESTARTSYS;
-       ret = sprintf(buf, "%s\n", xd->device_name ? xd->device_name : "");
+       ret = sysfs_emit(buf, "%s\n", xd->device_name ?: "");
        mutex_unlock(&xd->lock);
 
        return ret;
@@ -1685,7 +1685,7 @@ static ssize_t maxhopid_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
 
-       return sprintf(buf, "%d\n", xd->remote_max_hopid);
+       return sysfs_emit(buf, "%d\n", xd->remote_max_hopid);
 }
 static DEVICE_ATTR_RO(maxhopid);
 
@@ -1694,7 +1694,7 @@ static ssize_t vendor_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
 
-       return sprintf(buf, "%#x\n", xd->vendor);
+       return sysfs_emit(buf, "%#x\n", xd->vendor);
 }
 static DEVICE_ATTR_RO(vendor);
 
@@ -1706,7 +1706,7 @@ vendor_name_show(struct device *dev, struct device_attribute *attr, char *buf)
 
        if (mutex_lock_interruptible(&xd->lock))
                return -ERESTARTSYS;
-       ret = sprintf(buf, "%s\n", xd->vendor_name ? xd->vendor_name : "");
+       ret = sysfs_emit(buf, "%s\n", xd->vendor_name ?: "");
        mutex_unlock(&xd->lock);
 
        return ret;
@@ -1718,7 +1718,7 @@ static ssize_t unique_id_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
 
-       return sprintf(buf, "%pUb\n", xd->remote_uuid);
+       return sysfs_emit(buf, "%pUb\n", xd->remote_uuid);
 }
 static DEVICE_ATTR_RO(unique_id);
 
@@ -1727,7 +1727,7 @@ static ssize_t speed_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
 
-       return sprintf(buf, "%u.0 Gb/s\n", xd->link_speed);
+       return sysfs_emit(buf, "%u.0 Gb/s\n", xd->link_speed);
 }
 
 static DEVICE_ATTR(rx_speed, 0444, speed_show, NULL);
@@ -1738,7 +1738,7 @@ static ssize_t lanes_show(struct device *dev, struct device_attribute *attr,
 {
        struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
 
-       return sprintf(buf, "%u\n", xd->link_width);
+       return sysfs_emit(buf, "%u\n", xd->link_width);
 }
 
 static DEVICE_ATTR(rx_lanes, 0444, lanes_show, NULL);