* [PATCH net] net: dlink: mask rx_coalesce/rx_timeout before writing RxDMAIntCtrl
@ 2025-12-23 0:10 Yeounsu Moon
2025-12-23 9:43 ` Andrew Lunn
0 siblings, 1 reply; 5+ messages in thread
From: Yeounsu Moon @ 2025-12-23 0:10 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: netdev, linux-kernel, 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.
Found by inspection.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Tested-on: D-Link DGE-550T Rev-A3
Signed-off-by: Yeounsu Moon <yyyynoom@gmail.com>
---
drivers/net/ethernet/dlink/dl2k.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/dlink/dl2k.c b/drivers/net/ethernet/dlink/dl2k.c
index 846d58c769ea..f6ec0e4689f7 100644
--- a/drivers/net/ethernet/dlink/dl2k.c
+++ b/drivers/net/ethernet/dlink/dl2k.c
@@ -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);
--
2.52.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: dlink: mask rx_coalesce/rx_timeout before writing RxDMAIntCtrl
2025-12-23 0:10 [PATCH net] net: dlink: mask rx_coalesce/rx_timeout before writing RxDMAIntCtrl Yeounsu Moon
@ 2025-12-23 9:43 ` Andrew Lunn
2025-12-27 8:55 ` Yeounsu Moon
2025-12-30 10:57 ` Paolo Abeni
0 siblings, 2 replies; 5+ messages in thread
From: Andrew Lunn @ 2025-12-23 9:43 UTC (permalink / raw)
To: Yeounsu Moon
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel
On Tue, Dec 23, 2025 at 09:10:06AM +0900, Yeounsu Moon wrote:
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: dlink: mask rx_coalesce/rx_timeout before writing RxDMAIntCtrl
2025-12-23 9:43 ` Andrew Lunn
@ 2025-12-27 8:55 ` Yeounsu Moon
2025-12-30 10:57 ` Paolo Abeni
1 sibling, 0 replies; 5+ messages in thread
From: Yeounsu Moon @ 2025-12-27 8:55 UTC (permalink / raw)
To: Andrew Lunn, Yeounsu Moon
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel
Hi Andrew,
Sorry for the late reply. I recently started a new job and have been
busy.
On Tue Dec 23, 2025 at 6:43 PM KST, Andrew Lunn wrote:
>
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: dlink: mask rx_coalesce/rx_timeout before writing RxDMAIntCtrl
2025-12-23 9:43 ` Andrew Lunn
2025-12-27 8:55 ` Yeounsu Moon
@ 2025-12-30 10:57 ` Paolo Abeni
2026-01-03 9:26 ` Yeounsu Moon
1 sibling, 1 reply; 5+ messages in thread
From: Paolo Abeni @ 2025-12-30 10:57 UTC (permalink / raw)
To: Andrew Lunn, Yeounsu Moon
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, linux-kernel
On 12/23/25 10:43 AM, Andrew Lunn wrote:
> On Tue, Dec 23, 2025 at 09:10:06AM +0900, Yeounsu Moon wrote:
>> 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.
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: dlink: mask rx_coalesce/rx_timeout before writing RxDMAIntCtrl
2025-12-30 10:57 ` Paolo Abeni
@ 2026-01-03 9:26 ` Yeounsu Moon
0 siblings, 0 replies; 5+ messages in thread
From: Yeounsu Moon @ 2026-01-03 9:26 UTC (permalink / raw)
To: Paolo Abeni, Andrew Lunn, Yeounsu Moon
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, linux-kernel
On Tue Dec 30, 2025 at 7:57 PM KST, Paolo Abeni wrote:
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-01-03 9:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-23 0:10 [PATCH net] net: dlink: mask rx_coalesce/rx_timeout before writing RxDMAIntCtrl Yeounsu Moon
2025-12-23 9:43 ` Andrew Lunn
2025-12-27 8:55 ` Yeounsu Moon
2025-12-30 10:57 ` Paolo Abeni
2026-01-03 9:26 ` Yeounsu Moon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).