From acf8657b4c03ad6a74c79924baf7247a11aa0a51 Mon Sep 17 00:00:00 2001 From: Achal Verma Date: Wed, 12 May 2021 17:02:26 +0530 Subject: ahci: Fix potential NULL ptr dereference. This fixes coverity issue: 20360 Bug 200741055 Change-Id: I6bfdaf58b4d7d03a3c4edde6c229e9c1bc4164f7 Signed-off-by: Achal Verma Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2528439 Tested-by: Rahul Jain (SW-TEGRA) Reviewed-by: Rahul Jain (SW-TEGRA) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2575305 Tested-by: mobile promotions Reviewed-by: svc-mobile-coverity Reviewed-by: Phoenix Jung Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit --- drivers/ata/tegra/ahci_tegra.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/ata/tegra/ahci_tegra.c b/drivers/ata/tegra/ahci_tegra.c index cd2602a59..9033e8324 100644 --- a/drivers/ata/tegra/ahci_tegra.c +++ b/drivers/ata/tegra/ahci_tegra.c @@ -1412,16 +1412,25 @@ static int tegra_ahci_disable_features(struct ahci_host_priv *hpriv) static int tegra_ahci_quirks(struct ahci_host_priv *hpriv) { struct tegra_ahci_priv *tegra = hpriv->plat_data; - struct platform_device *pdev = tegra->pdev; - struct device *dev = &pdev->dev; - u32 t_satao_nvoob_comma_cnt_mask = - tegra->soc_data->reg.t_satao_nvoob_comma_cnt_mask; - u32 t_satao_nvoob_comma_cnt = - tegra->soc_data->reg.t_satao_nvoob_comma_cnt; + struct platform_device *pdev; + struct device *dev; + u32 t_satao_nvoob_comma_cnt_mask; + u32 t_satao_nvoob_comma_cnt; unsigned int val; unsigned int mask; int ret = 0; + if (tegra) { + pdev = tegra->pdev; + dev = &pdev->dev; + t_satao_nvoob_comma_cnt_mask = + tegra->soc_data->reg.t_satao_nvoob_comma_cnt_mask; + t_satao_nvoob_comma_cnt = + tegra->soc_data->reg.t_satao_nvoob_comma_cnt; + } else { + return -ENODEV; + } + /* SATA WARS */ /* For SQUELCH Filter & Gen3 drive getting detected as Gen1 drive */ @@ -1443,7 +1452,7 @@ static int tegra_ahci_quirks(struct ahci_host_priv *hpriv) val = T_SATA0_CFG2NVOOB_2_COMWAKE_IDLE_CNT_LOW; tegra_ahci_scfg_update(hpriv, val, mask, T_SATA0_CFG2NVOOB_2); - if (tegra && tegra->prod_list) { + if (tegra->prod_list) { tegra_ahci_scfg_writel(hpriv, T_SATA0_INDEX_CH1, T_SATA0_INDEX); ret = tegra_prod_set_by_name(tegra->base_list, "prod", tegra->prod_list); -- cgit v1.2.2