drivers/ptp: Convert snprintf to sysfs_emit

Per filesystems/sysfs.rst, show() should only use sysfs_emit()
or sysfs_emit_at() when formatting the value to be returned to user space.

coccinelle complains that there are still a couple of functions that use
snprintf(). Convert them to sysfs_emit().

> ./drivers/ptp/ptp_sysfs.c:27:8-16: WARNING: please use sysfs_emit

No functional change intended

Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Link: https://lore.kernel.org/r/20240125015329.123023-1-lizhijian@fujitsu.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Li Zhijian 2024-01-25 09:53:29 +08:00 committed by Jakub Kicinski
parent 1cf05e2508
commit 8d0293302d

View File

@ -24,8 +24,7 @@ static ssize_t max_phase_adjustment_show(struct device *dev,
{ {
struct ptp_clock *ptp = dev_get_drvdata(dev); struct ptp_clock *ptp = dev_get_drvdata(dev);
return snprintf(page, PAGE_SIZE - 1, "%d\n", return sysfs_emit(page, "%d\n", ptp->info->getmaxphase(ptp->info));
ptp->info->getmaxphase(ptp->info));
} }
static DEVICE_ATTR_RO(max_phase_adjustment); static DEVICE_ATTR_RO(max_phase_adjustment);
@ -34,7 +33,7 @@ static ssize_t var##_show(struct device *dev, \
struct device_attribute *attr, char *page) \ struct device_attribute *attr, char *page) \
{ \ { \
struct ptp_clock *ptp = dev_get_drvdata(dev); \ struct ptp_clock *ptp = dev_get_drvdata(dev); \
return snprintf(page, PAGE_SIZE-1, "%d\n", ptp->info->var); \ return sysfs_emit(page, "%d\n", ptp->info->var); \
} \ } \
static DEVICE_ATTR(name, 0444, var##_show, NULL); static DEVICE_ATTR(name, 0444, var##_show, NULL);
@ -102,7 +101,7 @@ static ssize_t extts_fifo_show(struct device *dev,
if (!qcnt) if (!qcnt)
goto out; goto out;
cnt = snprintf(page, PAGE_SIZE, "%u %lld %u\n", cnt = sysfs_emit(page, "%u %lld %u\n",
event.index, event.t.sec, event.t.nsec); event.index, event.t.sec, event.t.nsec);
out: out:
return cnt; return cnt;
@ -194,7 +193,7 @@ static ssize_t n_vclocks_show(struct device *dev,
if (mutex_lock_interruptible(&ptp->n_vclocks_mux)) if (mutex_lock_interruptible(&ptp->n_vclocks_mux))
return -ERESTARTSYS; return -ERESTARTSYS;
size = snprintf(page, PAGE_SIZE - 1, "%u\n", ptp->n_vclocks); size = sysfs_emit(page, "%u\n", ptp->n_vclocks);
mutex_unlock(&ptp->n_vclocks_mux); mutex_unlock(&ptp->n_vclocks_mux);
@ -270,7 +269,7 @@ static ssize_t max_vclocks_show(struct device *dev,
struct ptp_clock *ptp = dev_get_drvdata(dev); struct ptp_clock *ptp = dev_get_drvdata(dev);
ssize_t size; ssize_t size;
size = snprintf(page, PAGE_SIZE - 1, "%u\n", ptp->max_vclocks); size = sysfs_emit(page, "%u\n", ptp->max_vclocks);
return size; return size;
} }