2020-05-09 09:16:54

by chenzhou

[permalink] [raw]
Subject: [PATCH -next 0/2] sparc: use snprintf() in show() methods

snprintf() returns the number of bytes that would be written,
which may be greater than the the actual length to be written.

show() methods should return the number of bytes printed into the
buffer. This is the return value of scnprintf().

Chen Zhou (2):
sparc: use snprintf() in show_pciobppath_attr() in pci.c
sparc: use snprintf() in show_pciobppath_attr() in vio.c

arch/sparc/kernel/pci.c | 2 +-
arch/sparc/kernel/vio.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

--
2.20.1


2020-05-09 09:17:12

by chenzhou

[permalink] [raw]
Subject: [PATCH -next 1/2] sparc: use snprintf() in show_pciobppath_attr() in pci.c

snprintf() returns the number of bytes that would be written,
which may be greater than the the actual length to be written.

show_pciobppath_attr() should return the number of bytes printed
into the buffer. This is the return value of scnprintf().

Signed-off-by: Chen Zhou <[email protected]>
---
arch/sparc/kernel/pci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c
index 5ed43828e078..a41ad562ed4e 100644
--- a/arch/sparc/kernel/pci.c
+++ b/arch/sparc/kernel/pci.c
@@ -593,7 +593,7 @@ show_pciobppath_attr(struct device * dev, struct device_attribute * attr, char *
pdev = to_pci_dev(dev);
dp = pdev->dev.of_node;

- return snprintf (buf, PAGE_SIZE, "%pOF\n", dp);
+ return scnprintf(buf, PAGE_SIZE, "%pOF\n", dp);
}

static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH, show_pciobppath_attr, NULL);
--
2.20.1

2020-05-09 09:18:26

by chenzhou

[permalink] [raw]
Subject: [PATCH -next 2/2] sparc: use snprintf() in show_pciobppath_attr() in vio.c

snprintf() returns the number of bytes that would be written,
which may be greater than the the actual length to be written.

show_pciobppath_attr() should return the number of bytes printed
into the buffer. This is the return value of scnprintf().

Signed-off-by: Chen Zhou <[email protected]>
---
arch/sparc/kernel/vio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sparc/kernel/vio.c b/arch/sparc/kernel/vio.c
index c7cad9b7bba7..4f57056ed463 100644
--- a/arch/sparc/kernel/vio.c
+++ b/arch/sparc/kernel/vio.c
@@ -193,7 +193,7 @@ show_pciobppath_attr(struct device *dev, struct device_attribute *attr,
vdev = to_vio_dev(dev);
dp = vdev->dp;

- return snprintf (buf, PAGE_SIZE, "%pOF\n", dp);
+ return scnprintf(buf, PAGE_SIZE, "%pOF\n", dp);
}

static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH,
--
2.20.1

2020-05-09 11:44:22

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH -next 0/2] sparc: use snprintf() in show() methods

On Sat, 2020-05-09 at 17:18 +0800, Chen Zhou wrote:
> snprintf() returns the number of bytes that would be written,
> which may be greater than the the actual length to be written.
[]
> Chen Zhou (2):
> sparc: use snprintf() in show_pciobppath_attr() in pci.c
> sparc: use snprintf() in show_pciobppath_attr() in vio.c

Your subjects are a bit off: snprintf vs scnprintf


2020-05-11 01:26:34

by chenzhou

[permalink] [raw]
Subject: Re: [PATCH -next 0/2] sparc: use snprintf() in show() methods

Sorry, i made a mistake, should be scnprintf().


On 2020/5/9 19:40, Joe Perches wrote:
> On Sat, 2020-05-09 at 17:18 +0800, Chen Zhou wrote:
>> snprintf() returns the number of bytes that would be written,
>> which may be greater than the the actual length to be written.
> []
>> Chen Zhou (2):
>> sparc: use snprintf() in show_pciobppath_attr() in pci.c
>> sparc: use snprintf() in show_pciobppath_attr() in vio.c
> Your subjects are a bit off: snprintf vs scnprintf
>
>
>
>


2020-05-11 01:34:31

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH -next 0/2] sparc: use snprintf() in show() methods

On Mon, 2020-05-11 at 09:24 +0800, chenzhou wrote:
> Sorry, i made a mistake, should be scnprintf().

No worries.

But why do you think this is useful?
Is it likely that either snprint length will exceed PAGE_SIZE?

>
> On 2020/5/9 19:40, Joe Perches wrote:
> > On Sat, 2020-05-09 at 17:18 +0800, Chen Zhou wrote:
> > > snprintf() returns the number of bytes that would be written,
> > > which may be greater than the the actual length to be written.
> > []
> > > Chen Zhou (2):
> > > sparc: use snprintf() in show_pciobppath_attr() in pci.c
> > > sparc: use snprintf() in show_pciobppath_attr() in vio.c
> > Your subjects are a bit off: snprintf vs scnprintf
> >
> >
> >
> >
>
>

2020-05-13 22:38:16

by David Miller

[permalink] [raw]
Subject: Re: [PATCH -next 0/2] sparc: use snprintf() in show() methods

From: Chen Zhou <[email protected]>
Date: Sat, 9 May 2020 17:18:47 +0800

> snprintf() returns the number of bytes that would be written,
> which may be greater than the the actual length to be written.
>
> show() methods should return the number of bytes printed into the
> buffer. This is the return value of scnprintf().

Series applied with Subject lines corrected.