@@ -154,10 +154,6 @@ static int can_copy_perf_config_registers_or_number(u32 user_n_regs,
154154 if (user_n_regs < kernel_n_regs )
155155 return - EINVAL ;
156156
157- if (!access_ok (u64_to_user_ptr (user_regs_ptr ),
158- 2 * sizeof (u32 ) * kernel_n_regs ))
159- return - EFAULT ;
160-
161157 return 0 ;
162158}
163159
@@ -166,6 +162,7 @@ static int copy_perf_config_registers_or_number(const struct i915_oa_reg *kernel
166162 u64 user_regs_ptr ,
167163 u32 * user_n_regs )
168164{
165+ u32 __user * p = u64_to_user_ptr (user_regs_ptr );
169166 u32 r ;
170167
171168 if (* user_n_regs == 0 ) {
@@ -175,25 +172,19 @@ static int copy_perf_config_registers_or_number(const struct i915_oa_reg *kernel
175172
176173 * user_n_regs = kernel_n_regs ;
177174
178- for (r = 0 ; r < kernel_n_regs ; r ++ ) {
179- u32 __user * user_reg_ptr =
180- u64_to_user_ptr (user_regs_ptr + sizeof (u32 ) * r * 2 );
181- u32 __user * user_val_ptr =
182- u64_to_user_ptr (user_regs_ptr + sizeof (u32 ) * r * 2 +
183- sizeof (u32 ));
184- int ret ;
185-
186- ret = __put_user (i915_mmio_reg_offset (kernel_regs [r ].addr ),
187- user_reg_ptr );
188- if (ret )
189- return - EFAULT ;
175+ if (!user_write_access_begin (p , 2 * sizeof (u32 ) * kernel_n_regs ))
176+ return - EFAULT ;
190177
191- ret = __put_user (kernel_regs [r ].value , user_val_ptr );
192- if (ret )
193- return - EFAULT ;
178+ for (r = 0 ; r < kernel_n_regs ; r ++ , p += 2 ) {
179+ unsafe_put_user (i915_mmio_reg_offset (kernel_regs [r ].addr ),
180+ p , Efault );
181+ unsafe_put_user (kernel_regs [r ].value , p + 1 , Efault );
194182 }
195-
183+ user_write_access_end ();
196184 return 0 ;
185+ Efault :
186+ user_write_access_end ();
187+ return - EFAULT ;
197188}
198189
199190static int query_perf_config_data (struct drm_i915_private * i915 ,
@@ -229,10 +220,7 @@ static int query_perf_config_data(struct drm_i915_private *i915,
229220 return - EINVAL ;
230221 }
231222
232- if (!access_ok (user_query_config_ptr , total_size ))
233- return - EFAULT ;
234-
235- if (__get_user (flags , & user_query_config_ptr -> flags ))
223+ if (get_user (flags , & user_query_config_ptr -> flags ))
236224 return - EFAULT ;
237225
238226 if (flags != 0 )
@@ -245,7 +233,7 @@ static int query_perf_config_data(struct drm_i915_private *i915,
245233 BUILD_BUG_ON (sizeof (user_query_config_ptr -> uuid ) >= sizeof (uuid ));
246234
247235 memset (& uuid , 0 , sizeof (uuid ));
248- if (__copy_from_user (uuid , user_query_config_ptr -> uuid ,
236+ if (copy_from_user (uuid , user_query_config_ptr -> uuid ,
249237 sizeof (user_query_config_ptr -> uuid )))
250238 return - EFAULT ;
251239
@@ -259,16 +247,15 @@ static int query_perf_config_data(struct drm_i915_private *i915,
259247 }
260248 rcu_read_unlock ();
261249 } else {
262- if (__get_user (config_id , & user_query_config_ptr -> config ))
250+ if (get_user (config_id , & user_query_config_ptr -> config ))
263251 return - EFAULT ;
264252
265253 oa_config = i915_perf_get_oa_config (perf , config_id );
266254 }
267255 if (!oa_config )
268256 return - ENOENT ;
269257
270- if (__copy_from_user (& user_config , user_config_ptr ,
271- sizeof (user_config ))) {
258+ if (copy_from_user (& user_config , user_config_ptr , sizeof (user_config ))) {
272259 ret = - EFAULT ;
273260 goto out ;
274261 }
@@ -314,8 +301,7 @@ static int query_perf_config_data(struct drm_i915_private *i915,
314301
315302 memcpy (user_config .uuid , oa_config -> uuid , sizeof (user_config .uuid ));
316303
317- if (__copy_to_user (user_config_ptr , & user_config ,
318- sizeof (user_config ))) {
304+ if (copy_to_user (user_config_ptr , & user_config , sizeof (user_config ))) {
319305 ret = - EFAULT ;
320306 goto out ;
321307 }
0 commit comments