Skip to contentSkip to conversation

media: i2c: ccs: replace snprintf in show functions with sysfs_emit

PATCH Superseded Qing Wang 2 participants 2 messages Oct 18, 2021 – Oct 19, 2021

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Qing Wang

author
#0 lore raw

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

show() should 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:3761: WARNING: use scnprintf or sprintf.

---
 drivers/media/i2c/ccs/ccs-core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +6 -6
index 5363f3b..9158d3c
@@ -2758,13 +2758,13 @@ ident_show(struct device *dev, struct device_attribute *attr, char *buf)
 	struct ccs_module_info *minfo = &sensor->minfo;
 
 	if (minfo->mipi_manufacturer_id)
-		return snprintf(buf, PAGE_SIZE, "%4.4x%4.4x%2.2x\n",
-				minfo->mipi_manufacturer_id, minfo->model_id,
-				minfo->revision_number) + 1;
+		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",
-				minfo->smia_manufacturer_id, minfo->model_id,
-				minfo->revision_number) + 1;
+		return sysfs_emit(buf, "%2.2x%4.4x%2.2x\n",
+				    minfo->smia_manufacturer_id, minfo->model_id,
+				    minfo->revision_number) + 1;
 }
 static DEVICE_ATTR_RO(ident);
 
Signature · 1 line
2.7.4
#1 lore raw

Hello,

Quoting Qing Wang (2021-10-18 09:00:36)

Quoted 6 lines

show() should 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:3761: WARNING: use scnprintf or sprintf.

Thank you for posting a v2 with the lines adjusted ...

Quoted 10 lines
---
 drivers/media/i2c/ccs/ccs-core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +0 -0
index 5363f3b..9158d3c

drivers/media/i2c/ccs/ccs-core.c ident_show(struct device *dev, struct device_attribute *attr, char *buf) · line 2763

Quoted 9 lines
drivers/media/i2c/ccs/ccs-core.c +3 -3
@@ -2758,13 +2758,13 @@ ident_show(struct device *dev, struct device_attribute *attr, char *buf)
        struct ccs_module_info *minfo = &sensor->minfo;
 
        if (minfo->mipi_manufacturer_id)
-               return snprintf(buf, PAGE_SIZE, "%4.4x%4.4x%2.2x\n",
-                               minfo->mipi_manufacturer_id, minfo->model_id,
-                               minfo->revision_number) + 1;
+               return sysfs_emit(buf, "%4.4x%4.4x%2.2x\n",
+                                   minfo->mipi_manufacturer_id, minfo->model_id,
+                                   minfo->revision_number) + 1;

However they are still not lined up correctly.
It should look like:

return sysfs_emit(buf, "%4.4x%4.4x%2.2x\n",

                  minfo->mipi_manufacturer_id, minfo->model_id,
                  minfo->revision_number) + 1;

With the m from 'minfo' aligned directly below the b from 'buf' to match the indention.

--
Regards

Kieran

Quoted 13 lines
drivers/media/i2c/ccs/ccs-core.c +3 -3
        else
-               return snprintf(buf, PAGE_SIZE, "%2.2x%4.4x%2.2x\n",
-                               minfo->smia_manufacturer_id, minfo->model_id,
-                               minfo->revision_number) + 1;
+               return sysfs_emit(buf, "%2.2x%4.4x%2.2x\n",
+                                   minfo->smia_manufacturer_id, minfo->model_id,
+                                   minfo->revision_number) + 1;
 }
 static DEVICE_ATTR_RO(ident);
 
Signature · 1 line
2.7.4