@@ -294,31 +294,40 @@ static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj,
294294 struct kone_device * kone = hid_get_drvdata (dev_get_drvdata (dev ));
295295 struct usb_device * usb_dev = interface_to_usbdev (to_usb_interface (dev ));
296296 int retval = 0 , difference , old_profile ;
297+ struct kone_settings * settings = (struct kone_settings * )buf ;
297298
298299 /* I need to get my data in one piece */
299300 if (off != 0 || count != sizeof (struct kone_settings ))
300301 return - EINVAL ;
301302
302303 mutex_lock (& kone -> kone_lock );
303- difference = memcmp (buf , & kone -> settings , sizeof (struct kone_settings ));
304+ difference = memcmp (settings , & kone -> settings ,
305+ sizeof (struct kone_settings ));
304306 if (difference ) {
305- retval = kone_set_settings (usb_dev ,
306- (struct kone_settings const * )buf );
307- if (retval ) {
308- mutex_unlock (& kone -> kone_lock );
309- return retval ;
307+ if (settings -> startup_profile < 1 ||
308+ settings -> startup_profile > 5 ) {
309+ retval = - EINVAL ;
310+ goto unlock ;
310311 }
311312
313+ retval = kone_set_settings (usb_dev , settings );
314+ if (retval )
315+ goto unlock ;
316+
312317 old_profile = kone -> settings .startup_profile ;
313- memcpy (& kone -> settings , buf , sizeof (struct kone_settings ));
318+ memcpy (& kone -> settings , settings , sizeof (struct kone_settings ));
314319
315320 kone_profile_activated (kone , kone -> settings .startup_profile );
316321
317322 if (kone -> settings .startup_profile != old_profile )
318323 kone_profile_report (kone , kone -> settings .startup_profile );
319324 }
325+ unlock :
320326 mutex_unlock (& kone -> kone_lock );
321327
328+ if (retval )
329+ return retval ;
330+
322331 return sizeof (struct kone_settings );
323332}
324333static BIN_ATTR (settings , 0660 , kone_sysfs_read_settings ,
0 commit comments