iommu/mediatek: Remove a unnecessary checking for larbid
Subsystems (3)
Yong Wu
maintainerPATCH 1/1 iommu/mediatek: Remove a unnecessary checking for larbid
Fix a coverity issue:
Quoted 1 line
Quoted 1 line
assignment: Assigning: larbid = (fwspec->ids[0] >> 5) &
0x1fU.
larbid = MTK_M4U_TO_LARB(fwspec->ids[0]);
Quoted 3 lines
Quoted 3 lines
between: At condition larbid >= 32U, the value of larbid must be between 0 and 31.
dead_error_condition: The condition larbid >= 32U cannot be true.
if (larbid >= MTK_LARB_NR_MAX)
Quoted 3 lines
Quoted 3 lines
CID 11306470 (#1 of 1): Logically dead code (DEADCODE)
dead_error_line: Execution cannot reach this statement:
returnERR_PTR(-22L);
return ERR_PTR(-EINVAL);
The checking "if (larbid >= MTK_LARB_NR_MAX)" is unnecessary.
---
Rebase on v6.4-rc1.
--- drivers/iommu/mtk_iommu.c | 3 --- 1 file changed, 3 deletions(-)
drivers/iommu/mtk_iommu.c +0 -3
@@ -838,9 +838,6 @@ static struct iommu_device *mtk_iommu_probe_device(struct device *dev)* All the ports in each a device should be in the same larbs. */ larbid =MTK_M4U_TO_LARB (fwspec->ids[0 ]); -if (larbid >=MTK_LARB_NR_MAX ) -return ERR_PTR (-EINVAL ); -for (i =1 ; i < fwspec->num_ids; i++) { larbidx =MTK_M4U_TO_LARB (fwspec->ids[i]);if (larbid != larbidx) {
Signature · 1 line
2.25.1
AngeloGioacchino Del Regno
maintainerIl 04/07/23 13:56, Yong Wu ha scritto:
Quoted 7 lines
Fix a coverity issue:
Quoted 1 line
Quoted 1 line
assignment: Assigning: larbid = (fwspec->ids[0] >> 5) &
0x1fU.larbid = MTK_M4U_TO_LARB(fwspec->ids[0]);Quoted 3 lines
Quoted 3 lines
between: At condition larbid >= 32U, the value of larbid must be between 0 and 31.
dead_error_condition: The condition larbid >= 32U cannot be true.
Quoted 8 lines
if (larbid >=
MTK_LARB_NR_MAX)Quoted 3 lines
Quoted 3 lines
CID 11306470 (#1 of 1): Logically dead code (DEADCODE)
dead_error_line: Execution cannot reach this statement:
returnERR_PTR(-22L);return ERR_PTR(-EINVAL);The checking "if (larbid >=
MTK_LARB_NR_MAX)" is unnecessary.
I agree with the coverity tool in that after the transformation (going through the definition of MTK_M4U_TO_LARB) the check is pointless, but I think that the right fix here is to check for validity of fwspec->ids[0] instead of simply removing validation.
Having no validation after mtk_iommu_probe_device() is fine, but that's because we assume that *this* function performs all validation steps.
Regards,
Angelo
Quoted 21 lines
Signed-off-by Yong Wu <[email protected]>---
Rebase on v6.4-rc1.--- drivers/iommu/mtk_iommu.c | 3 --- 1 file changed, 3 deletions(-)drivers/iommu/mtk_iommu.c +0
-3@@ -838,9 +838,6 @@ static struct iommu_device *mtk_iommu_probe_device(struct device *dev)* All the ports in each a device should be in the same larbs. */ larbid =MTK_M4U_TO_LARB (fwspec->ids[0 ]); -if (larbid >=MTK_LARB_NR_MAX ) -return ERR_PTR (-EINVAL ); -for (i =1 ; i < fwspec->num_ids; i++) { larbidx =MTK_M4U_TO_LARB (fwspec->ids[i]);if (larbid != larbidx) {
Yong Wu (吴勇)
maintainerQuoted 29 lines · AngeloGioacchino Del Regno
External email : Please do not click links or open attachments until you have verified the sender or the content.
Il 04/07/23 13:56, Yong Wu ha scritto:Quoted 5 lines
Fix a coverity issue:
Quoted 1 line
Quoted 1 line
assignment: Assigning: larbid = (fwspec->ids[0] >> 5) &
0x1fU.larbid =
MTK_M4U_TO_LARB(fwspec->ids[0]);Quoted 1 line
Quoted 1 line
between: At condition larbid >= 32U, the value of larbid must be
between
Quoted 10 lines
Quoted 2 lines
Quoted 2 lines
0 and 31.
dead_error_condition: The condition larbid >= 32U cannot be true.if (larbid >=
MTK_LARB_NR_MAX)Quoted 3 lines
Quoted 3 lines
CID 11306470 (#1 of 1): Logically dead code (DEADCODE)
dead_error_line: Execution cannot reach this statement:
returnERR_PTR(-22L);return ERR_PTR(-EINVAL);The checking "if (larbid >=
MTK_LARB_NR_MAX)" is unnecessary.I agree with the coverity tool in that after the transformation (going through
the definition ofMTK_M4U_TO_LARB) the check is pointless, but I think that the
right fix here is to check for validity of fwspec->ids[0] instead of simply
removing validation.
Quoted 3 lines
Having no validation after
mtk_iommu_probe_device()is fine, but that's
because we assume that *this* function performs all validation steps.
There already is validation code at the point later in this function.
"if (!larbdev) return ERR_PTR(-EINVAL);" //if the larbid is invalid.
This patch just removes a deadcode.
Quoted 28 lines
Regards,
Angelodrivers/iommu/mtk_iommu.c static struct iommu_device
Quoted 12 lines
Signed-off-by Yong Wu <[email protected]>---
Rebase on v6.4-rc1.--- drivers/iommu/mtk_iommu.c | 3 --- 1 file changed, 3 deletions(-)drivers/iommu/mtk_iommu.c +0
-0@@ -838,9 +838,6 @@ static struct iommu_device*mtk_iommu_probe_device(struct device *dev)
Quoted 9 lines
drivers/iommu/mtk_iommu.c +0
-3* All the ports in each a device should be in the same larbs. */ larbid =MTK_M4U_TO_LARB (fwspec->ids[0 ]); -if (larbid >=MTK_LARB_NR_MAX ) -return ERR_PTR (-EINVAL ); -for (i =1 ; i < fwspec->num_ids; i++) { larbidx =MTK_M4U_TO_LARB (fwspec->ids[i]);if (larbid != larbidx) {
Quoted 34 lines · Yong Wu (吴勇)
Quoted 29 lines · AngeloGioacchino Del Regno
External email : Please do not click links or open attachments until you have verified the sender or the content.
Il 04/07/23 13:56, Yong Wu ha scritto:Quoted 5 lines
Fix a coverity issue:
Quoted 1 line
Quoted 1 line
assignment: Assigning: larbid = (fwspec->ids[0] >> 5) &
0x1fU.larbid =
MTK_M4U_TO_LARB(fwspec->ids[0]);Quoted 1 line
Quoted 1 line
between: At condition larbid >= 32U, the value of larbid must be
between
Quoted 10 lines
Quoted 2 lines
Quoted 2 lines
0 and 31.
dead_error_condition: The condition larbid >= 32U cannot be true.if (larbid >=
MTK_LARB_NR_MAX)Quoted 3 lines
Quoted 3 lines
CID 11306470 (#1 of 1): Logically dead code (DEADCODE)
dead_error_line: Execution cannot reach this statement:
returnERR_PTR(-22L);return ERR_PTR(-EINVAL);The checking "if (larbid >=
MTK_LARB_NR_MAX)" is unnecessary.I agree with the coverity tool in that after the transformation (going through
the definition ofMTK_M4U_TO_LARB) the check is pointless, but I think that the
right fix here is to check for validity of fwspec->ids[0] instead of simply
removing validation.Quoted 3 lines
Having no validation after
mtk_iommu_probe_device()is fine, but that's
because we assume that *this* function performs all validation steps.
Quoted 5 lines
There already is validation code at the point later in this function.
"if (!larbdev) return
ERR_PTR(-EINVAL);" //if the larbid is invalid.This patch just removes a deadcode.
Right, if the fwspec value was out of range then the truncated value might happen to map to a valid LARB, but then the fwspec could equally have an in-range value for a valid (but incorrect) LARB; in general a driver can't validate the overall correctness of data from the DT (and if it could, that data wouldn't need to be in the DT anyway).
From the history, the intent of this check doesn't appear to have been anything other than protecting the dereference of the data->larb_imu array, and it's never had any functional effect, so we don't lose anything by removing it. FWIW,
Cheers,
Robin.
Quoted 29 lines
Quoted 29 lines
Regards,
Angelodrivers/iommu/mtk_iommu.c static struct iommu_device
Quoted 12 lines
Signed-off-by Yong Wu <[email protected]>---
Rebase on v6.4-rc1.--- drivers/iommu/mtk_iommu.c | 3 --- 1 file changed, 3 deletions(-)drivers/iommu/mtk_iommu.c +0
-0@@ -838,9 +838,6 @@ static struct iommu_device*mtk_iommu_probe_device(struct device *dev)
Quoted 9 lines
drivers/iommu/mtk_iommu.c +0
-3* All the ports in each a device should be in the same larbs. */ larbid =MTK_M4U_TO_LARB (fwspec->ids[0 ]); -if (larbid >=MTK_LARB_NR_MAX ) -return ERR_PTR (-EINVAL ); -for (i =1 ; i < fwspec->num_ids; i++) { larbidx =MTK_M4U_TO_LARB (fwspec->ids[i]);if (larbid != larbidx) {
Il 05/07/23 10:26, Robin Murphy ha scritto:
Quoted 39 lines · Yong Wu (吴勇)
Quoted 38 lines · AngeloGioacchino Del Regno
Quoted 29 lines
External email : Please do not click links or open attachments until you have verified the sender or the content.
Il 04/07/23 13:56, Yong Wu ha scritto:Quoted 5 lines
Fix a coverity issue:
Quoted 1 line
Quoted 1 line
assignment: Assigning: larbid = (fwspec->ids[0] >> 5) &
0x1fU.larbid =
MTK_M4U_TO_LARB(fwspec->ids[0]);Quoted 1 line
Quoted 1 line
between: At condition larbid >= 32U, the value of larbid must be
between
Quoted 10 lines
Quoted 2 lines
Quoted 2 lines
0 and 31.
dead_error_condition: The condition larbid >= 32U cannot be true.if (larbid >=
MTK_LARB_NR_MAX)Quoted 3 lines
Quoted 3 lines
CID 11306470 (#1 of 1): Logically dead code (DEADCODE)
dead_error_line: Execution cannot reach this statement:
returnERR_PTR(-22L);return
ERR_PTR(-EINVAL);The checking "if (larbid >=
MTK_LARB_NR_MAX)" is unnecessary.I agree with the coverity tool in that after the transformation (going through
the definition ofMTK_M4U_TO_LARB) the check is pointless, but I think that the
right fix here is to check for validity of fwspec->ids[0] instead of simply
removing validation.Quoted 3 lines
Having no validation after
mtk_iommu_probe_device()is fine, but that's
because we assume that *this* function performs all validation steps.There already is validation code at the point later in this function.
"if (!larbdev) return
ERR_PTR(-EINVAL);" //if the larbid is invalid.
Quoted 9 lines
Quoted 1 line
This patch just removes a deadcode.
Right, if the fwspec value was out of range then the truncated value might happen to map to a valid LARB, but then the fwspec could equally have an in-range value for a valid (but incorrect) LARB; in general a driver can't validate the overall correctness of data from the DT (and if it could, that data wouldn't need to be in the DT anyway).
From the history, the intent of this check doesn't appear to have been anything
other than protecting the dereference of thedata->larb_imuarray, and it's never had any functional effect, so we don't lose anything by removing it. FWIW,Reviewed-by Robin Murphy <[email protected]>
Yong, you're right. My bad for not noticing the later validation code.
Quoted 32 lines
Cheers,
Robin.Quoted 29 lines
Quoted 29 lines
Regards,
Angelodrivers/iommu/mtk_iommu.c static struct iommu_device
Quoted 12 lines
Signed-off-by Yong Wu <[email protected]>---
Rebase on v6.4-rc1.
---
drivers/iommu/mtk_iommu.c| 3 ---1 file changed, 3 deletions(-)drivers/iommu/mtk_iommu.c +0
-0@@ -838,9 +838,6 @@ static struct iommu_device*mtk_iommu_probe_device(struct device *dev)
Quoted 9 lines
drivers/iommu/mtk_iommu.c +0
-3* All the ports in each a device should be in the same larbs. */ larbid = MTK_M4U_TO_LARB(fwspec->ids[0]); -if (larbid >=MTK_LARB_NR_MAX ) -return ERR_PTR (-EINVAL ); - for (i = 1; i < fwspec->num_ids; i++) { larbidx = MTK_M4U_TO_LARB(fwspec->ids[i]); if (larbid != larbidx) {