Skip to contentSkip to conversation

media: ccs: replace snprintf in show functions with sysfs_emit

PATCH In review Qing Wang 2 participants 2 messages Oct 15, 2021

Subsystems (2)
lore
Share & tools
lore

Qing Wang

author
#0 lore raw

PATCH 1/1 media: ccs: replace snprintf in show functions with sysfs_emit

show() must not use snprintf() when formatting the value to be returned to user space.

Fix the following coccicheck warning:
drivers/media/i2c/ccs/ccs-core.c:2717: WARNING: use scnprintf or sprintf.

Use sysfs_emit instead of scnprintf or sprintf makes more sense.

---
 drivers/media/i2c/ccs/ccs-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +2 -2
index a9403a2..21a156d 100644
@@ -2715,11 +2715,11 @@ ccs_sysfs_ident_read(struct device *dev, struct device_attribute *attr,
 	struct ccs_module_info *minfo = &sensor->minfo;
 
 	if (minfo->mipi_manufacturer_id)
-		return snprintf(buf, PAGE_SIZE, "%4.4x%4.4x%2.2x\n",
+		return sysfs_emit(buf, "%4.4x%4.4x%2.2x\n",
 				minfo->mipi_manufacturer_id, minfo->model_id,
 				minfo->revision_number) + 1;
 	else
-		return snprintf(buf, PAGE_SIZE, "%2.2x%4.4x%2.2x\n",
+		return sysfs_emit(buf, "%2.2x%4.4x%2.2x\n",
 				minfo->smia_manufacturer_id, minfo->model_id,
 				minfo->revision_number) + 1;
 }
Signature · 1 line
2.7.4
#1 lore raw

Hello,

Quoting Qing Wang (2021-10-15 07:49:22)

drivers/media/i2c/ccs/ccs-core.c ccs_sysfs_ident_read(struct device *dev, struct device_attribute *attr,

Quoted 18 lines

show() must not use snprintf() when formatting the value to be returned to user space.

Fix the following coccicheck warning:
drivers/media/i2c/ccs/ccs-core.c:2717: WARNING: use scnprintf or sprintf.

Use sysfs_emit instead of scnprintf or sprintf makes more sense.

---
 drivers/media/i2c/ccs/ccs-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +0 -0
index a9403a2..21a156d 100644
@@ -2715,11 +2715,11 @@ ccs_sysfs_ident_read(struct device *dev, struct device_attribute *attr,

What version of the kernel is this patch against?

I can't find the direct line mapping for this in either the linux-media tree or torvalds master branch (closest match at
https://git.linuxtv.org/media_tree.git/tree/drivers/media/i2c/ccs/ccs-core.c#n2754)

Ah: https://lore.kernel.org/all/[email protected]/
updated this, so I suspect this patch has been submitted against perhaps a v5.14 kernel? It would be best to rebase and repost against the latest branch of https://git.linuxtv.org/media_tree.git

drivers/media/i2c/ccs/ccs-core.c ccs_sysfs_ident_read(struct device *dev, struct device_attribute *attr, · line 2720

Quoted 7 lines
drivers/media/i2c/ccs/ccs-core.c +1 -1
        struct ccs_module_info *minfo = &sensor->minfo;
 
        if (minfo->mipi_manufacturer_id)
-               return snprintf(buf, PAGE_SIZE, "%4.4x%4.4x%2.2x\n",
+               return sysfs_emit(buf, "%4.4x%4.4x%2.2x\n",
                                minfo->mipi_manufacturer_id, minfo->model_id,
                                minfo->revision_number) + 1;

This change looks good, but I think it might be better to re-indent the minfo lines to match as well...

drivers/media/i2c/ccs/ccs-core.c ccs_sysfs_ident_read(struct device *dev, struct device_attribute *attr, · line 2724

Quoted 5 lines
drivers/media/i2c/ccs/ccs-core.c +1 -1
        else
-               return snprintf(buf, PAGE_SIZE, "%2.2x%4.4x%2.2x\n",
+               return sysfs_emit(buf, "%2.2x%4.4x%2.2x\n",
                                minfo->smia_manufacturer_id, minfo->model_id,
                                minfo->revision_number) + 1;

here as well of course.

--
Kieran

Quoted 4 lines
drivers/media/i2c/ccs/ccs-core.c +0 -0
 }
Signature · 1 line
2.7.4