Skip to contentSkip to conversation

net: dlink: mask rx_coalesce/rx_timeout before writing RxDMAIntCtrl

PATCH Superseded Yeounsu Moon 3 participants 5 messages Dec 23, 2025 – Jan 3

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: dlink: mask rx_coalesce/rx_timeout before writing RxDMAIntCtrl

RxDMAIntCtrl encodes rx_coalesce in the low 16 bits and rx_timeout in the high 16 bits. If either value exceeds the field width, the current code may truncate the value and/or corrupt adjacent bits when programming the register.

Mask both values to 16 bits and cast to u32 before shifting so only the intended fields are written.

Found by inspection.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

Tested-on: D-Link DGE-550T Rev-A3

---
 drivers/net/ethernet/dlink/dl2k.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/dlink/dl2k.c +2 -1
index 846d58c769ea..f6ec0e4689f7 100644
@@ -590,7 +590,8 @@ static void rio_hw_init(struct net_device *dev)
 
 	set_multicast (dev);
 	if (np->coalesce) {
-		dw32(RxDMAIntCtrl, np->rx_coalesce | np->rx_timeout << 16);
+		dw32(RxDMAIntCtrl, ((u32)np->rx_coalesce & 0x0000ffff) |
+				   (((u32)np->rx_timeout & 0x0000ffff) << 16));
 	}
 	/* Set RIO to poll every N*320nsec. */
 	dw8(RxDMAPollPeriod, 0x20);
Signature · 1 line
2.52.0
#1 lore raw
Quoted 7 lines · Yeounsu Moon

RxDMAIntCtrl encodes rx_coalesce in the low 16 bits and rx_timeout in the high 16 bits. If either value exceeds the field width, the current code may truncate the value and/or corrupt adjacent bits when programming the register.

Mask both values to 16 bits and cast to u32 before shifting so only the intended fields are written.

It would be better to do range checks in rio_probe1() and call netdev_err() and return -EINVAL?

Anybody trying to use very large values then gets an error message rather than it working, but not as expected.

Andrew

#2 lore raw

Hi Andrew,

Sorry for the late reply. I recently started a new job and have been busy.

Quoted 7 lines · Andrew Lunn

It would be better to do range checks in rio_probe1() and call netdev_err() and return -EINVAL?

Anybody trying to use very large values then gets an error message rather than it working, but not as expected.

I was planning to add the range checks in rio_probe1() in the next merge window to keep this patch small, but I agree it's better to include them now. I'll send a v2 with the checks added.

Thanks for the review.

Yeounsu Moon

maintainer
#3 lore raw
In reply to Andrew Lunn
Quoted 6 lines · Andrew Lunn
Quoted 5 lines · Yeounsu Moon

RxDMAIntCtrl encodes rx_coalesce in the low 16 bits and rx_timeout in the high 16 bits. If either value exceeds the field width, the current code may truncate the value and/or corrupt adjacent bits when programming the register.

Quoted 8 lines
Quoted 2 lines

Mask both values to 16 bits and cast to u32 before shifting so only the intended fields are written.

It would be better to do range checks in rio_probe1() and call netdev_err() and return -EINVAL?

Anybody trying to use very large values then gets an error message rather than it working, but not as expected.

I'm not sure we can do such change: any eventual user with bad setting will get a broken setup after kernel update. I think we should avoid such regression, and use something similar to this patch.

@Yeounsu: the type cast in the current patch is not needed, please drop it, thanks!

Paolo

#4 lore raw
Quoted 8 lines · Paolo Abeni

I'm not sure we can do such change: any eventual user with bad setting will get a broken setup after kernel update. I think we should avoid such regression, and use something similar to this patch.

@Yeounsu: the type cast in the current patch is not needed, please drop it, thanks!

Paolo

Thank you for the review. I'll send v2 patch as suggested.

Separately, I agree with Andrew that it would be useful to alert users when an invalid value is provided. Would it be OK to send a net-next follow-up that warns (via netdev_warn()) when rx_coalesce or rx_timeout exceeds 16 bits, while keeping the current behavior (no -EINVAL)?

Yeounsu Moon