All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] i915: snprintf returns large values
@ 2010-09-08 19:44 ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2010-09-08 19:44 UTC (permalink / raw)
  To: David Airlie; +Cc: Daniel Vetter, kernel-janitors, dri-devel

snprintf() returns the number of bytes which would have been used if
there was enough space.  It can be larger than the size of the buffer.
Obviously in this case the buffer is large enough but everyone just
copy and pastes this code so it's better to limit it and set a good
example.

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

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 5e43d70..1cb29ec 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -741,6 +741,9 @@ i915_wedged_read(struct file *filp,
 		       "wedged :  %d\n",
 		       atomic_read(&dev_priv->mm.wedged));
 
+	if (len > sizeof (buf))
+		len = sizeof (buf);
+
 	return simple_read_from_buffer(ubuf, max, ppos, buf, len);
 }
 

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

* [patch] i915: snprintf returns large values
@ 2010-09-08 19:44 ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2010-09-08 19:44 UTC (permalink / raw)
  To: David Airlie; +Cc: Daniel Vetter, kernel-janitors, dri-devel

snprintf() returns the number of bytes which would have been used if
there was enough space.  It can be larger than the size of the buffer.
Obviously in this case the buffer is large enough but everyone just
copy and pastes this code so it's better to limit it and set a good
example.

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

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 5e43d70..1cb29ec 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -741,6 +741,9 @@ i915_wedged_read(struct file *filp,
 		       "wedged :  %d\n",
 		       atomic_read(&dev_priv->mm.wedged));
 
+	if (len > sizeof (buf))
+		len = sizeof (buf);
+
 	return simple_read_from_buffer(ubuf, max, ppos, buf, len);
 }

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

* Re: [patch] i915: snprintf returns large values
  2010-09-08 19:44 ` Dan Carpenter
@ 2010-09-08 19:49   ` Chris Wilson
  -1 siblings, 0 replies; 4+ messages in thread
From: Chris Wilson @ 2010-09-08 19:49 UTC (permalink / raw)
  To: Dan Carpenter, David Airlie; +Cc: Daniel Vetter, kernel-janitors, dri-devel

On Wed, 8 Sep 2010 21:44:47 +0200, Dan Carpenter <error27@gmail.com> wrote:
> snprintf() returns the number of bytes which would have been used if
> there was enough space.  It can be larger than the size of the buffer.
> Obviously in this case the buffer is large enough but everyone just
> copy and pastes this code so it's better to limit it and set a good
> example.

Applied to drm-intel-next as it is just a pedagogical fix.
Thanks,
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre

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

* Re: [patch] i915: snprintf returns large values
@ 2010-09-08 19:49   ` Chris Wilson
  0 siblings, 0 replies; 4+ messages in thread
From: Chris Wilson @ 2010-09-08 19:49 UTC (permalink / raw)
  To: Dan Carpenter, David Airlie; +Cc: Daniel Vetter, kernel-janitors, dri-devel

On Wed, 8 Sep 2010 21:44:47 +0200, Dan Carpenter <error27@gmail.com> wrote:
> snprintf() returns the number of bytes which would have been used if
> there was enough space.  It can be larger than the size of the buffer.
> Obviously in this case the buffer is large enough but everyone just
> copy and pastes this code so it's better to limit it and set a good
> example.

Applied to drm-intel-next as it is just a pedagogical fix.
Thanks,
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre

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

end of thread, other threads:[~2010-09-08 19:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-08 19:44 [patch] i915: snprintf returns large values Dan Carpenter
2010-09-08 19:44 ` Dan Carpenter
2010-09-08 19:49 ` Chris Wilson
2010-09-08 19:49   ` Chris Wilson

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.