From 96db4ef5ab3aa8ee17cb8fbefa82b7382deb903c Mon Sep 17 00:00:00 2001 From: Prateek Patel Date: Wed, 22 Dec 2021 05:06:17 +0000 Subject: [PATCH] tegra: hwpm: fix null check Coverity defect Null-checking inode suggests that it may be null, but it has already been dereferenced on path leading to the check. Fix it by adding the null check in correct sequence. CID 10127947 Bug 3461002 Change-Id: Ib9135bdb67c489fa52f5dda6725d3cbd1faddd1e Signed-off-by: Prateek Patel Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2645543 Tested-by: mobile promotions Reviewed-by: mobile promotions --- tegra-soc-hwpm-ioctl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tegra-soc-hwpm-ioctl.c b/tegra-soc-hwpm-ioctl.c index e442498..7b6372c 100644 --- a/tegra-soc-hwpm-ioctl.c +++ b/tegra-soc-hwpm-ioctl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2021-2022, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -530,7 +530,7 @@ end: static int tegra_soc_hwpm_open(struct inode *inode, struct file *filp) { int ret = 0; - unsigned int minor = iminor(inode); + unsigned int minor; struct tegra_soc_hwpm *hwpm = NULL; u32 i; @@ -542,6 +542,8 @@ static int tegra_soc_hwpm_open(struct inode *inode, struct file *filp) tegra_soc_hwpm_err("Invalid file"); return -EINVAL; } + + minor = iminor(inode); if (minor > 0) { tegra_soc_hwpm_err("Incorrect minor number"); return -EBADFD;