misc: tegra-cec: fix access_ok() API's parameters

This change fixes below follow-up issues with the earlier fix
to access_ok() API done as part of
https://git-master.nvidia.com/r/c/linux-nvidia/+/2361042:

1. Definition of VERIFY_READ and VERIFY_WRITE have been removed
after K4.14. Hence, used them only for kernel versions < K5.4.
2. Changed access_type parameter of tegra_cec_access_ok() API
to bool. WRITE or READ will be chosen based on the bool value.
3. In the last CL, VERIFY_WRITE was changed to VERIFY_READ in
two access_ok() calls by mistake. Corrected them in this CL.
4. Defined access_type variable with attribute __maybe_unused
since gcc doesn't seem to consider a variable as used if only
passed as function parameter.

bug 200601926

Change-Id: I9f3540cd028280ca679b4b69d5b4a72aa943b2ae
Signed-off-by: Naveen Kumar S <nkumars@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2394585
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Reviewed-by: automaticguardword <automaticguardword@nvidia.com>
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Shu Zhong <shuz@nvidia.com>
Reviewed-by: Ujwal Patel <ujwalp@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
GVS: Gerrit_Virtual_Submit
This commit is contained in:
Naveen Kumar S
2020-07-23 18:44:45 +05:30
committed by Prafull Suryawanshi
parent 80d0f3b9fa
commit b55afecfc2

View File

@@ -361,11 +361,12 @@ static int tegra_cec_get_rx_snoop(struct tegra_cec *cec, u32 *state)
return 0;
}
static int tegra_cec_access_ok(u8 access_type, unsigned long arg, size_t size)
static int tegra_cec_access_ok(bool write, unsigned long arg, size_t size)
{
int err = 0;
#if KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE
u8 __maybe_unused access_type = write ? VERIFY_WRITE : VERIFY_READ;
err = !access_ok(access_type, arg, size);
#else
err = !access_ok((void *)arg, size);
@@ -395,7 +396,7 @@ static long tegra_cec_ioctl(struct file *file, unsigned int cmd,
tegra_cec_dump_registers(cec);
break;
case TEGRA_CEC_IOCTL_SET_RX_SNOOP:
err = tegra_cec_access_ok(VERIFY_READ, arg, sizeof(u32));
err = tegra_cec_access_ok(false, arg, sizeof(u32));
if (err)
return -EFAULT;
if (copy_from_user((u32 *) &state, (u32 *) arg, sizeof(u32)))
@@ -403,7 +404,7 @@ static long tegra_cec_ioctl(struct file *file, unsigned int cmd,
tegra_cec_set_rx_snoop(cec, state);
break;
case TEGRA_CEC_IOCTL_GET_RX_SNOOP:
err = tegra_cec_access_ok(VERIFY_READ, arg, sizeof(u32));
err = tegra_cec_access_ok(true, arg, sizeof(u32));
if (err)
return -EFAULT;
err = tegra_cec_get_rx_snoop(cec, &state);
@@ -413,7 +414,7 @@ static long tegra_cec_ioctl(struct file *file, unsigned int cmd,
}
break;
case TEGRA_CEC_IOCTL_GET_POST_RECOVERY:
err = tegra_cec_access_ok(VERIFY_READ, arg, sizeof(u32));
err = tegra_cec_access_ok(true, arg, sizeof(u32));
if (err)
return -EFAULT;
if (copy_to_user((bool *) arg, &post_recovery, sizeof(bool)))