netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/2] Fix link speed handling for SJA1105 DSA driver
@ 2019-06-01 10:37 Vladimir Oltean
  2019-06-01 10:37 ` [PATCH net 1/2] net: dsa: sja1105: Force a negative value for enum sja1105_speed_t Vladimir Oltean
  2019-06-01 10:37 ` [PATCH net 2/2] net: dsa: sja1105: Fix link speed not working at 100 Mbps and below Vladimir Oltean
  0 siblings, 2 replies; 6+ messages in thread
From: Vladimir Oltean @ 2019-06-01 10:37 UTC (permalink / raw)
  To: f.fainelli, vivien.didelot, andrew, davem; +Cc: netdev, Vladimir Oltean

This patchset fixes two bugs in the logic handling of the enum
sja1105_speed_t which caused link speeds of 10 and 100 Mbps to not be
interpreted correctly and thus not be applied to the switch MACs.

Vladimir Oltean (2):
  net: dsa: sja1105: Force a negative value for enum sja1105_speed_t
  net: dsa: sja1105: Fix link speed not working at 100 Mbps and below

 drivers/net/dsa/sja1105/sja1105.h      | 1 +
 drivers/net/dsa/sja1105/sja1105_main.c | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net 1/2] net: dsa: sja1105: Force a negative value for enum sja1105_speed_t
  2019-06-01 10:37 [PATCH net 0/2] Fix link speed handling for SJA1105 DSA driver Vladimir Oltean
@ 2019-06-01 10:37 ` Vladimir Oltean
  2019-06-01 16:03   ` Andrew Lunn
  2019-06-01 10:37 ` [PATCH net 2/2] net: dsa: sja1105: Fix link speed not working at 100 Mbps and below Vladimir Oltean
  1 sibling, 1 reply; 6+ messages in thread
From: Vladimir Oltean @ 2019-06-01 10:37 UTC (permalink / raw)
  To: f.fainelli, vivien.didelot, andrew, davem; +Cc: netdev, Vladimir Oltean

The code in sja1105_adjust_port_config relies on the fact that an
invalid link speed is detected by sja1105_get_speed_cfg and returned as
-EINVAL.  However storing this into an enum that only has positive
members will cast it into an unsigned value, and it will miss the
negative check.

So make the -EINVAL value part of the enum, so that it is stored as a
signed number and passes the negative check.

Fixes: 8aa9ebccae87 ("net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch")
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
---
 drivers/net/dsa/sja1105/sja1105.h      | 1 +
 drivers/net/dsa/sja1105/sja1105_main.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/dsa/sja1105/sja1105.h b/drivers/net/dsa/sja1105/sja1105.h
index 1e6d0f33a663..15df37ec63bf 100644
--- a/drivers/net/dsa/sja1105/sja1105.h
+++ b/drivers/net/dsa/sja1105/sja1105.h
@@ -160,6 +160,7 @@ typedef enum {
 	SJA1105_SPEED_100MBPS	= 2,
 	SJA1105_SPEED_1000MBPS	= 1,
 	SJA1105_SPEED_AUTO	= 0,
+	SJA1105_SPEED_INVALID	= -EINVAL,
 } sja1105_speed_t;
 
 int sja1105pqrs_setup_rgmii_delay(const void *ctx, int port);
diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c
index b89d979ba213..12b1af52d84b 100644
--- a/drivers/net/dsa/sja1105/sja1105_main.c
+++ b/drivers/net/dsa/sja1105/sja1105_main.c
@@ -719,7 +719,7 @@ static sja1105_speed_t sja1105_get_speed_cfg(unsigned int speed_mbps)
 	for (i = SJA1105_SPEED_AUTO; i <= SJA1105_SPEED_1000MBPS; i++)
 		if (sja1105_speed[i] == speed_mbps)
 			return i;
-	return -EINVAL;
+	return SJA1105_SPEED_INVALID;
 }
 
 /* Set link speed and enable/disable traffic I/O in the MAC configuration
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net 2/2] net: dsa: sja1105: Fix link speed not working at 100 Mbps and below
  2019-06-01 10:37 [PATCH net 0/2] Fix link speed handling for SJA1105 DSA driver Vladimir Oltean
  2019-06-01 10:37 ` [PATCH net 1/2] net: dsa: sja1105: Force a negative value for enum sja1105_speed_t Vladimir Oltean
@ 2019-06-01 10:37 ` Vladimir Oltean
  1 sibling, 0 replies; 6+ messages in thread
From: Vladimir Oltean @ 2019-06-01 10:37 UTC (permalink / raw)
  To: f.fainelli, vivien.didelot, andrew, davem; +Cc: netdev, Vladimir Oltean

The hardware values for link speed are held in the sja1105_speed_t enum.
However they do not increase in the order that sja1105_get_speed_cfg was
iterating over them (basically from SJA1105_SPEED_AUTO - 0 - to
SJA1105_SPEED_1000MBPS - 1 - skipping the other two).

Change the iteration from going through the enum values to going through
the sja1105_speed array, which makes sure that all elements are visited
regardless of underlying ordering.

Fixes: 8aa9ebccae87 ("net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch")
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
---
 drivers/net/dsa/sja1105/sja1105_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c
index 12b1af52d84b..c3eab40b0500 100644
--- a/drivers/net/dsa/sja1105/sja1105_main.c
+++ b/drivers/net/dsa/sja1105/sja1105_main.c
@@ -716,7 +716,7 @@ static sja1105_speed_t sja1105_get_speed_cfg(unsigned int speed_mbps)
 {
 	int i;
 
-	for (i = SJA1105_SPEED_AUTO; i <= SJA1105_SPEED_1000MBPS; i++)
+	for (i = 0; i < ARRAY_SIZE(sja1105_speed); i++)
 		if (sja1105_speed[i] == speed_mbps)
 			return i;
 	return SJA1105_SPEED_INVALID;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net 1/2] net: dsa: sja1105: Force a negative value for enum sja1105_speed_t
  2019-06-01 10:37 ` [PATCH net 1/2] net: dsa: sja1105: Force a negative value for enum sja1105_speed_t Vladimir Oltean
@ 2019-06-01 16:03   ` Andrew Lunn
  2019-06-01 20:30     ` Vladimir Oltean
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Lunn @ 2019-06-01 16:03 UTC (permalink / raw)
  To: Vladimir Oltean; +Cc: f.fainelli, vivien.didelot, davem, netdev

On Sat, Jun 01, 2019 at 01:37:34PM +0300, Vladimir Oltean wrote:
> The code in sja1105_adjust_port_config relies on the fact that an
> invalid link speed is detected by sja1105_get_speed_cfg and returned as
> -EINVAL.  However storing this into an enum that only has positive
> members will cast it into an unsigned value, and it will miss the
> negative check.
> 
> So make the -EINVAL value part of the enum, so that it is stored as a
> signed number and passes the negative check.
> 
> Fixes: 8aa9ebccae87 ("net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch")
> Signed-off-by: Vladimir Oltean <olteanv@gmail.com>

Hi Vladimir

It seems like just using a switch statement would be simpler, and more
likely to be correct. And it would avoid adding SJA1105_SPEED_INVALID
= -EINVAL which feels hackish.

  Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net 1/2] net: dsa: sja1105: Force a negative value for enum sja1105_speed_t
  2019-06-01 16:03   ` Andrew Lunn
@ 2019-06-01 20:30     ` Vladimir Oltean
  2019-06-01 21:36       ` Andrew Lunn
  0 siblings, 1 reply; 6+ messages in thread
From: Vladimir Oltean @ 2019-06-01 20:30 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: Florian Fainelli, Vivien Didelot, David S. Miller, netdev

On Sat, 1 Jun 2019 at 19:03, Andrew Lunn <andrew@lunn.ch> wrote:
>
> On Sat, Jun 01, 2019 at 01:37:34PM +0300, Vladimir Oltean wrote:
> > The code in sja1105_adjust_port_config relies on the fact that an
> > invalid link speed is detected by sja1105_get_speed_cfg and returned as
> > -EINVAL.  However storing this into an enum that only has positive
> > members will cast it into an unsigned value, and it will miss the
> > negative check.
> >
> > So make the -EINVAL value part of the enum, so that it is stored as a
> > signed number and passes the negative check.
> >
> > Fixes: 8aa9ebccae87 ("net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch")
> > Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
>
> Hi Vladimir
>
> It seems like just using a switch statement would be simpler, and more
> likely to be correct. And it would avoid adding SJA1105_SPEED_INVALID
> = -EINVAL which feels hackish.
>
>   Andrew

Hi Andrew,

You mean I should completely remove the sja1105_get_speed_cfg function?
I suppose I can do that, I'm only using it in one place.

Thanks,
-Vladimir

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net 1/2] net: dsa: sja1105: Force a negative value for enum sja1105_speed_t
  2019-06-01 20:30     ` Vladimir Oltean
@ 2019-06-01 21:36       ` Andrew Lunn
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2019-06-01 21:36 UTC (permalink / raw)
  To: Vladimir Oltean; +Cc: Florian Fainelli, Vivien Didelot, David S. Miller, netdev

 On Sat, Jun 01, 2019 at 11:30:16PM +0300, Vladimir Oltean wrote:
> On Sat, 1 Jun 2019 at 19:03, Andrew Lunn <andrew@lunn.ch> wrote:
> >
> > On Sat, Jun 01, 2019 at 01:37:34PM +0300, Vladimir Oltean wrote:
> > > The code in sja1105_adjust_port_config relies on the fact that an
> > > invalid link speed is detected by sja1105_get_speed_cfg and returned as
> > > -EINVAL.  However storing this into an enum that only has positive
> > > members will cast it into an unsigned value, and it will miss the
> > > negative check.
> > >
> > > So make the -EINVAL value part of the enum, so that it is stored as a
> > > signed number and passes the negative check.
> > >
> > > Fixes: 8aa9ebccae87 ("net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch")
> > > Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
> >
> > Hi Vladimir
> >
> > It seems like just using a switch statement would be simpler, and more
> > likely to be correct. And it would avoid adding SJA1105_SPEED_INVALID
> > = -EINVAL which feels hackish.
> >
> >   Andrew
> 
> Hi Andrew,
> 
> You mean I should completely remove the sja1105_get_speed_cfg function?
> I suppose I can do that, I'm only using it in one place.

I think it is often better to use simple, obviously correct code.
This seems to be one example.

     Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-06-01 21:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-01 10:37 [PATCH net 0/2] Fix link speed handling for SJA1105 DSA driver Vladimir Oltean
2019-06-01 10:37 ` [PATCH net 1/2] net: dsa: sja1105: Force a negative value for enum sja1105_speed_t Vladimir Oltean
2019-06-01 16:03   ` Andrew Lunn
2019-06-01 20:30     ` Vladimir Oltean
2019-06-01 21:36       ` Andrew Lunn
2019-06-01 10:37 ` [PATCH net 2/2] net: dsa: sja1105: Fix link speed not working at 100 Mbps and below Vladimir Oltean

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).