nvmet: replace sysfs_emit() with sprintf() in configfs show attrs
Subsystems (2)
PATCH 1/1 nvmet: replace sysfs_emit() with sprintf() in configfs show attrs
sysfs_emit() is designed for sysfs attributes and internally checks that the buffer is page-aligned. Although configfs currently happens to use a page-aligned buffer allocated via kzalloc(PAGE_SIZE), using sysfs_emit() in configfs show callbacks is a semantic misuse of the API. Replace with sprintf() to match the convention used by all other configfs show functions in these files.
--- drivers/nvme/target/configfs.c | 6 +++--- drivers/nvme/target/pci-epf.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/nvme/target/configfs.c +3 -3
@@ -798,7 +798,7 @@ CONFIGFS_ATTR_WO(nvmet_ns_, revalidate_size);static ssize_t nvmet_ns_resv_enable_show (struct config_item *item,char *page) { -return sysfs_emit (page,"%d\n" ,to_nvmet_ns (item)->pr.enable); +return sprintf (page,"%d\n" ,to_nvmet_ns (item)->pr.enable); } static ssize_t nvmet_ns_resv_enable_store(struct config_item *item,
@@ -1534,7 +1534,7 @@ static ssize_t nvmet_subsys_attr_ieee_oui_show(struct config_item *item, {struct nvmet_subsys *subsys =to_subsys (item); -return sysfs_emit (page,"0x%06x\n" , subsys->ieee_oui); +return sprintf (page,"0x%06x\n" , subsys->ieee_oui); } static ssize_t nvmet_subsys_attr_ieee_oui_store_locked(struct nvmet_subsys *subsys,
@@ -1582,7 +1582,7 @@ static ssize_t nvmet_subsys_attr_firmware_show(struct config_item *item, {struct nvmet_subsys *subsys =to_subsys (item); -return sysfs_emit (page,"%s\n" , subsys->firmware_rev); +return sprintf (page,"%s\n" , subsys->firmware_rev); } static ssize_t nvmet_subsys_attr_firmware_store_locked(struct nvmet_subsys *subsys,
drivers/nvme/target/pci-epf.c +3 -3
@@ -2482,7 +2482,7 @@ static ssize_t nvmet_pci_epf_portid_show(struct config_item *item, char *page)struct config_group *group =to_config_group (item);struct nvmet_pci_epf *nvme_epf =to_nvme_epf (group); -return sysfs_emit (page,"%u\n" ,le16_to_cpu (nvme_epf->portid)); +return sprintf (page,"%u\n" ,le16_to_cpu (nvme_epf->portid)); } static ssize_t nvmet_pci_epf_portid_store(struct config_item *item,
@@ -2515,7 +2515,7 @@ static ssize_t nvmet_pci_epf_subsysnqn_show(struct config_item *item,struct config_group *group =to_config_group (item);struct nvmet_pci_epf *nvme_epf =to_nvme_epf (group); -return sysfs_emit (page,"%s\n" , nvme_epf->subsysnqn); +return sprintf (page,"%s\n" , nvme_epf->subsysnqn); } static ssize_t nvmet_pci_epf_subsysnqn_store(struct config_item *item,
@@ -2543,7 +2543,7 @@ static ssize_t nvmet_pci_epf_mdts_kb_show(struct config_item *item, char *page)struct config_group *group =to_config_group (item);struct nvmet_pci_epf *nvme_epf =to_nvme_epf (group); -return sysfs_emit (page,"%u\n" , nvme_epf->mdts_kb); +return sprintf (page,"%u\n" , nvme_epf->mdts_kb); } static ssize_t nvmet_pci_epf_mdts_kb_store(struct config_item *item,
Signature · 1 line
2.43.7
Christoph Hellwig
maintainerAdding Greg to see if he agrees.
But if we add churn to change this, we should probably switch to using seq_file for memory safety, and have some generic configfs-level infrastruture for that.
Quoted 2 lines · Christoph Hellwig
Adding Greg to see if he agrees.
Ick, no, sysfs_emit() should be just fine, and safe, for configfs to use, please don't do conversions away from it.
Quoted 3 lines
But if we add churn to change this, we should probably switch to using
seq_filefor memory safety, and have some generic configfs-level infrastruture for that.
seq_file() would also be great, but really, sysfs_emit() should be all that you need to use here as you should only have one-value-per-file with no overflows possible anyway.
thanks,
greg k-h
Quoted 8 lines · Greg Kroah-Hartman
Quoted 1 line · Christoph Hellwig
Adding Greg to see if he agrees.
Ick, no,
sysfs_emit()should be just fine, and safe, for configfs to use, please don't do conversions away from it.Quoted 3 lines
But if we add churn to change this, we should probably switch to using
seq_filefor memory safety, and have some generic configfs-level infrastruture for that.
Quoted 7 lines
seq_file()would also be great, but really,sysfs_emit()should be all that you need to use here as you should only have one-value-per-file with no overflows possible anyway.thanks,
greg k-h
Got it.
Best Regards,
Guixin Liu