Skip to contentSkip to conversation

comedi: Convert snprintf() to scnprintf()

PATCH Superseded Jules Irenge 3 participants 5 messages Sep 26, 2022 – Sep 28, 2022 Comedi drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 comedi: Convert snprintf() to scnprintf()

Coccinnelle reports a warning
Warning: Use scnprintf or sprintf
Adding to that, there has been a slow migration from snprintf to scnprintf. This LWN article explains the rationale for this change
https: //lwn.net/Articles/69419/
Ie. snprintf() returns what *would* be the resulting length, while scnprintf() returns the actual length.

---
 drivers/comedi/comedi_fops.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/comedi/comedi_fops.c +4 -4
index 55a0cae04b8d..e8a0142d5894 100644
@@ -396,7 +396,7 @@ static ssize_t max_read_buffer_kb_show(struct device *csdev,
 	mutex_unlock(&dev->mutex);
 
 	comedi_dev_put(dev);
-	return snprintf(buf, PAGE_SIZE, "%u\n", size);
+	return scnprintf(buf, PAGE_SIZE, "%u\n", size);
 }
 
 static ssize_t max_read_buffer_kb_store(struct device *csdev,
@@ -452,7 +452,7 @@ static ssize_t read_buffer_kb_show(struct device *csdev,
 	mutex_unlock(&dev->mutex);
 
 	comedi_dev_put(dev);
-	return snprintf(buf, PAGE_SIZE, "%u\n", size);
+	return scnprintf(buf, PAGE_SIZE, "%u\n", size);
 }
 
 static ssize_t read_buffer_kb_store(struct device *csdev,
@@ -509,7 +509,7 @@ static ssize_t max_write_buffer_kb_show(struct device *csdev,
 	mutex_unlock(&dev->mutex);
 
 	comedi_dev_put(dev);
-	return snprintf(buf, PAGE_SIZE, "%u\n", size);
+	return scnprintf(buf, PAGE_SIZE, "%u\n", size);
 }
 
 static ssize_t max_write_buffer_kb_store(struct device *csdev,
@@ -565,7 +565,7 @@ static ssize_t write_buffer_kb_show(struct device *csdev,
 	mutex_unlock(&dev->mutex);
 
 	comedi_dev_put(dev);
-	return snprintf(buf, PAGE_SIZE, "%u\n", size);
+	return scnprintf(buf, PAGE_SIZE, "%u\n", size);
 }
 
 static ssize_t write_buffer_kb_store(struct device *csdev,
Signature · 1 line
2.37.3
#1 lore raw
Quoted 18 lines · Jules Irenge

Coccinnelle reports a warning
Warning: Use scnprintf or sprintf
Adding to that, there has been a slow migration from snprintf to scnprintf. This LWN article explains the rationale for this change
https: //lwn.net/Articles/69419/
Ie. snprintf() returns what *would* be the resulting length, while scnprintf() returns the actual length.

---
 drivers/comedi/comedi_fops.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/comedi/comedi_fops.c +0 -0
index 55a0cae04b8d..e8a0142d5894 100644

drivers/comedi/comedi_fops.c static ssize_t max_read_buffer_kb_show(struct device *csdev, · line 399

Quoted 5 lines
drivers/comedi/comedi_fops.c +1 -1
@@ -396,7 +396,7 @@ static ssize_t max_read_buffer_kb_show(struct device *csdev,
 	mutex_unlock(&dev->mutex);
 
 	comedi_dev_put(dev);
-	return snprintf(buf, PAGE_SIZE, "%u\n", size);
+	return scnprintf(buf, PAGE_SIZE, "%u\n", size);

Ick, no, you should use sysfs_emit() if you really want to change these functions to "do the right thing".

thanks,

greg k-h

#2 lore raw
Quoted 28 lines · Greg KH
Quoted 18 lines · Jules Irenge

Coccinnelle reports a warning
Warning: Use scnprintf or sprintf
Adding to that, there has been a slow migration from snprintf to scnprintf. This LWN article explains the rationale for this change
https: //lwn.net/Articles/69419/
Ie. snprintf() returns what *would* be the resulting length, while scnprintf() returns the actual length.

---
 drivers/comedi/comedi_fops.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/comedi/comedi_fops.c +0 -0
index 55a0cae04b8d..e8a0142d5894 100644

drivers/comedi/comedi_fops.c static ssize_t max_read_buffer_kb_show(struct device *csdev, · line 399

Quoted 5 lines
drivers/comedi/comedi_fops.c +1 -1
@@ -396,7 +396,7 @@ static ssize_t max_read_buffer_kb_show(struct device *csdev,
 	mutex_unlock(&dev->mutex);
 
 	comedi_dev_put(dev);
-	return snprintf(buf, PAGE_SIZE, "%u\n", size);
+	return scnprintf(buf, PAGE_SIZE, "%u\n", size);

Ick, no, you should use sysfs_emit() if you really want to change these functions to "do the right thing".

Quoted 3 lines

thanks,

greg k-h

Thanks for feedback.

I just sent a different version.

I will appreciate any more feedback.

Thanks,

Jules

maintainer
#3 lore raw
In reply to Greg KH
Quoted 21 lines · Greg KH
Quoted 20 lines · Jules Irenge

Coccinnelle reports a warning
Warning: Use scnprintf or sprintf
Adding to that, there has been a slow migration from snprintf to scnprintf. This LWN article explains the rationale for this change
https: //lwn.net/Articles/69419/
Ie. snprintf() returns what *would* be the resulting length, while scnprintf() returns the actual length.

---
  drivers/comedi/comedi_fops.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/comedi/comedi_fops.c +0 -0
index 55a0cae04b8d..e8a0142d5894 100644
@@ -396,7 +396,7 @@ static ssize_t max_read_buffer_kb_show(struct device *csdev,
  	mutex_unlock(&dev->mutex);
 
Quoted 6 lines

drivers/comedi/comedi_fops.c static ssize_t max_read_buffer_kb_show(struct device *csdev, · line 399

Quoted 3 lines
drivers/comedi/comedi_fops.c +1 -1
  	comedi_dev_put(dev);
-	return snprintf(buf, PAGE_SIZE, "%u\n", size);
+	return scnprintf(buf, PAGE_SIZE, "%u\n", size);

Ick, no, you should use sysfs_emit() if you really want to change these functions to "do the right thing".

There was a patch to do that by Xuezhi Zhang. It got to PATCH v4. I should have replied with a "Reviewed-By" tag, but I'd already done that for the earlier versions.

https://lore.kernel.org/lkml/[email protected]/

Signature · 4 lines
-=( Ian Abbott <[email protected]> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-
#4 lore raw
Quoted 28 lines · Ian Abbott
Quoted 14 lines · Greg KH
Quoted 13 lines · Jules Irenge

Coccinnelle reports a warning
Warning: Use scnprintf or sprintf
Adding to that, there has been a slow migration from snprintf to scnprintf. This LWN article explains the rationale for this change
https: //lwn.net/Articles/69419/
Ie. snprintf() returns what *would* be the resulting length, while scnprintf() returns the actual length.

---
  drivers/comedi/comedi_fops.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 12 lines

drivers/comedi/comedi_fops.c static ssize_t max_read_buffer_kb_show(struct device *csdev, · line 398

Quoted 9 lines
drivers/comedi/comedi_fops.c +1 -1
index 55a0cae04b8d..e8a0142d5894 100644
@@ -396,7 +396,7 @@ static ssize_t max_read_buffer_kb_show(struct device *csdev,
  	mutex_unlock(&dev->mutex);
  	comedi_dev_put(dev);
-	return snprintf(buf, PAGE_SIZE, "%u\n", size);
+	return scnprintf(buf, PAGE_SIZE, "%u\n", size);

Ick, no, you should use sysfs_emit() if you really want to change these functions to "do the right thing".

Quoted 6 lines

There was a patch to do that by Xuezhi Zhang. It got to PATCH v4. I should have replied with a "Reviewed-By" tag, but I'd already done that for the earlier versions.

https://lore.kernel.org/lkml/[email protected]/

Great, it's good to know how to fix the warning anyway.

Thanks,
Jules