[PATCH net 1/2] net: stmmac: est: Fix GCL bounds checks

Rohan G Thomas via B4 Relay posted 2 patches 3 weeks ago
There is a newer version of this series
[PATCH net 1/2] net: stmmac: est: Fix GCL bounds checks
Posted by Rohan G Thomas via B4 Relay 3 weeks ago
From: Rohan G Thomas <rohan.g.thomas@intel.com>

Fix the bounds checks for the hw supported maximum GCL entry
count and gate interval time.

Fixes: b60189e0392f ("net: stmmac: Integrate EST with TAPRIO scheduler API")
Signed-off-by: Rohan G Thomas <rohan.g.thomas@intel.com>
Reviewed-by: Matthew Gerlach <matthew.gerlach@altera.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
index 694d6ee1438197bd4434af6e9b78f022e94ff98f..89d094abb6be5c993c81901e3f79a6b03f310511 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
@@ -981,7 +981,7 @@ static int tc_taprio_configure(struct stmmac_priv *priv,
 	if (qopt->cmd == TAPRIO_CMD_DESTROY)
 		goto disable;
 
-	if (qopt->num_entries >= dep)
+	if (qopt->num_entries > dep)
 		return -EINVAL;
 	if (!qopt->cycle_time)
 		return -ERANGE;
@@ -1012,7 +1012,7 @@ static int tc_taprio_configure(struct stmmac_priv *priv,
 		s64 delta_ns = qopt->entries[i].interval;
 		u32 gates = qopt->entries[i].gate_mask;
 
-		if (delta_ns > GENMASK(wid, 0))
+		if (delta_ns >= BIT(wid))
 			return -ERANGE;
 		if (gates > GENMASK(31 - wid, 0))
 			return -ERANGE;

-- 
2.25.1
Re: [PATCH net 1/2] net: stmmac: est: Fix GCL bounds checks
Posted by Russell King (Oracle) 3 weeks ago
On Thu, Sep 11, 2025 at 04:22:59PM +0800, Rohan G Thomas via B4 Relay wrote:
> @@ -1012,7 +1012,7 @@ static int tc_taprio_configure(struct stmmac_priv *priv,
>  		s64 delta_ns = qopt->entries[i].interval;
>  		u32 gates = qopt->entries[i].gate_mask;
>  
> -		if (delta_ns > GENMASK(wid, 0))
> +		if (delta_ns >= BIT(wid))

While I agree this makes it look better, you don't change the version
below, which makes the code inconsistent. I also don't see anything
wrong with the original comparison.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [PATCH net 1/2] net: stmmac: est: Fix GCL bounds checks
Posted by G Thomas, Rohan 3 weeks ago
Hi Russell,

Thanks for reviewing the patch.

On 9/11/2025 4:54 PM, Russell King (Oracle) wrote:
> On Thu, Sep 11, 2025 at 04:22:59PM +0800, Rohan G Thomas via B4 Relay wrote:
>> @@ -1012,7 +1012,7 @@ static int tc_taprio_configure(struct stmmac_priv *priv,
>>   		s64 delta_ns = qopt->entries[i].interval;
>>   		u32 gates = qopt->entries[i].gate_mask;
>>   
>> -		if (delta_ns > GENMASK(wid, 0))
>> +		if (delta_ns >= BIT(wid))
> 
> While I agree this makes it look better, you don't change the version
> below, which makes the code inconsistent. I also don't see anything
> wrong with the original comparison.

Just to clarify the intent behind this change:
For example, if wid = 3, then GENMASK(3, 0) = 0b1111 = 15. But the
maximum supported gate interval in this case is actually 7, since only 3
bits are available to represent the value. So in the patch, the
condition delta_ns >= BIT(wid) effectively checks if delta_ns is 8 or
more, which correctly returns an error for values that exceed the 3-bit
limit.

> Best Regards,
Rohan
Re: [PATCH net 1/2] net: stmmac: est: Fix GCL bounds checks
Posted by Jakub Kicinski 2 weeks, 6 days ago
On Thu, 11 Sep 2025 18:12:16 +0530 G Thomas, Rohan wrote:
> On 9/11/2025 4:54 PM, Russell King (Oracle) wrote:
> > On Thu, Sep 11, 2025 at 04:22:59PM +0800, Rohan G Thomas via B4 Relay wrote:  
> >> @@ -1012,7 +1012,7 @@ static int tc_taprio_configure(struct stmmac_priv *priv,
> >>   		s64 delta_ns = qopt->entries[i].interval;
> >>   		u32 gates = qopt->entries[i].gate_mask;
> >>   
> >> -		if (delta_ns > GENMASK(wid, 0))
> >> +		if (delta_ns >= BIT(wid))  
> > 
> > While I agree this makes it look better, you don't change the version
> > below, which makes the code inconsistent. I also don't see anything
> > wrong with the original comparison.  
> 
> Just to clarify the intent behind this change:
> For example, if wid = 3, then GENMASK(3, 0) = 0b1111 = 15. But the
> maximum supported gate interval in this case is actually 7, since only 3
> bits are available to represent the value. So in the patch, the
> condition delta_ns >= BIT(wid) effectively checks if delta_ns is 8 or
> more, which correctly returns an error for values that exceed the 3-bit
> limit.

Comparison to BIT() looks rather odd, I think it's better to correct
the GENMASK() bound?
Re: [PATCH net 1/2] net: stmmac: est: Fix GCL bounds checks
Posted by G Thomas, Rohan 2 weeks, 6 days ago
Hi Jakub,

Thanks for reviewing the patch.

On 9/12/2025 5:31 AM, Jakub Kicinski wrote:
> On Thu, 11 Sep 2025 18:12:16 +0530 G Thomas, Rohan wrote:
>> On 9/11/2025 4:54 PM, Russell King (Oracle) wrote:
>>> On Thu, Sep 11, 2025 at 04:22:59PM +0800, Rohan G Thomas via B4 Relay wrote:
>>>> @@ -1012,7 +1012,7 @@ static int tc_taprio_configure(struct stmmac_priv *priv,
>>>>    		s64 delta_ns = qopt->entries[i].interval;
>>>>    		u32 gates = qopt->entries[i].gate_mask;
>>>>    
>>>> -		if (delta_ns > GENMASK(wid, 0))
>>>> +		if (delta_ns >= BIT(wid))
>>>
>>> While I agree this makes it look better, you don't change the version
>>> below, which makes the code inconsistent. I also don't see anything
>>> wrong with the original comparison.
>>
>> Just to clarify the intent behind this change:
>> For example, if wid = 3, then GENMASK(3, 0) = 0b1111 = 15. But the
>> maximum supported gate interval in this case is actually 7, since only 3
>> bits are available to represent the value. So in the patch, the
>> condition delta_ns >= BIT(wid) effectively checks if delta_ns is 8 or
>> more, which correctly returns an error for values that exceed the 3-bit
>> limit.
> 
> Comparison to BIT() looks rather odd, I think it's better to correct
> the GENMASK() bound?

Sure I'll update the condition to use GENMASK(wid - 1, 0) in the next
version. That should make the logic consistent with the checks below.

Best Regards,
Rohan