Commit 4dc955f7 authored by Mika Kuoppala's avatar Mika Kuoppala Committed by Daniel Vetter

drm/i915: introduce i915_error_state_buf_init

Make function for struct i915_error_state_buf initialization
and export it, for sysfs and debugfs.
Signed-off-by: default avatarMika Kuoppala <mika.kuoppala@intel.com>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 95d5bfb3
...@@ -1028,38 +1028,48 @@ static int i915_error_state_release(struct inode *inode, struct file *file) ...@@ -1028,38 +1028,48 @@ static int i915_error_state_release(struct inode *inode, struct file *file)
return 0; return 0;
} }
static ssize_t i915_error_state_read(struct file *file, char __user *userbuf, int i915_error_state_buf_init(struct drm_i915_error_state_buf *ebuf,
size_t count, loff_t *pos) size_t count, loff_t pos)
{ {
struct i915_error_state_file_priv *error_priv = file->private_data; memset(ebuf, 0, sizeof(*ebuf));
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));
/* We need to have enough room to store any i915_error_state printf /* We need to have enough room to store any i915_error_state printf
* so that we can move it to start position. * so that we can move it to start position.
*/ */
error_str.size = count + 1 > PAGE_SIZE ? count + 1 : PAGE_SIZE; ebuf->size = count + 1 > PAGE_SIZE ? count + 1 : PAGE_SIZE;
error_str.buf = kmalloc(error_str.size, ebuf->buf = kmalloc(ebuf->size,
GFP_TEMPORARY | __GFP_NORETRY | __GFP_NOWARN); GFP_TEMPORARY | __GFP_NORETRY | __GFP_NOWARN);
if (error_str.buf == NULL) { if (ebuf->buf == NULL) {
error_str.size = PAGE_SIZE; ebuf->size = PAGE_SIZE;
error_str.buf = kmalloc(error_str.size, GFP_TEMPORARY); ebuf->buf = kmalloc(ebuf->size, GFP_TEMPORARY);
} }
if (error_str.buf == NULL) { if (ebuf->buf == NULL) {
error_str.size = 128; ebuf->size = 128;
error_str.buf = kmalloc(error_str.size, GFP_TEMPORARY); ebuf->buf = kmalloc(ebuf->size, GFP_TEMPORARY);
} }
if (error_str.buf == NULL) if (ebuf->buf == NULL)
return -ENOMEM; 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); ret = i915_error_state_to_str(&error_str, error_priv);
if (ret) if (ret)
...@@ -1074,7 +1084,7 @@ static ssize_t i915_error_state_read(struct file *file, char __user *userbuf, ...@@ -1074,7 +1084,7 @@ static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
else else
*pos = error_str.start + ret_count; *pos = error_str.start + ret_count;
out: out:
kfree(error_str.buf); i915_error_state_buf_release(&error_str);
return ret ?: ret_count; return ret ?: ret_count;
} }
......
...@@ -1931,6 +1931,13 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *estr, ...@@ -1931,6 +1931,13 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *estr,
void i915_error_state_get(struct drm_device *dev, void i915_error_state_get(struct drm_device *dev,
struct i915_error_state_file_priv *error_priv); struct i915_error_state_file_priv *error_priv);
void i915_error_state_put(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 */ /* i915_suspend.c */
extern int i915_save_state(struct drm_device *dev); extern int i915_save_state(struct drm_device *dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment