From 78df3dae46cfa978cab7f5ec0bae8a774b4650ea Mon Sep 17 00:00:00 2001 From: Naveen Kumar S Date: Thu, 23 Jul 2020 18:44:45 +0530 Subject: [PATCH] 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 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2394585 Tested-by: mobile promotions Reviewed-by: automaticguardword Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Shu Zhong Reviewed-by: Ujwal Patel Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit --- drivers/misc/tegra-cec/tegra_cec.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/misc/tegra-cec/tegra_cec.c b/drivers/misc/tegra-cec/tegra_cec.c index 2ddd86cc..b2c8b1a6 100644 --- a/drivers/misc/tegra-cec/tegra_cec.c +++ b/drivers/misc/tegra-cec/tegra_cec.c @@ -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)))