diff options
Diffstat (limited to 'drivers/gpu/drm/msm/dp/dp_debug.c')
-rw-r--r-- | drivers/gpu/drm/msm/dp/dp_debug.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/drivers/gpu/drm/msm/dp/dp_debug.c b/drivers/gpu/drm/msm/dp/dp_debug.c index 78bea02955fb..e21614aa41e9 100644 --- a/drivers/gpu/drm/msm/dp/dp_debug.c +++ b/drivers/gpu/drm/msm/dp/dp_debug.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -49,6 +49,7 @@ struct dp_debug_private { struct device *dev; struct work_struct sim_work; struct dp_debug dp_debug; + struct mutex lock; }; static int dp_debug_get_edid_buf(struct dp_debug_private *debug) @@ -98,13 +99,15 @@ static ssize_t dp_debug_write_edid(struct file *file, if (!debug) return -ENODEV; + mutex_lock(&debug->lock); + if (*ppos) goto bail; size = min_t(size_t, count, SZ_1K); buf = kzalloc(size, GFP_KERNEL); - if (!buf) { + if (ZERO_OR_NULL_PTR(buf)) { rc = -ENOMEM; goto bail; } @@ -148,6 +151,7 @@ bail: if (!debug->dp_debug.sim_mode) debug->panel->set_edid(debug->panel, edid); + mutex_unlock(&debug->lock); return rc; } @@ -166,13 +170,15 @@ static ssize_t dp_debug_write_dpcd(struct file *file, if (!debug) return -ENODEV; + mutex_lock(&debug->lock); + if (*ppos) goto bail; size = min_t(size_t, count, SZ_2K); buf = kzalloc(size, GFP_KERNEL); - if (!buf) { + if (ZERO_OR_NULL_PTR(buf)) { rc = -ENOMEM; goto bail; } @@ -230,6 +236,7 @@ bail: else debug->panel->set_dpcd(debug->panel, dpcd); + mutex_unlock(&debug->lock); return rc; } @@ -493,7 +500,7 @@ static ssize_t dp_debug_read_edid_modes(struct file *file, goto error; buf = kzalloc(SZ_4K, GFP_KERNEL); - if (!buf) { + if (ZERO_OR_NULL_PTR(buf)) { rc = -ENOMEM; goto error; } @@ -538,7 +545,7 @@ static ssize_t dp_debug_read_info(struct file *file, char __user *user_buff, return 0; buf = kzalloc(SZ_4K, GFP_KERNEL); - if (!buf) + if (ZERO_OR_NULL_PTR(buf)) return -ENOMEM; rc = snprintf(buf + len, max_size, "\tstate=0x%x\n", debug->aux->state); @@ -624,7 +631,7 @@ static ssize_t dp_debug_bw_code_read(struct file *file, return 0; buf = kzalloc(SZ_4K, GFP_KERNEL); - if (!buf) + if (ZERO_OR_NULL_PTR(buf)) return -ENOMEM; len += snprintf(buf + len, (SZ_4K - len), @@ -745,7 +752,7 @@ static ssize_t dp_debug_read_hdr(struct file *file, goto error; buf = kzalloc(SZ_4K, GFP_KERNEL); - if (!buf) { + if (ZERO_OR_NULL_PTR(buf)) { rc = -ENOMEM; goto error; } @@ -873,6 +880,8 @@ static ssize_t dp_debug_write_sim(struct file *file, if (*ppos) return 0; + mutex_lock(&debug->lock); + /* Leave room for termination char */ len = min_t(size_t, count, SZ_8 - 1); if (copy_from_user(buf, user_buff, len)) @@ -906,9 +915,11 @@ static ssize_t dp_debug_write_sim(struct file *file, debug->aux->set_sim_mode(debug->aux, debug->dp_debug.sim_mode, debug->edid, debug->dpcd); end: + mutex_unlock(&debug->lock); return len; error: devm_kfree(debug->dev, debug->edid); + mutex_unlock(&debug->lock); return len; } @@ -1272,6 +1283,8 @@ struct dp_debug *dp_debug_get(struct device *dev, struct dp_panel *panel, dp_debug->hdisplay = 0; dp_debug->vrefresh = 0; + mutex_init(&debug->lock); + rc = dp_debug_init(dp_debug); if (rc) { devm_kfree(dev, debug); @@ -1308,6 +1321,8 @@ void dp_debug_put(struct dp_debug *dp_debug) dp_debug_deinit(dp_debug); + mutex_destroy(&debug->lock); + if (debug->edid) devm_kfree(debug->dev, debug->edid); |