* [PATCH 1/7] comedi: Convert snprintf() to scnprintf()
@ 2022-09-26 18:37 Jules Irenge
2022-09-27 6:06 ` Greg KH
0 siblings, 1 reply; 5+ messages in thread
From: Jules Irenge @ 2022-09-26 18:37 UTC (permalink / raw)
To: abbotti; +Cc: hsweeten, gregkh, linux-kernel, abbotti
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.
Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
---
drivers/comedi/comedi_fops.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/comedi/comedi_fops.c b/drivers/comedi/comedi_fops.c
index 55a0cae04b8d..e8a0142d5894 100644
--- a/drivers/comedi/comedi_fops.c
+++ b/drivers/comedi/comedi_fops.c
@@ -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,
--
2.37.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/7] comedi: Convert snprintf() to scnprintf()
2022-09-26 18:37 [PATCH 1/7] comedi: Convert snprintf() to scnprintf() Jules Irenge
@ 2022-09-27 6:06 ` Greg KH
2022-09-28 13:27 ` Jules Irenge
2022-09-28 15:45 ` Ian Abbott
0 siblings, 2 replies; 5+ messages in thread
From: Greg KH @ 2022-09-27 6:06 UTC (permalink / raw)
To: Jules Irenge; +Cc: abbotti, hsweeten, linux-kernel
On Mon, Sep 26, 2022 at 07:37:37PM +0100, Jules Irenge wrote:
> 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.
>
> Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
> ---
> drivers/comedi/comedi_fops.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/comedi/comedi_fops.c b/drivers/comedi/comedi_fops.c
> index 55a0cae04b8d..e8a0142d5894 100644
> --- a/drivers/comedi/comedi_fops.c
> +++ b/drivers/comedi/comedi_fops.c
> @@ -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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/7] comedi: Convert snprintf() to scnprintf()
2022-09-27 6:06 ` Greg KH
@ 2022-09-28 13:27 ` Jules Irenge
2022-09-28 15:45 ` Ian Abbott
1 sibling, 0 replies; 5+ messages in thread
From: Jules Irenge @ 2022-09-28 13:27 UTC (permalink / raw)
To: Greg KH; +Cc: abbotti, hsweeten, linux-kernel
On Tue, Sep 27, 2022 at 08:06:55AM +0200, Greg KH wrote:
> On Mon, Sep 26, 2022 at 07:37:37PM +0100, Jules Irenge wrote:
> > 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.
> >
> > Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
> > ---
> > drivers/comedi/comedi_fops.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/comedi/comedi_fops.c b/drivers/comedi/comedi_fops.c
> > index 55a0cae04b8d..e8a0142d5894 100644
> > --- a/drivers/comedi/comedi_fops.c
> > +++ b/drivers/comedi/comedi_fops.c
> > @@ -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
Thanks for feedback.
I just sent a different version.
I will appreciate any more feedback.
Thanks,
Jules
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/7] comedi: Convert snprintf() to scnprintf()
2022-09-27 6:06 ` Greg KH
2022-09-28 13:27 ` Jules Irenge
@ 2022-09-28 15:45 ` Ian Abbott
2022-09-28 18:51 ` Jules Irenge
1 sibling, 1 reply; 5+ messages in thread
From: Ian Abbott @ 2022-09-28 15:45 UTC (permalink / raw)
To: Greg KH, Jules Irenge; +Cc: hsweeten, linux-kernel
On 27/09/2022 07:06, Greg KH wrote:
> On Mon, Sep 26, 2022 at 07:37:37PM +0100, Jules Irenge wrote:
>> 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.
>>
>> Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
>> ---
>> drivers/comedi/comedi_fops.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/comedi/comedi_fops.c b/drivers/comedi/comedi_fops.c
>> index 55a0cae04b8d..e8a0142d5894 100644
>> --- a/drivers/comedi/comedi_fops.c
>> +++ b/drivers/comedi/comedi_fops.c
>> @@ -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".
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/20220901013423.418464-1-zhangxuezhi3@gmail.com/
--
-=( Ian Abbott <abbotti@mev.co.uk> || 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 )=-
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/7] comedi: Convert snprintf() to scnprintf()
2022-09-28 15:45 ` Ian Abbott
@ 2022-09-28 18:51 ` Jules Irenge
0 siblings, 0 replies; 5+ messages in thread
From: Jules Irenge @ 2022-09-28 18:51 UTC (permalink / raw)
To: Ian Abbott; +Cc: hsweeten, linux-kernel
On Wed, Sep 28, 2022 at 04:45:53PM +0100, Ian Abbott wrote:
> On 27/09/2022 07:06, Greg KH wrote:
> > On Mon, Sep 26, 2022 at 07:37:37PM +0100, Jules Irenge wrote:
> > > 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.
> > >
> > > Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
> > > ---
> > > drivers/comedi/comedi_fops.c | 8 ++++----
> > > 1 file changed, 4 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/comedi/comedi_fops.c b/drivers/comedi/comedi_fops.c
> > > index 55a0cae04b8d..e8a0142d5894 100644
> > > --- a/drivers/comedi/comedi_fops.c
> > > +++ b/drivers/comedi/comedi_fops.c
> > > @@ -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".
>
> 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/20220901013423.418464-1-zhangxuezhi3@gmail.com/
>
Great, it's good to know how to fix the warning anyway.
Thanks,
Jules
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-09-28 18:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-26 18:37 [PATCH 1/7] comedi: Convert snprintf() to scnprintf() Jules Irenge
2022-09-27 6:06 ` Greg KH
2022-09-28 13:27 ` Jules Irenge
2022-09-28 15:45 ` Ian Abbott
2022-09-28 18:51 ` Jules Irenge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox