@@ -1304,132 +1304,129 @@ static const struct v4l2_ctrl_type_ops std_type_ops = {
13041304 .validate = std_validate ,
13051305};
13061306
1307- /* Helper function: copy the current control value back to the caller */
1308- static int cur_to_user (struct v4l2_ext_control * c ,
1309- struct v4l2_ctrl * ctrl )
1307+ /* Helper function: copy the given control value back to the caller */
1308+ static int ptr_to_user (struct v4l2_ext_control * c ,
1309+ struct v4l2_ctrl * ctrl ,
1310+ union v4l2_ctrl_ptr ptr )
13101311{
13111312 u32 len ;
13121313
13131314 if (ctrl -> is_ptr && !ctrl -> is_string )
1314- return copy_to_user (c -> ptr , ctrl -> cur .p , ctrl -> elem_size );
1315+ return copy_to_user (c -> ptr , ptr .p , ctrl -> elem_size );
13151316
13161317 switch (ctrl -> type ) {
13171318 case V4L2_CTRL_TYPE_STRING :
1318- len = strlen (ctrl -> cur . string );
1319+ len = strlen (ptr . p_char );
13191320 if (c -> size < len + 1 ) {
13201321 c -> size = len + 1 ;
13211322 return - ENOSPC ;
13221323 }
1323- return copy_to_user (c -> string , ctrl -> cur . string ,
1324- len + 1 ) ? - EFAULT : 0 ;
1324+ return copy_to_user (c -> string , ptr . p_char , len + 1 ) ?
1325+ - EFAULT : 0 ;
13251326 case V4L2_CTRL_TYPE_INTEGER64 :
1326- c -> value64 = ctrl -> cur . val64 ;
1327+ c -> value64 = * ptr . p_s64 ;
13271328 break ;
13281329 default :
1329- c -> value = ctrl -> cur . val ;
1330+ c -> value = * ptr . p_s32 ;
13301331 break ;
13311332 }
13321333 return 0 ;
13331334}
13341335
1335- /* Helper function: copy the caller-provider value as the new control value */
1336- static int user_to_new (struct v4l2_ext_control * c ,
1336+ /* Helper function: copy the current control value back to the caller */
1337+ static int cur_to_user (struct v4l2_ext_control * c ,
13371338 struct v4l2_ctrl * ctrl )
1339+ {
1340+ return ptr_to_user (c , ctrl , ctrl -> p_cur );
1341+ }
1342+
1343+ /* Helper function: copy the new control value back to the caller */
1344+ static int new_to_user (struct v4l2_ext_control * c ,
1345+ struct v4l2_ctrl * ctrl )
1346+ {
1347+ return ptr_to_user (c , ctrl , ctrl -> p_new );
1348+ }
1349+
1350+ /* Helper function: copy the caller-provider value to the given control value */
1351+ static int user_to_ptr (struct v4l2_ext_control * c ,
1352+ struct v4l2_ctrl * ctrl ,
1353+ union v4l2_ctrl_ptr ptr )
13381354{
13391355 int ret ;
13401356 u32 size ;
13411357
13421358 ctrl -> is_new = 1 ;
13431359 if (ctrl -> is_ptr && !ctrl -> is_string )
1344- return copy_from_user (ctrl -> p , c -> ptr , ctrl -> elem_size );
1360+ return copy_from_user (ptr . p , c -> ptr , ctrl -> elem_size );
13451361
13461362 switch (ctrl -> type ) {
13471363 case V4L2_CTRL_TYPE_INTEGER64 :
1348- ctrl -> val64 = c -> value64 ;
1364+ * ptr . p_s64 = c -> value64 ;
13491365 break ;
13501366 case V4L2_CTRL_TYPE_STRING :
13511367 size = c -> size ;
13521368 if (size == 0 )
13531369 return - ERANGE ;
13541370 if (size > ctrl -> maximum + 1 )
13551371 size = ctrl -> maximum + 1 ;
1356- ret = copy_from_user (ctrl -> string , c -> string , size );
1372+ ret = copy_from_user (ptr . p_char , c -> string , size );
13571373 if (!ret ) {
1358- char last = ctrl -> string [size - 1 ];
1374+ char last = ptr . p_char [size - 1 ];
13591375
1360- ctrl -> string [size - 1 ] = 0 ;
1376+ ptr . p_char [size - 1 ] = 0 ;
13611377 /* If the string was longer than ctrl->maximum,
13621378 then return an error. */
1363- if (strlen (ctrl -> string ) == ctrl -> maximum && last )
1379+ if (strlen (ptr . p_char ) == ctrl -> maximum && last )
13641380 return - ERANGE ;
13651381 }
13661382 return ret ? - EFAULT : 0 ;
13671383 default :
1368- ctrl -> val = c -> value ;
1384+ * ptr . p_s32 = c -> value ;
13691385 break ;
13701386 }
13711387 return 0 ;
13721388}
13731389
1374- /* Helper function: copy the new control value back to the caller */
1375- static int new_to_user (struct v4l2_ext_control * c ,
1390+ /* Helper function: copy the caller-provider value as the new control value */
1391+ static int user_to_new (struct v4l2_ext_control * c ,
13761392 struct v4l2_ctrl * ctrl )
13771393{
1378- u32 len ;
1379-
1380- if (ctrl -> is_ptr && !ctrl -> is_string )
1381- return copy_to_user (c -> ptr , ctrl -> p , ctrl -> elem_size );
1394+ return user_to_ptr (c , ctrl , ctrl -> p_new );
1395+ }
13821396
1397+ /* Copy the one value to another. */
1398+ static void ptr_to_ptr (struct v4l2_ctrl * ctrl ,
1399+ union v4l2_ctrl_ptr from , union v4l2_ctrl_ptr to )
1400+ {
1401+ if (ctrl == NULL )
1402+ return ;
13831403 switch (ctrl -> type ) {
13841404 case V4L2_CTRL_TYPE_STRING :
1385- len = strlen (ctrl -> string );
1386- if (c -> size < len + 1 ) {
1387- c -> size = ctrl -> maximum + 1 ;
1388- return - ENOSPC ;
1389- }
1390- return copy_to_user (c -> string , ctrl -> string ,
1391- len + 1 ) ? - EFAULT : 0 ;
1405+ /* strings are always 0-terminated */
1406+ strcpy (to .p_char , from .p_char );
1407+ break ;
13921408 case V4L2_CTRL_TYPE_INTEGER64 :
1393- c -> value64 = ctrl -> val64 ;
1409+ * to . p_s64 = * from . p_s64 ;
13941410 break ;
13951411 default :
1396- c -> value = ctrl -> val ;
1412+ if (ctrl -> is_ptr )
1413+ memcpy (to .p , from .p , ctrl -> elem_size );
1414+ else
1415+ * to .p_s32 = * from .p_s32 ;
13971416 break ;
13981417 }
1399- return 0 ;
14001418}
14011419
14021420/* Copy the new value to the current value. */
14031421static void new_to_cur (struct v4l2_fh * fh , struct v4l2_ctrl * ctrl , u32 ch_flags )
14041422{
1405- bool changed = false ;
1423+ bool changed ;
14061424
14071425 if (ctrl == NULL )
14081426 return ;
1427+ changed = !ctrl -> type_ops -> equal (ctrl , ctrl -> p_cur , ctrl -> p_new );
1428+ ptr_to_ptr (ctrl , ctrl -> p_new , ctrl -> p_cur );
14091429
1410- switch (ctrl -> type ) {
1411- case V4L2_CTRL_TYPE_BUTTON :
1412- changed = true;
1413- break ;
1414- case V4L2_CTRL_TYPE_STRING :
1415- /* strings are always 0-terminated */
1416- changed = strcmp (ctrl -> string , ctrl -> cur .string );
1417- strcpy (ctrl -> cur .string , ctrl -> string );
1418- break ;
1419- case V4L2_CTRL_TYPE_INTEGER64 :
1420- changed = ctrl -> val64 != ctrl -> cur .val64 ;
1421- ctrl -> cur .val64 = ctrl -> val64 ;
1422- break ;
1423- default :
1424- if (ctrl -> is_ptr ) {
1425- changed = memcmp (ctrl -> p , ctrl -> cur .p , ctrl -> elem_size );
1426- memcpy (ctrl -> cur .p , ctrl -> p , ctrl -> elem_size );
1427- } else {
1428- changed = ctrl -> val != ctrl -> cur .val ;
1429- ctrl -> cur .val = ctrl -> val ;
1430- }
1431- break ;
1432- }
14331430 if (ch_flags & V4L2_EVENT_CTRL_CH_FLAGS ) {
14341431 /* Note: CH_FLAGS is only set for auto clusters. */
14351432 ctrl -> flags &=
@@ -1458,21 +1455,7 @@ static void cur_to_new(struct v4l2_ctrl *ctrl)
14581455{
14591456 if (ctrl == NULL )
14601457 return ;
1461- switch (ctrl -> type ) {
1462- case V4L2_CTRL_TYPE_STRING :
1463- /* strings are always 0-terminated */
1464- strcpy (ctrl -> string , ctrl -> cur .string );
1465- break ;
1466- case V4L2_CTRL_TYPE_INTEGER64 :
1467- ctrl -> val64 = ctrl -> cur .val64 ;
1468- break ;
1469- default :
1470- if (ctrl -> is_ptr )
1471- memcpy (ctrl -> p , ctrl -> cur .p , ctrl -> elem_size );
1472- else
1473- ctrl -> val = ctrl -> cur .val ;
1474- break ;
1475- }
1458+ ptr_to_ptr (ctrl , ctrl -> p_cur , ctrl -> p_new );
14761459}
14771460
14781461/* Return non-zero if one or more of the controls in the cluster has a new
0 commit comments