Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Li Zhijian and committed by
Jakub Kicinski
8d029330 1cf05e25

+6 -7
+6 -7
drivers/ptp/ptp_sysfs.c
··· 24 24 { 25 25 struct ptp_clock *ptp = dev_get_drvdata(dev); 26 26 27 - return snprintf(page, PAGE_SIZE - 1, "%d\n", 28 - ptp->info->getmaxphase(ptp->info)); 27 + return sysfs_emit(page, "%d\n", ptp->info->getmaxphase(ptp->info)); 29 28 } 30 29 static DEVICE_ATTR_RO(max_phase_adjustment); 31 30 ··· 33 34 struct device_attribute *attr, char *page) \ 34 35 { \ 35 36 struct ptp_clock *ptp = dev_get_drvdata(dev); \ 36 - return snprintf(page, PAGE_SIZE-1, "%d\n", ptp->info->var); \ 37 + return sysfs_emit(page, "%d\n", ptp->info->var); \ 37 38 } \ 38 39 static DEVICE_ATTR(name, 0444, var##_show, NULL); 39 40 ··· 101 102 if (!qcnt) 102 103 goto out; 103 104 104 - cnt = snprintf(page, PAGE_SIZE, "%u %lld %u\n", 105 - event.index, event.t.sec, event.t.nsec); 105 + cnt = sysfs_emit(page, "%u %lld %u\n", 106 + event.index, event.t.sec, event.t.nsec); 106 107 out: 107 108 return cnt; 108 109 } ··· 193 194 if (mutex_lock_interruptible(&ptp->n_vclocks_mux)) 194 195 return -ERESTARTSYS; 195 196 196 - size = snprintf(page, PAGE_SIZE - 1, "%u\n", ptp->n_vclocks); 197 + size = sysfs_emit(page, "%u\n", ptp->n_vclocks); 197 198 198 199 mutex_unlock(&ptp->n_vclocks_mux); 199 200 ··· 269 270 struct ptp_clock *ptp = dev_get_drvdata(dev); 270 271 ssize_t size; 271 272 272 - size = snprintf(page, PAGE_SIZE - 1, "%u\n", ptp->max_vclocks); 273 + size = sysfs_emit(page, "%u\n", ptp->max_vclocks); 273 274 274 275 return size; 275 276 }