[PATCH net-next v6 2/3] net: dsa: yt921x: Return early for failed MIB read

David Yang posted 3 patches 3 weeks ago
There is a newer version of this series
[PATCH net-next v6 2/3] net: dsa: yt921x: Return early for failed MIB read
Posted by David Yang 3 weeks ago
This patch does not change anything effectively, but serves as a
prerequisite for another patch.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/yt921x.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/net/dsa/yt921x.c b/drivers/net/dsa/yt921x.c
index 5e4e8093ba16..fe08385445d2 100644
--- a/drivers/net/dsa/yt921x.c
+++ b/drivers/net/dsa/yt921x.c
@@ -707,6 +707,12 @@ static int yt921x_read_mib(struct yt921x_priv *priv, int port)
 		WRITE_ONCE(*valp, val);
 	}
 
+	if (res) {
+		dev_err(dev, "Failed to %s port %d: %i\n", "read stats for",
+			port, res);
+		return res;
+	}
+
 	pp->rx_frames = mib->rx_64byte + mib->rx_65_127byte +
 			mib->rx_128_255byte + mib->rx_256_511byte +
 			mib->rx_512_1023byte + mib->rx_1024_1518byte +
@@ -716,10 +722,7 @@ static int yt921x_read_mib(struct yt921x_priv *priv, int port)
 			mib->tx_512_1023byte + mib->tx_1024_1518byte +
 			mib->tx_jumbo;
 
-	if (res)
-		dev_err(dev, "Failed to %s port %d: %i\n", "read stats for",
-			port, res);
-	return res;
+	return 0;
 }
 
 static void yt921x_poll_mib(struct work_struct *work)
-- 
2.51.0
Re: [PATCH net-next v6 2/3] net: dsa: yt921x: Return early for failed MIB read
Posted by Andrew Lunn 3 weeks ago
On Sun, Jan 18, 2026 at 09:30:15AM +0800, David Yang wrote:
> This patch does not change anything effectively, but serves as a
> prerequisite for another patch.
> 
> Signed-off-by: David Yang <mmyangfl@gmail.com>
> ---
>  drivers/net/dsa/yt921x.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/dsa/yt921x.c b/drivers/net/dsa/yt921x.c
> index 5e4e8093ba16..fe08385445d2 100644
> --- a/drivers/net/dsa/yt921x.c
> +++ b/drivers/net/dsa/yt921x.c
> @@ -707,6 +707,12 @@ static int yt921x_read_mib(struct yt921x_priv *priv, int port)
>  		WRITE_ONCE(*valp, val);
>  	}
>  
> +	if (res) {
> +		dev_err(dev, "Failed to %s port %d: %i\n", "read stats for",
> +			port, res);
> +		return res;
> +	}

I know you are just moving code around, so i can understand a straight
cut/paste.

However, when i look at the code, what is the point of %s and the
constant "read stats for"?

	Andrew
Re: [PATCH net-next v6 2/3] net: dsa: yt921x: Return early for failed MIB read
Posted by Yangfl 3 weeks ago
On Mon, Jan 19, 2026 at 12:06 AM Andrew Lunn <andrew@lunn.ch> wrote:
>
> On Sun, Jan 18, 2026 at 09:30:15AM +0800, David Yang wrote:
> > This patch does not change anything effectively, but serves as a
> > prerequisite for another patch.
> >
> > Signed-off-by: David Yang <mmyangfl@gmail.com>
> > ---
> >  drivers/net/dsa/yt921x.c | 11 +++++++----
> >  1 file changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/net/dsa/yt921x.c b/drivers/net/dsa/yt921x.c
> > index 5e4e8093ba16..fe08385445d2 100644
> > --- a/drivers/net/dsa/yt921x.c
> > +++ b/drivers/net/dsa/yt921x.c
> > @@ -707,6 +707,12 @@ static int yt921x_read_mib(struct yt921x_priv *priv, int port)
> >               WRITE_ONCE(*valp, val);
> >       }
> >
> > +     if (res) {
> > +             dev_err(dev, "Failed to %s port %d: %i\n", "read stats for",
> > +                     port, res);
> > +             return res;
> > +     }
>
> I know you are just moving code around, so i can understand a straight
> cut/paste.
>
> However, when i look at the code, what is the point of %s and the
> constant "read stats for"?
>
>         Andrew

The error format is used many times across the file, so using the same
string helps reduce the data size a bit.
Re: [PATCH net-next v6 2/3] net: dsa: yt921x: Return early for failed MIB read
Posted by Paolo Abeni 2 weeks, 3 days ago
 1/18/26 8:24 PM, Yangfl wrote:
> On Mon, Jan 19, 2026 at 12:06 AM Andrew Lunn <andrew@lunn.ch> wrote:
>>
>> On Sun, Jan 18, 2026 at 09:30:15AM +0800, David Yang wrote:
>>> This patch does not change anything effectively, but serves as a
>>> prerequisite for another patch.
>>>
>>> Signed-off-by: David Yang <mmyangfl@gmail.com>
>>> ---
>>>  drivers/net/dsa/yt921x.c | 11 +++++++----
>>>  1 file changed, 7 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/drivers/net/dsa/yt921x.c b/drivers/net/dsa/yt921x.c
>>> index 5e4e8093ba16..fe08385445d2 100644
>>> --- a/drivers/net/dsa/yt921x.c
>>> +++ b/drivers/net/dsa/yt921x.c
>>> @@ -707,6 +707,12 @@ static int yt921x_read_mib(struct yt921x_priv *priv, int port)
>>>               WRITE_ONCE(*valp, val);
>>>       }
>>>
>>> +     if (res) {
>>> +             dev_err(dev, "Failed to %s port %d: %i\n", "read stats for",
>>> +                     port, res);
>>> +             return res;
>>> +     }
>>
>> I know you are just moving code around, so i can understand a straight
>> cut/paste.
>>
>> However, when i look at the code, what is the point of %s and the
>> constant "read stats for"?
>>
>>         Andrew
> 
> The error format is used many times across the file, so using the same
> string helps reduce the data size a bit.

I think you could/should clean the implementation encapsulating the
dev_err in an helper tacking the variable string as an argument.

Since you have to repost, you could introduce a pre-req patch doing that.

Thanks,

Paolo