Skip to contentSkip to conversation

drm/vc4: hdmi: Fix off by ones in vc4_hdmi_read/write()

PATCH Applied Dan Carpenter 2 participants 2 messages Sep 10, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/vc4: hdmi: Fix off by ones in vc4_hdmi_read/write()

The variant->registers[] has ->num_registers elements so the > comparison needs to be changes to >= to prevent an out of bounds access.

Fixes 311e305fdb4e ("drm/vc4: hdmi: Implement a register layout abstraction")
---
 drivers/gpu/drm/vc4/vc4_hdmi_regs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vc4/vc4_hdmi_regs.h +2 -2
index a5f1354e3e06..47364bd3960d 100644
@@ -398,7 +398,7 @@ static inline u32 vc4_hdmi_read(struct vc4_hdmi *hdmi,
 	const struct vc4_hdmi_variant *variant = hdmi->variant;
 	void __iomem *base;
 
-	if (reg > variant->num_registers) {
+	if (reg >= variant->num_registers) {
 		dev_warn(&hdmi->pdev->dev,
 			 "Invalid register ID %u\n", reg);
 		return 0;
@@ -424,7 +424,7 @@ static inline void vc4_hdmi_write(struct vc4_hdmi *hdmi,
 	const struct vc4_hdmi_variant *variant = hdmi->variant;
 	void __iomem *base;
 
-	if (reg > variant->num_registers) {
+	if (reg >= variant->num_registers) {
 		dev_warn(&hdmi->pdev->dev,
 			 "Invalid register ID %u\n", reg);
 		return;
Signature · 1 line
2.28.0
#1 lore raw
Quoted 6 lines · Dan Carpenter

The variant->registers[] has ->num_registers elements so the > comparison needs to be changes to >= to prevent an out of bounds access.

Fixes 311e305fdb4e ("drm/vc4: hdmi: Implement a register layout abstraction")

Applied, thanks!
Maxime