All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] mfd: snprintf() returns largish values
@ 2010-08-12  7:50 ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2010-08-12  7:50 UTC (permalink / raw)
  To: Feng Tang; +Cc: Greg Kroah-Hartman, Alan Cox, linux-kernel, kernel-janitors

snprintf() returns the number of bytes which would have been written so
it can be larger than the size of the buffer.  In this case it's fine,
but people copy and paste this code so I've fixed it.

Signed-off-by: Dan Carpenter <error27@gmail.com>

diff --git a/drivers/serial/mfd.c b/drivers/serial/mfd.c
index bc9af50..5aa25e5 100644
--- a/drivers/serial/mfd.c
+++ b/drivers/serial/mfd.c
@@ -171,6 +171,9 @@ static ssize_t port_show_regs(struct file *file, char __user *user_buf,
 	len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
 			"DIV: \t\t0x%08x\n", serial_in(up, UART_DIV));
 
+	if (len > HSU_REGS_BUFSIZE)
+		len = HSU_REGS_BUFSIZE;
+
 	ret =  simple_read_from_buffer(user_buf, count, ppos, buf, len);
 	kfree(buf);
 	return ret;
@@ -218,6 +221,9 @@ static ssize_t dma_show_regs(struct file *file, char __user *user_buf,
 	len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
 			"D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D3TSR));
 
+	if (len > HSU_REGS_BUFSIZE)
+		len = HSU_REGS_BUFSIZE;
+
 	ret =  simple_read_from_buffer(user_buf, count, ppos, buf, len);
 	kfree(buf);
 	return ret;

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [patch] mfd: snprintf() returns largish values
@ 2010-08-12  7:50 ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2010-08-12  7:50 UTC (permalink / raw)
  To: Feng Tang; +Cc: Greg Kroah-Hartman, Alan Cox, linux-kernel, kernel-janitors

snprintf() returns the number of bytes which would have been written so
it can be larger than the size of the buffer.  In this case it's fine,
but people copy and paste this code so I've fixed it.

Signed-off-by: Dan Carpenter <error27@gmail.com>

diff --git a/drivers/serial/mfd.c b/drivers/serial/mfd.c
index bc9af50..5aa25e5 100644
--- a/drivers/serial/mfd.c
+++ b/drivers/serial/mfd.c
@@ -171,6 +171,9 @@ static ssize_t port_show_regs(struct file *file, char __user *user_buf,
 	len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
 			"DIV: \t\t0x%08x\n", serial_in(up, UART_DIV));
 
+	if (len > HSU_REGS_BUFSIZE)
+		len = HSU_REGS_BUFSIZE;
+
 	ret =  simple_read_from_buffer(user_buf, count, ppos, buf, len);
 	kfree(buf);
 	return ret;
@@ -218,6 +221,9 @@ static ssize_t dma_show_regs(struct file *file, char __user *user_buf,
 	len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
 			"D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D3TSR));
 
+	if (len > HSU_REGS_BUFSIZE)
+		len = HSU_REGS_BUFSIZE;
+
 	ret =  simple_read_from_buffer(user_buf, count, ppos, buf, len);
 	kfree(buf);
 	return ret;

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [patch] mfd: snprintf() returns largish values
  2010-08-12  7:50 ` Dan Carpenter
@ 2010-08-13  1:23   ` Feng Tang
  -1 siblings, 0 replies; 4+ messages in thread
From: Feng Tang @ 2010-08-13  1:23 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Greg Kroah-Hartman, Alan Cox, linux-kernel, kernel-janitors

On Thu, 12 Aug 2010 15:50:09 +0800
Dan Carpenter <error27@gmail.com> wrote:

> snprintf() returns the number of bytes which would have been written
> so it can be larger than the size of the buffer.  In this case it's
> fine, but people copy and paste this code so I've fixed it.
> 
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> 
> diff --git a/drivers/serial/mfd.c b/drivers/serial/mfd.c
> index bc9af50..5aa25e5 100644
> --- a/drivers/serial/mfd.c
> +++ b/drivers/serial/mfd.c
> @@ -171,6 +171,9 @@ static ssize_t port_show_regs(struct file *file,
> char __user *user_buf, len += snprintf(buf + len, HSU_REGS_BUFSIZE -
> len, "DIV: \t\t0x%08x\n", serial_in(up, UART_DIV));
>  
> +	if (len > HSU_REGS_BUFSIZE)
> +		len = HSU_REGS_BUFSIZE;
> +
>  	ret =  simple_read_from_buffer(user_buf, count, ppos, buf,
> len); kfree(buf);
>  	return ret;
> @@ -218,6 +221,9 @@ static ssize_t dma_show_regs(struct file *file,
> char __user *user_buf, len += snprintf(buf + len, HSU_REGS_BUFSIZE -
> len, "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D3TSR));
>  
> +	if (len > HSU_REGS_BUFSIZE)
> +		len = HSU_REGS_BUFSIZE;
> +
>  	ret =  simple_read_from_buffer(user_buf, count, ppos, buf,
> len); kfree(buf);
>  	return ret;

Hi Carpenter,

It looks ok to me, thanks,

- Feng

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] mfd: snprintf() returns largish values
@ 2010-08-13  1:23   ` Feng Tang
  0 siblings, 0 replies; 4+ messages in thread
From: Feng Tang @ 2010-08-13  1:23 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Greg Kroah-Hartman, Alan Cox, linux-kernel, kernel-janitors

On Thu, 12 Aug 2010 15:50:09 +0800
Dan Carpenter <error27@gmail.com> wrote:

> snprintf() returns the number of bytes which would have been written
> so it can be larger than the size of the buffer.  In this case it's
> fine, but people copy and paste this code so I've fixed it.
> 
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> 
> diff --git a/drivers/serial/mfd.c b/drivers/serial/mfd.c
> index bc9af50..5aa25e5 100644
> --- a/drivers/serial/mfd.c
> +++ b/drivers/serial/mfd.c
> @@ -171,6 +171,9 @@ static ssize_t port_show_regs(struct file *file,
> char __user *user_buf, len += snprintf(buf + len, HSU_REGS_BUFSIZE -
> len, "DIV: \t\t0x%08x\n", serial_in(up, UART_DIV));
>  
> +	if (len > HSU_REGS_BUFSIZE)
> +		len = HSU_REGS_BUFSIZE;
> +
>  	ret =  simple_read_from_buffer(user_buf, count, ppos, buf,
> len); kfree(buf);
>  	return ret;
> @@ -218,6 +221,9 @@ static ssize_t dma_show_regs(struct file *file,
> char __user *user_buf, len += snprintf(buf + len, HSU_REGS_BUFSIZE -
> len, "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D3TSR));
>  
> +	if (len > HSU_REGS_BUFSIZE)
> +		len = HSU_REGS_BUFSIZE;
> +
>  	ret =  simple_read_from_buffer(user_buf, count, ppos, buf,
> len); kfree(buf);
>  	return ret;

Hi Carpenter,

It looks ok to me, thanks,

- Feng

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-08-13  1:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-12  7:50 [patch] mfd: snprintf() returns largish values Dan Carpenter
2010-08-12  7:50 ` Dan Carpenter
2010-08-13  1:23 ` Feng Tang
2010-08-13  1:23   ` Feng Tang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.