aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/platforms/powernv/opal-sysparam.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/platforms/powernv/opal-sysparam.c')
-rw-r--r--arch/powerpc/platforms/powernv/opal-sysparam.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/arch/powerpc/platforms/powernv/opal-sysparam.c b/arch/powerpc/platforms/powernv/opal-sysparam.c
index 6b614726baf2..d202f9bc3683 100644
--- a/arch/powerpc/platforms/powernv/opal-sysparam.c
+++ b/arch/powerpc/platforms/powernv/opal-sysparam.c
@@ -39,10 +39,11 @@ struct param_attr {
39 struct kobj_attribute kobj_attr; 39 struct kobj_attribute kobj_attr;
40}; 40};
41 41
42static int opal_get_sys_param(u32 param_id, u32 length, void *buffer) 42static ssize_t opal_get_sys_param(u32 param_id, u32 length, void *buffer)
43{ 43{
44 struct opal_msg msg; 44 struct opal_msg msg;
45 int ret, token; 45 ssize_t ret;
46 int token;
46 47
47 token = opal_async_get_token_interruptible(); 48 token = opal_async_get_token_interruptible();
48 if (token < 0) { 49 if (token < 0) {
@@ -59,7 +60,7 @@ static int opal_get_sys_param(u32 param_id, u32 length, void *buffer)
59 60
60 ret = opal_async_wait_response(token, &msg); 61 ret = opal_async_wait_response(token, &msg);
61 if (ret) { 62 if (ret) {
62 pr_err("%s: Failed to wait for the async response, %d\n", 63 pr_err("%s: Failed to wait for the async response, %zd\n",
63 __func__, ret); 64 __func__, ret);
64 goto out_token; 65 goto out_token;
65 } 66 }
@@ -111,7 +112,7 @@ static ssize_t sys_param_show(struct kobject *kobj,
111{ 112{
112 struct param_attr *attr = container_of(kobj_attr, struct param_attr, 113 struct param_attr *attr = container_of(kobj_attr, struct param_attr,
113 kobj_attr); 114 kobj_attr);
114 int ret; 115 ssize_t ret;
115 116
116 mutex_lock(&opal_sysparam_mutex); 117 mutex_lock(&opal_sysparam_mutex);
117 ret = opal_get_sys_param(attr->param_id, attr->param_size, 118 ret = opal_get_sys_param(attr->param_id, attr->param_size,
@@ -121,9 +122,10 @@ static ssize_t sys_param_show(struct kobject *kobj,
121 122
122 memcpy(buf, param_data_buf, attr->param_size); 123 memcpy(buf, param_data_buf, attr->param_size);
123 124
125 ret = attr->param_size;
124out: 126out:
125 mutex_unlock(&opal_sysparam_mutex); 127 mutex_unlock(&opal_sysparam_mutex);
126 return ret ? ret : attr->param_size; 128 return ret;
127} 129}
128 130
129static ssize_t sys_param_store(struct kobject *kobj, 131static ssize_t sys_param_store(struct kobject *kobj,
@@ -131,14 +133,20 @@ static ssize_t sys_param_store(struct kobject *kobj,
131{ 133{
132 struct param_attr *attr = container_of(kobj_attr, struct param_attr, 134 struct param_attr *attr = container_of(kobj_attr, struct param_attr,
133 kobj_attr); 135 kobj_attr);
134 int ret; 136 ssize_t ret;
137
138 /* MAX_PARAM_DATA_LEN is sizeof(param_data_buf) */
139 if (count > MAX_PARAM_DATA_LEN)
140 count = MAX_PARAM_DATA_LEN;
135 141
136 mutex_lock(&opal_sysparam_mutex); 142 mutex_lock(&opal_sysparam_mutex);
137 memcpy(param_data_buf, buf, count); 143 memcpy(param_data_buf, buf, count);
138 ret = opal_set_sys_param(attr->param_id, attr->param_size, 144 ret = opal_set_sys_param(attr->param_id, attr->param_size,
139 param_data_buf); 145 param_data_buf);
140 mutex_unlock(&opal_sysparam_mutex); 146 mutex_unlock(&opal_sysparam_mutex);
141 return ret ? ret : count; 147 if (!ret)
148 ret = count;
149 return ret;
142} 150}
143 151
144void __init opal_sys_param_init(void) 152void __init opal_sys_param_init(void)
@@ -214,13 +222,13 @@ void __init opal_sys_param_init(void)
214 } 222 }
215 223
216 if (of_property_read_u32_array(sysparam, "param-len", size, count)) { 224 if (of_property_read_u32_array(sysparam, "param-len", size, count)) {
217 pr_err("SYSPARAM: Missing propery param-len in the DT\n"); 225 pr_err("SYSPARAM: Missing property param-len in the DT\n");
218 goto out_free_perm; 226 goto out_free_perm;
219 } 227 }
220 228
221 229
222 if (of_property_read_u8_array(sysparam, "param-perm", perm, count)) { 230 if (of_property_read_u8_array(sysparam, "param-perm", perm, count)) {
223 pr_err("SYSPARAM: Missing propery param-perm in the DT\n"); 231 pr_err("SYSPARAM: Missing property param-perm in the DT\n");
224 goto out_free_perm; 232 goto out_free_perm;
225 } 233 }
226 234
@@ -233,6 +241,12 @@ void __init opal_sys_param_init(void)
233 241
234 /* For each of the parameters, populate the parameter attributes */ 242 /* For each of the parameters, populate the parameter attributes */
235 for (i = 0; i < count; i++) { 243 for (i = 0; i < count; i++) {
244 if (size[i] > MAX_PARAM_DATA_LEN) {
245 pr_warn("SYSPARAM: Not creating parameter %d as size "
246 "exceeds buffer length\n", i);
247 continue;
248 }
249
236 sysfs_attr_init(&attr[i].kobj_attr.attr); 250 sysfs_attr_init(&attr[i].kobj_attr.attr);
237 attr[i].param_id = id[i]; 251 attr[i].param_id = id[i];
238 attr[i].param_size = size[i]; 252 attr[i].param_size = size[i];