Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mika Kuoppala <mika.kuoppala@linux.intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH 3/4] drm/i915: introduce i915_error_state_buf_init
Date: Thu,  6 Jun 2013 15:18:41 +0300	[thread overview]
Message-ID: <1370521122-20268-3-git-send-email-mika.kuoppala@intel.com> (raw)
In-Reply-To: <1370521122-20268-1-git-send-email-mika.kuoppala@intel.com>

Make function for struct i915_error_state_buf initialization
and export it, for sysfs and debugfs.

Signed-off-by: Mika Kuoppala <mika.kuoppala@intel.com>
---
 drivers/gpu/drm/i915/i915_debugfs.c |   50 +++++++++++++++++++++--------------
 drivers/gpu/drm/i915/i915_drv.h     |    7 +++++
 2 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 1e22820..6ea6747 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -937,38 +937,48 @@ static int i915_error_state_release(struct inode *inode, struct file *file)
 	return 0;
 }
 
-static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
-				     size_t count, loff_t *pos)
+int i915_error_state_buf_init(struct drm_i915_error_state_buf *ebuf,
+			      size_t count, loff_t pos)
 {
-	struct i915_error_state_file_priv *error_priv = file->private_data;
-	struct drm_i915_error_state_buf error_str;
-	loff_t tmp_pos = 0;
-	ssize_t ret_count = 0;
-	int ret = 0;
-
-	memset(&error_str, 0, sizeof(error_str));
+	memset(ebuf, 0, sizeof(*ebuf));
 
 	/* We need to have enough room to store any i915_error_state printf
 	 * so that we can move it to start position.
 	 */
-	error_str.size = count + 1 > PAGE_SIZE ? count + 1 : PAGE_SIZE;
-	error_str.buf = kmalloc(error_str.size,
+	ebuf->size = count + 1 > PAGE_SIZE ? count + 1 : PAGE_SIZE;
+	ebuf->buf = kmalloc(ebuf->size,
 				GFP_TEMPORARY | __GFP_NORETRY | __GFP_NOWARN);
 
-	if (error_str.buf == NULL) {
-		error_str.size = PAGE_SIZE;
-		error_str.buf = kmalloc(error_str.size, GFP_TEMPORARY);
+	if (ebuf->buf == NULL) {
+		ebuf->size = PAGE_SIZE;
+		ebuf->buf = kmalloc(ebuf->size, GFP_TEMPORARY);
 	}
 
-	if (error_str.buf == NULL) {
-		error_str.size = 128;
-		error_str.buf = kmalloc(error_str.size, GFP_TEMPORARY);
+	if (ebuf->buf == NULL) {
+		ebuf->size = 128;
+		ebuf->buf = kmalloc(ebuf->size, GFP_TEMPORARY);
 	}
 
-	if (error_str.buf == NULL)
+	if (ebuf->buf == NULL)
 		return -ENOMEM;
 
-	error_str.start = *pos;
+	ebuf->start = pos;
+
+	return 0;
+}
+
+static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
+				     size_t count, loff_t *pos)
+{
+	struct i915_error_state_file_priv *error_priv = file->private_data;
+	struct drm_i915_error_state_buf error_str;
+	loff_t tmp_pos = 0;
+	ssize_t ret_count = 0;
+	int ret;
+
+	ret = i915_error_state_buf_init(&error_str, count, *pos);
+	if (ret)
+		return ret;
 
 	ret = i915_error_state_to_str(&error_str, error_priv);
 	if (ret)
@@ -983,7 +993,7 @@ static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
 	else
 		*pos = error_str.start + ret_count;
 out:
-	kfree(error_str.buf);
+	i915_error_state_buf_release(&error_str);
 	return ret ?: ret_count;
 }
 
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index adc2841..b8e16d1 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1860,6 +1860,13 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *estr,
 void i915_error_state_get(struct drm_device *dev,
 			  struct i915_error_state_file_priv *error_priv);
 void i915_error_state_put(struct i915_error_state_file_priv *error_priv);
+int i915_error_state_buf_init(struct drm_i915_error_state_buf *eb,
+			      size_t count, loff_t pos);
+static inline void i915_error_state_buf_release(
+	struct drm_i915_error_state_buf *eb)
+{
+	kfree(eb->buf);
+}
 
 /* i915_suspend.c */
 extern int i915_save_state(struct drm_device *dev);
-- 
1.7.9.5

  parent reply	other threads:[~2013-06-06 12:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-06 12:18 [PATCH 1/4] drm/i915: export error state to string conversion Mika Kuoppala
2013-06-06 12:18 ` [PATCH 2/4] drm/i915: export error state ref handling Mika Kuoppala
2013-06-06 12:18 ` Mika Kuoppala [this message]
2013-06-06 12:18 ` [PATCH 4/4] drm/i915: add i915_error_state sysfs entry Mika Kuoppala
2013-06-06 12:22   ` Chris Wilson
2013-06-06 12:24   ` Daniel Vetter
2013-06-06 13:33   ` [PATCH 4/4] drm/i915: add error_state " Mika Kuoppala
2013-06-06 13:48     ` Chris Wilson
2013-06-06 14:38       ` Mika Kuoppala
2013-07-01 16:19         ` Chris Wilson
2013-07-01 16:56           ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1370521122-20268-3-git-send-email-mika.kuoppala@intel.com \
    --to=mika.kuoppala@linux.intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox