Skip to content

[PATCH] iommu/mediatek-v1: Fix off-by-one in MT2701_LARB_NR_MAX#58

Draft
akku1139 wants to merge 1 commit into
mainlinefrom
patch/mt2701-larb-nr-max
Draft

[PATCH] iommu/mediatek-v1: Fix off-by-one in MT2701_LARB_NR_MAX#58
akku1139 wants to merge 1 commit into
mainlinefrom
patch/mt2701-larb-nr-max

Conversation

@akku1139

Copy link
Copy Markdown
Member

The mt2701_m4u_in_larb[] array contains 4 (for LARB0 to LARB3) elements, meaning mt2701_m4u_to_larb() can legitimately return 3. The current check if (larbid >= MT2701_LARB_NR_MAX) incorrectly rejects valid LARB3 with -EINVAL.

Fix this off-by-one error by updating MT2701_LARB_NR_MAX to 4.

Note that this does not cause immediate issues with the current mt2701.dtsi and mt7623n.dtsi because it only defines 3 LARBs:
mediatek,larbs = <&larb0 &larb1 &larb2>;
Thus, larbid never reaches 3 in the existing upstream device tree.

Fixes: de78657 ("iommu/mediatek: Fix NULL pointer dereference when printing dev_name")

The mt2701_m4u_in_larb[] array contains 4 (for LARB0 to LARB3)
elements, meaning mt2701_m4u_to_larb() can legitimately return 3.
The current check `if (larbid >= MT2701_LARB_NR_MAX)` incorrectly
rejects valid LARB3 with -EINVAL.

Fix this off-by-one error by updating MT2701_LARB_NR_MAX to 4.

Note that this does not cause immediate issues with the current
mt2701.dtsi and mt7623n.dtsi because it only defines 3 LARBs:
    mediatek,larbs = <&larb0 &larb1 &larb2>;
Thus, larbid never reaches 3 in the existing upstream device tree.

Fixes: de78657 ("iommu/mediatek: Fix NULL pointer dereference when printing dev_name")
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
@akku1139 akku1139 added the PATCH label Jun 29, 2026
@akku1139

akku1139 commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

@akku1139 akku1139 added the Bug label Jun 29, 2026
@akku1139 akku1139 changed the title iommu/mediatek-v1: Fix off-by-one in MT2701_LARB_NR_MAX [PATCH] iommu/mediatek-v1: Fix off-by-one in MT2701_LARB_NR_MAX Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant