thunderbolt: Convert to use sysfs_emit()/sysfs_emit_at() APIs
Subsystems (2)
PATCH 1/2 thunderbolt: Convert to use sysfs_emit()/sysfs_emit_at() APIs
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.
--- drivers/thunderbolt/domain.c | 10 ++++------ drivers/thunderbolt/retimer.c | 8 ++++---- drivers/thunderbolt/switch.c | 28 ++++++++++++++-------------- drivers/thunderbolt/xdomain.c | 26 +++++++++++++------------- 4 files changed, 35 insertions(+), 37 deletions(-)
drivers/thunderbolt/domain.c +4 -6
@@ -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);
drivers/thunderbolt/retimer.c +4 -4
@@ -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);
drivers/thunderbolt/switch.c +14 -14
@@ -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);
drivers/thunderbolt/xdomain.c +13 -13
@@ -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);
Signature · 1 line
2.35.1
PATCH 2/2 thunderbolt: Use dev_err_probe()
Unify error message format by using dev_err_probe(). While at it, use temporary variable for device in the rest of the messaging calls.
--- drivers/thunderbolt/nhi.c | 48 +++++++++++++++------------------------ 1 file changed, 18 insertions(+), 30 deletions(-)
drivers/thunderbolt/nhi.c +18 -30
@@ -1184,6 +1184,7 @@ static void nhi_check_iommu(struct tb_nhi *nhi)static int nhi_init_msi (struct tb_nhi *nhi) {struct pci_dev *pdev = nhi->pdev; +struct device *dev = &pdev->dev;int res, irq, nvec;/* In case someone left them on. */
@@ -1214,10 +1215,8 @@ static int nhi_init_msi(struct tb_nhi *nhi) res =devm_request_irq (&pdev->dev, irq, nhi_msi,IRQF_NO_SUSPEND ,"thunderbolt" , nhi); -if (res) { -dev_err (&pdev->dev,"request_irq failed, aborting\n" ); -return res; - } +if (res) +return dev_err_probe (dev, res,"request_irq failed, aborting\n" ); }return 0 ;
@@ -1258,26 +1257,21 @@ static struct tb *nhi_select_cm(struct tb_nhi *nhi)static int nhi_probe (struct pci_dev *pdev,const struct pci_device_id *id) { +struct device *dev = &pdev->dev;struct tb_nhi *nhi;struct tb *tb;int res; -if (!nhi_imr_valid (pdev)) { -dev_warn (&pdev->dev,"firmware image not valid, aborting\n" ); -return -ENODEV ; - } +if (!nhi_imr_valid (pdev)) +return dev_err_probe (dev, -ENODEV ,"firmware image not valid, aborting\n" ); res =pcim_enable_device (pdev); -if (res) { -dev_err (&pdev->dev,"cannot enable PCI device, aborting\n" ); -return res; - } +if (res) +return dev_err_probe (dev, res,"cannot enable PCI device, aborting\n" ); res =pcim_iomap_regions (pdev,1 <<0 ,"thunderbolt" ); -if (res) { -dev_err (&pdev->dev,"cannot obtain PCI resources, aborting\n" ); -return res; - } +if (res) +return dev_err_probe (dev, res,"cannot obtain PCI resources, aborting\n" ); nhi =devm_kzalloc (&pdev->dev,sizeof (*nhi),GFP_KERNEL );if (!nhi)
@@ -1288,7 +1282,7 @@ static int nhi_probe(struct pci_dev *pdev, const struct pci_device_id *id)/* cannot fail - table is allocated in pcim_iomap_regions */ nhi->iobase =pcim_iomap_table (pdev)[0 ]; nhi->hop_count =ioread32 (nhi->iobase +REG_HOP_COUNT ) &0x3ff ; -dev_dbg (&pdev->dev,"total paths: %d\n" , nhi->hop_count); +dev_dbg (dev,"total paths: %d\n" , nhi->hop_count); nhi->tx_rings =devm_kcalloc (&pdev->dev, nhi->hop_count,sizeof (*nhi->tx_rings),GFP_KERNEL );
@@ -1301,18 +1295,14 @@ static int nhi_probe(struct pci_dev *pdev, const struct pci_device_id *id)nhi_check_iommu (nhi); res =nhi_init_msi (nhi); -if (res) { -dev_err (&pdev->dev,"cannot enable MSI, aborting\n" ); -return res; - } +if (res) +return dev_err_probe (dev, res,"cannot enable MSI, aborting\n" );spin_lock_init (&nhi->lock); res =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 )); -if (res) { -dev_err (&pdev->dev,"failed to set DMA mask\n" ); -return res; - } +if (res) +return dev_err_probe (dev, res,"failed to set DMA mask\n" );pci_set_master (pdev);
@@ -1323,13 +1313,11 @@ static int nhi_probe(struct pci_dev *pdev, const struct pci_device_id *id) } tb =nhi_select_cm (nhi); -if (!tb) { -dev_err (&nhi->pdev->dev, +if (!tb) +return dev_err_probe (dev, -ENODEV ,"failed to determine connection manager, aborting\n" ); -return -ENODEV ; - } -dev_dbg (&nhi->pdev->dev,"NHI initialized, starting thunderbolt\n" ); +dev_dbg (dev,"NHI initialized, starting thunderbolt\n" ); res =tb_domain_add (tb);if (res) {
Signature · 1 line
2.35.1
Quoted 7 lines · Andy Shevchenko
Follow the advice of the
Documentation/filesystems/sysfs.rstandshow()should only usesysfs_emit()orsysfs_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 <[email protected]>
This and the following patch applied to thunderbolt.git/next. Thanks Andy!